mirror of
https://github.com/streamyfin/streamyfin.git
synced 2026-01-15 23:59:08 +00:00
Some checks failed
🤖 Android APK Build / 🏗️ Build Android APK (push) Has been cancelled
🤖 iOS IPA Build / 🏗️ Build iOS IPA (push) Has been cancelled
🔒 Lockfile Consistency Check / 🔍 Check bun.lock and package.json consistency (push) Has been cancelled
🛡️ CodeQL Analysis / 🔎 Analyze with CodeQL (javascript-typescript) (push) Has been cancelled
🏷️🔀Merge Conflict Labeler / 🏷️ Labeling Merge Conflicts (push) Has been cancelled
🕒 Handle Stale Issues / 🗑️ Cleanup Stale Issues (push) Has been cancelled
34 lines
1.1 KiB
TypeScript
34 lines
1.1 KiB
TypeScript
import type { BaseItemDto } from "@jellyfin/sdk/lib/generated-client";
|
|
import { useAtom } from "jotai";
|
|
import useImageStorage from "@/hooks/useImageStorage";
|
|
import { apiAtom } from "@/providers/JellyfinProvider";
|
|
import { getPrimaryImageUrlById } from "@/utils/jellyfin/image/getPrimaryImageUrlById";
|
|
import { storage } from "@/utils/mmkv";
|
|
|
|
const useDownloadHelper = () => {
|
|
const [api] = useAtom(apiAtom);
|
|
const { saveImage } = useImageStorage();
|
|
|
|
const saveSeriesPrimaryImage = async (item: BaseItemDto) => {
|
|
console.log(`Attempting to save primary image for item: ${item.Id}`);
|
|
if (
|
|
item.Type === "Episode" &&
|
|
item.SeriesId &&
|
|
!storage.getString(item.SeriesId)
|
|
) {
|
|
console.log(`Saving primary image for series: ${item.SeriesId}`);
|
|
await saveImage(
|
|
item.SeriesId,
|
|
getPrimaryImageUrlById({ api, id: item.SeriesId }),
|
|
);
|
|
console.log(`Primary image saved for series: ${item.SeriesId}`);
|
|
} else {
|
|
console.log(`Skipping primary image save for item: ${item.Id}`);
|
|
}
|
|
};
|
|
|
|
return { saveSeriesPrimaryImage };
|
|
};
|
|
|
|
export default useDownloadHelper;
|