mirror of
https://github.com/streamyfin/streamyfin.git
synced 2026-05-31 19:18:26 +01:00
fix: linting (#1184)
This commit is contained in:
committed by
GitHub
parent
30dc3980e3
commit
2be78a232c
@@ -8,6 +8,7 @@ import {
|
||||
getAllDownloadedItems,
|
||||
getDownloadedItemById,
|
||||
getDownloadsDatabase,
|
||||
updateDownloadedItem,
|
||||
} from "./Downloads/database";
|
||||
import { getDownloadedItemSize } from "./Downloads/fileOperations";
|
||||
import { useDownloadEventHandlers } from "./Downloads/hooks/useDownloadEventHandlers";
|
||||
@@ -29,7 +30,7 @@ function useDownloadProvider() {
|
||||
const successHapticFeedback = useHaptic("success");
|
||||
|
||||
// Track task ID to process ID mapping
|
||||
const taskMapRef = useRef<Map<number, string>>(new Map());
|
||||
const taskMapRef = useRef<Map<number | string, string>>(new Map());
|
||||
|
||||
// Reactive downloaded items that updates when refreshKey changes
|
||||
const downloadedItems = useMemo(() => {
|
||||
@@ -130,13 +131,13 @@ function useDownloadProvider() {
|
||||
cancelDownload,
|
||||
getDownloadedItemSize,
|
||||
getDownloadedItemById,
|
||||
updateDownloadedItem,
|
||||
triggerRefresh,
|
||||
APP_CACHE_DOWNLOAD_DIRECTORY: APP_CACHE_DOWNLOAD_DIRECTORY.uri,
|
||||
appSizeUsage,
|
||||
// Deprecated/not implemented in simple version
|
||||
startDownload: async () => {},
|
||||
cleanCacheDirectory: async () => {},
|
||||
updateDownloadedItem: () => {},
|
||||
dumpDownloadDiagnostics: async () => "",
|
||||
};
|
||||
}
|
||||
@@ -161,9 +162,9 @@ export function useDownload() {
|
||||
startDownload: async () => {},
|
||||
getDownloadedItemSize: () => 0,
|
||||
getDownloadedItemById: () => undefined,
|
||||
updateDownloadedItem: () => {},
|
||||
APP_CACHE_DOWNLOAD_DIRECTORY: "",
|
||||
cleanCacheDirectory: async () => {},
|
||||
updateDownloadedItem: () => {},
|
||||
appSizeUsage: async () => ({ total: 0, remaining: 0, appSize: 0 }),
|
||||
dumpDownloadDiagnostics: async () => "",
|
||||
};
|
||||
|
||||
@@ -185,10 +185,16 @@ export async function fetchSegments(
|
||||
}> {
|
||||
try {
|
||||
const segments = await fetchAndParseSegments(itemId, api);
|
||||
return segments;
|
||||
return {
|
||||
introSegments: segments.introSegments,
|
||||
creditSegments: segments.creditSegments,
|
||||
};
|
||||
} catch (error) {
|
||||
console.error(`[SEGMENTS] Failed to fetch segments:`, error);
|
||||
return {};
|
||||
return {
|
||||
introSegments: undefined,
|
||||
creditSegments: undefined,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -222,7 +228,12 @@ export async function downloadAdditionalAssets(params: {
|
||||
mediaSource.TranscodingUrl
|
||||
? Promise.resolve(mediaSource)
|
||||
: downloadSubtitles(mediaSource, item, api.basePath || ""),
|
||||
item.Id ? fetchSegments(item.Id, api) : Promise.resolve({}),
|
||||
item.Id
|
||||
? fetchSegments(item.Id, api)
|
||||
: Promise.resolve({
|
||||
introSegments: undefined,
|
||||
creditSegments: undefined,
|
||||
}),
|
||||
// Cover image downloads (run but don't wait for results)
|
||||
downloadCoverImage(item, api, saveImageFn).catch((err) => {
|
||||
console.error("[COVER] Error downloading cover:", err);
|
||||
|
||||
@@ -181,6 +181,41 @@ export function removeDownloadedItem(id: string): DownloadedItem | undefined {
|
||||
return itemToDelete;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update a downloaded item in the database
|
||||
*/
|
||||
export function updateDownloadedItem(
|
||||
_id: string,
|
||||
updatedItem: DownloadedItem,
|
||||
): void {
|
||||
const db = getDownloadsDatabase();
|
||||
const baseItem = updatedItem.item;
|
||||
|
||||
if (baseItem.Type === "Movie" && baseItem.Id) {
|
||||
db.movies[baseItem.Id] = updatedItem;
|
||||
} else if (
|
||||
baseItem.Type === "Episode" &&
|
||||
baseItem.SeriesId &&
|
||||
baseItem.ParentIndexNumber !== undefined &&
|
||||
baseItem.ParentIndexNumber !== null &&
|
||||
baseItem.IndexNumber !== undefined &&
|
||||
baseItem.IndexNumber !== null
|
||||
) {
|
||||
const seriesId = baseItem.SeriesId;
|
||||
const seasonNumber = baseItem.ParentIndexNumber;
|
||||
const episodeNumber = baseItem.IndexNumber;
|
||||
|
||||
if (db.series[seriesId]?.seasons[seasonNumber]?.episodes[episodeNumber]) {
|
||||
db.series[seriesId].seasons[seasonNumber].episodes[episodeNumber] =
|
||||
updatedItem;
|
||||
}
|
||||
} else if (baseItem.Id && db.other?.[baseItem.Id]) {
|
||||
db.other[baseItem.Id] = updatedItem;
|
||||
}
|
||||
|
||||
saveDownloadsDatabase(db);
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear all downloaded items from the database
|
||||
*/
|
||||
|
||||
@@ -24,7 +24,7 @@ import {
|
||||
} from "./useDownloadSpeedCalculator";
|
||||
|
||||
interface UseDownloadEventHandlersProps {
|
||||
taskMapRef: MutableRefObject<Map<number, string>>;
|
||||
taskMapRef: MutableRefObject<Map<number | string, string>>;
|
||||
processes: JobStatus[];
|
||||
updateProcess: (
|
||||
processId: string,
|
||||
@@ -59,7 +59,8 @@ export function useDownloadEventHandlers({
|
||||
// If no mapping exists, find by URL (for queued downloads)
|
||||
if (!processId && event.url) {
|
||||
// Check if we have a URL mapping (queued download)
|
||||
processId = taskMapRef.current.get(event.url);
|
||||
const urlKey = event.url;
|
||||
processId = taskMapRef.current.get(urlKey);
|
||||
|
||||
if (!processId) {
|
||||
// Fallback: search by matching URL in processes
|
||||
@@ -74,7 +75,7 @@ export function useDownloadEventHandlers({
|
||||
if (processId) {
|
||||
// Create taskId mapping and remove URL mapping
|
||||
taskMapRef.current.set(event.taskId, processId);
|
||||
taskMapRef.current.delete(event.url);
|
||||
taskMapRef.current.delete(urlKey);
|
||||
console.log(
|
||||
`[DPL] Mapped queued download: taskId=${event.taskId} to processId=${processId.slice(0, 8)}...`,
|
||||
);
|
||||
|
||||
@@ -27,7 +27,7 @@ import type { JobStatus } from "../types";
|
||||
import { generateFilename, uriToFilePath } from "../utils";
|
||||
|
||||
interface UseDownloadOperationsProps {
|
||||
taskMapRef: MutableRefObject<Map<number, string>>;
|
||||
taskMapRef: MutableRefObject<Map<number | string, string>>;
|
||||
processes: JobStatus[];
|
||||
setProcesses: (updater: (prev: JobStatus[]) => JobStatus[]) => void;
|
||||
removeProcess: (id: string) => void;
|
||||
@@ -169,7 +169,7 @@ export function useDownloadOperations({
|
||||
if (typeof key === "number") {
|
||||
taskId = key;
|
||||
} else {
|
||||
downloadUrl = key;
|
||||
downloadUrl = key as string;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
@@ -94,9 +94,9 @@ export const PlaySettingsProvider: React.FC<{ children: React.ReactNode }> = ({
|
||||
console.log(`${data?.url?.slice(0, 100)}...${data?.url?.slice(-50)}`);
|
||||
|
||||
_setPlaySettings(newSettings);
|
||||
setPlayUrl(data?.url!);
|
||||
setPlaySessionId(data?.sessionId!);
|
||||
setMediaSource(data?.mediaSource!);
|
||||
if (data?.url) setPlayUrl(data.url);
|
||||
if (data?.sessionId) setPlaySessionId(data.sessionId);
|
||||
if (data?.mediaSource) setMediaSource(data.mediaSource);
|
||||
|
||||
return data;
|
||||
} catch (error) {
|
||||
|
||||
Reference in New Issue
Block a user