Skip to content

Commit

Permalink
refactor: replace deprecated getItemImageUrl function (#2488)
Browse files Browse the repository at this point in the history
  • Loading branch information
ferferga authored Nov 5, 2024
1 parent e45a106 commit a14092a
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
3 changes: 2 additions & 1 deletion frontend/src/components/Item/Metadata/MetadataEditor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@
v-if="item.Id && item.PrimaryImageTag"
:alt="$t('person')"
:src="
remote.sdk.api?.getItemImageUrl(
getItemImageUrl(
item.Id,
ImageType.Primary
)
Expand Down Expand Up @@ -234,6 +234,7 @@ import { format, formatISO } from 'date-fns';
import { computed, ref } from 'vue';
import { useI18n } from 'vue-i18n';
import { watchImmediate } from '@vueuse/core';
import { getItemImageUrl } from '@/utils/images';
import { isArray } from '@/utils/validation';
import { remote } from '@/plugins/remote';
import { useSnackbar } from '@/composables/use-snackbar';
Expand Down
3 changes: 2 additions & 1 deletion frontend/src/components/Item/Metadata/PersonEditor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
class="ml-2">
<JImg
:src="
person?.Id && $remote.sdk.api?.getItemImageUrl(person.Id, ImageType.Primary)
person?.Id && getItemImageUrl(person.Id, ImageType.Primary)
"
:alt="$t('person')">
<template #placeholder>
Expand Down Expand Up @@ -82,6 +82,7 @@ import { computed, ref } from 'vue';
import { useI18n } from 'vue-i18n';
import { type BaseItemPerson, ImageType } from '@jellyfin/sdk/lib/generated-client';
import { watchImmediate } from '@vueuse/core';
import { getItemImageUrl } from '@/utils/images';
const { person } = defineProps<{ person: BaseItemPerson | undefined }>();
Expand Down
13 changes: 11 additions & 2 deletions frontend/src/utils/images.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import {
type BaseItemPerson,
ImageType
} from '@jellyfin/sdk/lib/generated-client';
import { getImageApi } from '@jellyfin/sdk/lib/utils/api/image-api';
import type { ImageUrlsApi } from '@jellyfin/sdk/lib/utils/api/image-urls-api';
import { remote } from '@/plugins/remote';
import { CardShapes, getShapeFromItemType, isPerson } from '@/utils/items';

Expand All @@ -20,6 +22,13 @@ const excludedBlurhashTypes = Object.freeze(
new Set<ImageType>([ImageType.Logo])
);

/**
* Gets the image URL given an item id and the image type requested
*/
export function getItemImageUrl(...args: Parameters<ImageUrlsApi['getItemImageUrlById']>) {
return remote.sdk.newUserApi(getImageApi).getItemImageUrlById(...args);
}

/**
* Gets the tag of the image of an specific item and type.
*
Expand Down Expand Up @@ -347,7 +356,7 @@ export function getImageInfo(
};
}

const url_string = remote.sdk.api?.getItemImageUrl(itemId, imgType);
const url_string = getItemImageUrl(itemId, imgType);

if (imgTag && imgType && url_string) {
url = new URL(url_string);
Expand Down Expand Up @@ -420,7 +429,7 @@ export function getLogo(
}

if (imgTag && imgType && itemId) {
url = new URL(remote.sdk.api?.getItemImageUrl(itemId, imgType) ?? '');
url = new URL(getItemImageUrl(itemId, imgType));

const parameters: Record<string, string> = {
imgTag,
Expand Down

0 comments on commit a14092a

Please sign in to comment.