fix: linting (#1184)

This commit is contained in:
Fredrik Burmester
2025-11-14 19:34:59 +01:00
committed by GitHub
parent 30dc3980e3
commit 2be78a232c
25 changed files with 114 additions and 70 deletions

View File

@@ -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);

View File

@@ -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
*/

View File

@@ -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)}...`,
);

View File

@@ -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;
}
}
});