chore(deps); update and migrate to latest node and cargo packages
This commit is contained in:
100 files changed
+7417
-8802
No files matched your search
@@ -0,0 +1,188 @@
|
||||
import type { Api } from "@jellyfin/sdk";
|
||||
import {
|
||||
type BaseItemDto,
|
||||
BaseItemKind,
|
||||
ItemFields,
|
||||
LocationType,
|
||||
} from "@jellyfin/sdk/lib/generated-client";
|
||||
import { getLibraryApi } from "@jellyfin/sdk/lib/utils/api/library-api";
|
||||
import { getShowApi } from "@jellyfin/sdk/lib/utils/api/show-api";
|
||||
import { type QueryClient, queryOptions } from "@tanstack/react-query";
|
||||
|
||||
/**
|
||||
* Query options shared by the unified `/item/$id` route loader and its sections,
|
||||
* so data prefetched in the loader is picked up by the components.
|
||||
*/
|
||||
|
||||
export const getSimilarItemsQueryOptions = (
|
||||
api: Api | undefined,
|
||||
userId: string | undefined,
|
||||
id: string,
|
||||
type: BaseItemKind | undefined,
|
||||
) =>
|
||||
queryOptions({
|
||||
queryKey: ["item", id, "similarItem"],
|
||||
queryFn: async () => {
|
||||
if (!api) return null;
|
||||
const request = { userId, itemId: id, limit: 16 };
|
||||
const result =
|
||||
type === BaseItemKind.Series
|
||||
? await getLibraryApi(api).getSimilarShows(request)
|
||||
: await getLibraryApi(api).getSimilarItems(request);
|
||||
return result.data;
|
||||
},
|
||||
networkMode: "always",
|
||||
});
|
||||
|
||||
export const getSeasonsQueryOptions = (
|
||||
api: Api | undefined,
|
||||
userId: string | undefined,
|
||||
seriesId: string,
|
||||
) =>
|
||||
queryOptions({
|
||||
queryKey: ["item", seriesId, "seasons"],
|
||||
queryFn: async () => {
|
||||
if (!api) return null;
|
||||
const result = await getShowApi(api).getSeasons({
|
||||
userId,
|
||||
seriesId,
|
||||
isMissing: false,
|
||||
});
|
||||
return result.data;
|
||||
},
|
||||
});
|
||||
|
||||
export const getSpecialFeaturesQueryOptions = (
|
||||
api: Api | undefined,
|
||||
userId: string | undefined,
|
||||
id: string,
|
||||
) =>
|
||||
queryOptions({
|
||||
queryKey: ["item", id, "specialFeatures"],
|
||||
queryFn: async () => {
|
||||
if (!api) return null;
|
||||
const result = await getLibraryApi(api).getSpecialFeatures({
|
||||
itemId: id,
|
||||
userId,
|
||||
});
|
||||
return result.data;
|
||||
},
|
||||
});
|
||||
|
||||
export const getCollectionItemsQueryOptions = (
|
||||
api: Api | undefined,
|
||||
userId: string | undefined,
|
||||
id: string,
|
||||
) =>
|
||||
queryOptions({
|
||||
queryKey: ["item", id, "collection"],
|
||||
queryFn: async () => {
|
||||
if (!api) return null;
|
||||
const result = await getLibraryApi(api).getItems({
|
||||
userId,
|
||||
parentId: id,
|
||||
fields: [ItemFields.SeasonUserData, ItemFields.Overview],
|
||||
excludeLocationTypes: [LocationType.Virtual],
|
||||
});
|
||||
return result.data;
|
||||
},
|
||||
networkMode: "always",
|
||||
});
|
||||
|
||||
export const getUpcomingEpisodesQueryOptions = (
|
||||
api: Api | undefined,
|
||||
userId: string | undefined,
|
||||
episode: BaseItemDto,
|
||||
) =>
|
||||
queryOptions({
|
||||
queryKey: ["item", episode.Id ?? "", "episode", "upcomingEpisodes"],
|
||||
queryFn: async () => {
|
||||
if (!api) return null;
|
||||
const result = await getLibraryApi(api).getItems({
|
||||
userId,
|
||||
parentId: episode.ParentId ?? "",
|
||||
startIndex: episode.IndexNumber ?? 0,
|
||||
excludeLocationTypes: [LocationType.Virtual],
|
||||
});
|
||||
return result.data;
|
||||
},
|
||||
networkMode: "always",
|
||||
});
|
||||
|
||||
export const personTabs = [
|
||||
{ title: "Movies", key: "personMovies", kind: BaseItemKind.Movie },
|
||||
{ title: "TV Shows", key: "personShows", kind: BaseItemKind.Series },
|
||||
{ title: "Books", key: "personBooks", kind: BaseItemKind.Book },
|
||||
{ title: "Photos", key: "personPhotos", kind: BaseItemKind.Photo },
|
||||
{ title: "Episodes", key: "personEpisodes", kind: BaseItemKind.Episode },
|
||||
] as const;
|
||||
|
||||
export type PersonTab = (typeof personTabs)[number];
|
||||
|
||||
export const getPersonItemsQueryOptions = (
|
||||
api: Api | undefined,
|
||||
userId: string | undefined,
|
||||
personId: string,
|
||||
tab: PersonTab,
|
||||
) =>
|
||||
queryOptions({
|
||||
queryKey: ["item", personId, tab.key],
|
||||
queryFn: async () => {
|
||||
if (!api) return null;
|
||||
const result = await getLibraryApi(api).getItems({
|
||||
userId,
|
||||
personIds: [personId],
|
||||
includeItemTypes: [tab.kind],
|
||||
recursive: true,
|
||||
fields:
|
||||
tab.kind === BaseItemKind.Episode
|
||||
? [ItemFields.SeasonUserData, ItemFields.Overview]
|
||||
: undefined,
|
||||
sortBy: ["PremiereDate", "ProductionYear", "SortName"],
|
||||
sortOrder:
|
||||
tab.kind === BaseItemKind.Photo || tab.kind === BaseItemKind.Episode
|
||||
? undefined
|
||||
: ["Descending"],
|
||||
excludeLocationTypes: [LocationType.Virtual],
|
||||
});
|
||||
return result.data;
|
||||
},
|
||||
networkMode: "always",
|
||||
});
|
||||
|
||||
/**
|
||||
* Starts fetching the data a given item type's page needs. Safe to call before the
|
||||
* item itself has loaded (when the type is known from a link hint).
|
||||
*/
|
||||
export const prefetchItemDetail = (
|
||||
queryClient: QueryClient,
|
||||
api: Api,
|
||||
userId: string,
|
||||
id: string,
|
||||
type: BaseItemKind | undefined,
|
||||
) => {
|
||||
switch (type) {
|
||||
case BaseItemKind.Person:
|
||||
for (const tab of personTabs) {
|
||||
queryClient.prefetchQuery(
|
||||
getPersonItemsQueryOptions(api, userId, id, tab),
|
||||
);
|
||||
}
|
||||
return;
|
||||
case BaseItemKind.Episode:
|
||||
// Upcoming episodes depend on the episode's parent, so they are prefetched once it loads.
|
||||
return;
|
||||
case BaseItemKind.Series:
|
||||
queryClient.prefetchQuery(getSeasonsQueryOptions(api, userId, id));
|
||||
queryClient.prefetchQuery(
|
||||
getSpecialFeaturesQueryOptions(api, userId, id),
|
||||
);
|
||||
break;
|
||||
case BaseItemKind.BoxSet:
|
||||
queryClient.prefetchQuery(
|
||||
getCollectionItemsQueryOptions(api, userId, id),
|
||||
);
|
||||
break;
|
||||
}
|
||||
queryClient.prefetchQuery(getSimilarItemsQueryOptions(api, userId, id, type));
|
||||
};
|
||||
@@ -1,6 +1,6 @@
|
||||
import type { Api } from "@jellyfin/sdk";
|
||||
import { BaseItemKind, ItemFields } from "@jellyfin/sdk/lib/generated-client";
|
||||
import { getUserLibraryApi } from "@jellyfin/sdk/lib/utils/api/user-library-api";
|
||||
import { getLibraryApi } from "@jellyfin/sdk/lib/utils/api/library-api";
|
||||
import { queryOptions } from "@tanstack/react-query";
|
||||
|
||||
/**
|
||||
@@ -24,7 +24,7 @@ export const getItemQueryOptions = (
|
||||
if (!userId) {
|
||||
throw Error("User ID is not defined");
|
||||
}
|
||||
const result = await getUserLibraryApi(api).getItem({
|
||||
const result = await getLibraryApi(api).getItem({
|
||||
userId: userId,
|
||||
itemId: id,
|
||||
});
|
||||
@@ -51,7 +51,7 @@ export const getLatestItemsQueryOptions = (
|
||||
if (!userId) {
|
||||
throw Error("User ID is not defined");
|
||||
}
|
||||
const media = await getUserLibraryApi(api).getLatestMedia({
|
||||
const media = await getLibraryApi(api).getLatestMedia({
|
||||
userId: userId,
|
||||
fields: [
|
||||
ItemFields.Overview,
|
||||
@@ -72,3 +72,29 @@ export const getLatestItemsQueryOptions = (
|
||||
return media.data;
|
||||
},
|
||||
});
|
||||
|
||||
/**
|
||||
* @param api api instance
|
||||
* @param userId user's id
|
||||
* @param libraryId the library (user view) id
|
||||
* @returns query options for the latest items of a single library
|
||||
*/
|
||||
export const getLibraryLatestQueryOptions = (
|
||||
api: Api | null | undefined,
|
||||
userId: string | null | undefined,
|
||||
libraryId: string | null | undefined,
|
||||
) =>
|
||||
queryOptions({
|
||||
queryKey: ["home", "latestMedia", libraryId],
|
||||
queryFn: async () => {
|
||||
if (!api || !userId) return null;
|
||||
const media = await getLibraryApi(api).getLatestMedia({
|
||||
userId,
|
||||
parentId: libraryId ?? undefined,
|
||||
limit: 16,
|
||||
fields: [ItemFields.PrimaryImageAspectRatio, ItemFields.ParentId],
|
||||
});
|
||||
return media.data;
|
||||
},
|
||||
enabled: !!userId,
|
||||
});
|
||||
@@ -1,5 +1,5 @@
|
||||
import type { Api } from "@jellyfin/sdk";
|
||||
import { getUserLibraryApi } from "@jellyfin/sdk/lib/utils/api/user-library-api";
|
||||
import { getLibraryApi } from "@jellyfin/sdk/lib/utils/api/library-api";
|
||||
import { queryOptions } from "@tanstack/react-query";
|
||||
|
||||
/**
|
||||
@@ -17,7 +17,7 @@ export const getLibraryQueryOptions = (
|
||||
queryKey: ["library", "currentLib", id],
|
||||
queryFn: async () => {
|
||||
if (!api || !userId) throw Error("API or User ID is not defined");
|
||||
const result = await getUserLibraryApi(api).getItem({
|
||||
const result = await getLibraryApi(api).getItem({
|
||||
userId: userId,
|
||||
itemId: id,
|
||||
});
|
||||
|
||||
@@ -9,10 +9,10 @@ import {
|
||||
SortOrder,
|
||||
VideoType,
|
||||
} from "@jellyfin/sdk/lib/generated-client";
|
||||
import { getArtistsApi } from "@jellyfin/sdk/lib/utils/api/artists-api";
|
||||
import { getItemsApi } from "@jellyfin/sdk/lib/utils/api/items-api";
|
||||
import { getPersonsApi } from "@jellyfin/sdk/lib/utils/api/persons-api";
|
||||
import { getStudiosApi } from "@jellyfin/sdk/lib/utils/api/studios-api";
|
||||
import { getArtistApi } from "@jellyfin/sdk/lib/utils/api/artist-api";
|
||||
import { getLibraryApi } from "@jellyfin/sdk/lib/utils/api/library-api";
|
||||
import { getPersonApi } from "@jellyfin/sdk/lib/utils/api/person-api";
|
||||
import { getStudioApi } from "@jellyfin/sdk/lib/utils/api/studio-api";
|
||||
import { queryOptions } from "@tanstack/react-query";
|
||||
|
||||
export interface LibraryItemsParams {
|
||||
@@ -91,31 +91,31 @@ export const getLibraryItemsQueryOptions = (
|
||||
};
|
||||
let result: { data: BaseItemDtoQueryResult };
|
||||
if (currentViewType === "MusicArtist") {
|
||||
result = await getArtistsApi(api).getAlbumArtists({
|
||||
result = await getArtistApi(api).getAlbumArtists({
|
||||
userId: userId,
|
||||
parentId: libraryId,
|
||||
limit: params.limit,
|
||||
});
|
||||
} else if (currentViewType === "Artist") {
|
||||
result = await getArtistsApi(api).getArtists({
|
||||
result = await getArtistApi(api).getArtists({
|
||||
userId: userId,
|
||||
parentId: libraryId,
|
||||
limit: params.limit,
|
||||
});
|
||||
} else if (currentViewType === "Person") {
|
||||
result = await getPersonsApi(api).getPersons({
|
||||
result = await getPersonApi(api).getPersons({
|
||||
userId: userId,
|
||||
personTypes: ["Actor"],
|
||||
limit: params.limit,
|
||||
});
|
||||
} else if (currentViewType === "Studio") {
|
||||
result = await getStudiosApi(api).getStudios({
|
||||
result = await getStudioApi(api).getStudios({
|
||||
userId: userId,
|
||||
parentId: libraryId,
|
||||
limit: params.limit,
|
||||
});
|
||||
} else if (currentViewType === "BoxSet") {
|
||||
result = await getItemsApi(api).getItems({
|
||||
result = await getLibraryApi(api).getItems({
|
||||
userId: userId,
|
||||
parentId: libraryId,
|
||||
recursive: params.collectionType === "boxsets" ? undefined : true,
|
||||
@@ -142,7 +142,7 @@ export const getLibraryItemsQueryOptions = (
|
||||
limit: params.limit,
|
||||
});
|
||||
} else {
|
||||
result = await getItemsApi(api).getItems({
|
||||
result = await getLibraryApi(api).getItems({
|
||||
userId: userId,
|
||||
parentId: libraryId,
|
||||
recursive: true,
|
||||
|
||||
Reference in new issue
Block a user