@jellyfin/sdk
Version:
A TypeScript SDK for Jellyfin.
116 lines (113 loc) • 4.12 kB
JavaScript
import { ImageApi } from '../../generated-client/api/image-api.js';
import { ImageType } from '../../generated-client/models/image-type.js';
/**
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
/**
* ImageUrlsApi - ImageApi with URL utility methods
* @export
* @class ImageUrlsApi
* @extends {ImageApi}
*/
class ImageUrlsApi extends ImageApi {
/**
* Get an Item image URL for a given Item ID.
* @param itemId The Item ID.
* @param [imageType=ImageType.Primary] An optional Image Type.
* @param [params={}] Additional request parameters.
* @returns The image URL.
*/
getItemImageUrlById(itemId, imageType = ImageType.Primary, params = {}) {
var _a;
// TODO: We could probably use ImageApiAxiosParamCreator to make this more robust
return this.axios.getUri({
baseURL: (_a = this.configuration) === null || _a === void 0 ? void 0 : _a.basePath,
url: `/Items/${itemId}/Images/${imageType}`,
params
});
}
/**
* Get an Item image URL with automatic `tag` param handling.
* @param item The Item.
* @param [imageType] An optional Image Type (Primary by default).
* @param [params={}] Additional request parameters.
* @returns The Item image URL.
*/
getItemImageUrl(item, imageType = ImageType.Primary, params = {}) {
var _a, _b;
if (!(item === null || item === void 0 ? void 0 : item.Id))
return;
return this.getItemImageUrlById(item.Id, imageType, {
...params,
tag: (_a = params.tag) !== null && _a !== void 0 ? _a : (_b = item.ImageTags) === null || _b === void 0 ? void 0 : _b[imageType]
});
}
/**
* Get an Item's backdrop image URLs.
* @param item The Item.
* @param [params={}] Additional request parameters.
* @returns An array of backdrop image URLs.
*/
getItemBackdropImageUrls(item, params = {}) {
var _a, _b;
const urls = [];
const id = item === null || item === void 0 ? void 0 : item.Id;
if (!id)
return urls;
(_a = item.BackdropImageTags) === null || _a === void 0 ? void 0 : _a.forEach(tag => {
const url = this.getItemImageUrlById(id, ImageType.Backdrop, {
...params,
tag
});
urls.push(url);
});
if (urls.length > 0)
return urls;
const parentId = item.ParentBackdropItemId;
if (parentId) {
(_b = item.ParentBackdropImageTags) === null || _b === void 0 ? void 0 : _b.forEach(tag => {
const url = this.getItemImageUrlById(parentId, ImageType.Backdrop, {
...params,
tag
});
urls.push(url);
});
}
return urls;
}
/**
* Get the splash screen image URL.
* @param [params={}] Additional request parameters.
* @returns The splash screen image URL.
*/
getSplashscreenImageUrl(params = {}) {
var _a;
return this.axios.getUri({
baseURL: (_a = this.configuration) === null || _a === void 0 ? void 0 : _a.basePath,
url: '/Branding/Splashscreen',
params
});
}
/**
* Get a User's primary image URL.
* @param user The User.
* @param [params={}] Additional request parameters.
* @returns The User's primary image URL.
*/
getUserImageUrl(user, params = {}) {
var _a;
if (!(user === null || user === void 0 ? void 0 : user.Id))
return;
return this.axios.getUri({
baseURL: (_a = this.configuration) === null || _a === void 0 ? void 0 : _a.basePath,
url: `/Users/${user.Id}/Images/Primary`,
params: {
...params,
tag: user.PrimaryImageTag
}
});
}
}
export { ImageUrlsApi };