From 4aa6f996765119ad2b755230411526602b196ea5 Mon Sep 17 00:00:00 2001 From: MasutaYunikon Date: Mon, 23 Mar 2026 05:37:23 +0100 Subject: [PATCH] fix: path now work on every device --- server/index.ts | 4 ++-- server/organize-worker.ts | 29 ++++++++++++++++++++++------- server/organize.ts | 6 +++++- 3 files changed, 29 insertions(+), 10 deletions(-) diff --git a/server/index.ts b/server/index.ts index 4a81b69..d644a8c 100644 --- a/server/index.ts +++ b/server/index.ts @@ -206,9 +206,9 @@ function buildResolvedEpisodes(sd: any, hash: string, seasonFilter?: number): an let filePath: string | null = null for (const p of paths) { if (typeof p === 'string') { - if (!filePath) filePath = p // legacy fallback + if (!filePath) filePath = p.replace(/\\/g, '/') // legacy fallback } else if (p?.infohash?.toLowerCase() === h) { - filePath = p.path + filePath = p.path.replace(/\\/g, '/') break } } diff --git a/server/organize-worker.ts b/server/organize-worker.ts index ed0d156..1cfa664 100644 --- a/server/organize-worker.ts +++ b/server/organize-worker.ts @@ -80,7 +80,7 @@ function findTorrentByHash(hash: string, seriesData: any[]): { torrent: any; ser } // Construit la map filename → { season_number, original_filename, fullPath } -// en matchant par infohash dans ep.paths[] +// Supporte les deux formats : { infohash, path } et string (legacy) function buildFileMap( serieData : any, hash : string, @@ -92,14 +92,25 @@ function buildFileMap( for (const season of serieData.seasons ?? []) { if (seasonFilter !== undefined && season.season_number !== seasonFilter) continue for (const ep of season.episodes ?? []) { - const match = (ep.paths ?? []).find((p: any) => p.infohash?.toLowerCase() === h) - if (!match) continue - const filename = match.path.split('/').pop() ?? match.path + const paths: any[] = ep.paths ?? [] + let matchedPath: string | null = null + + for (const p of paths) { + if (typeof p === 'string') { + if (!matchedPath) matchedPath = p.replace(/\\/g, '/') + } else if (p?.infohash?.toLowerCase() === h) { + matchedPath = p.path.replace(/\\/g, '/') + break + } + } + + if (!matchedPath) continue + const filename = matchedPath.split('/').pop() ?? matchedPath const original = ep.original_filename ?? filename map.set(filename, { season_number : season.season_number, original_filename: original, - fullPath : match.path, + fullPath : matchedPath, }) } } @@ -224,8 +235,12 @@ async function organizeTorrent(hash: string, name: string, savePath: string, ser if (torrent._episode) { const ep = torrent._episode const season = torrent._season - const match = (ep.paths ?? []).find((p: any) => p.infohash?.toLowerCase() === hash.toLowerCase()) - const filePath = match?.path ?? null + const paths: any[] = ep.paths ?? [] + let filePath: string | null = null + for (const p of paths) { + if (typeof p === 'string') { if (!filePath) filePath = p.replace(/\\/g, '/') } + else if (p?.infohash?.toLowerCase() === hash.toLowerCase()) { filePath = p.path.replace(/\\/g, '/'); break } + } const filename = filePath?.split('/').pop() ?? name const original = ep.original_filename ?? filename const destDir = path.join(mediaPath, serieTitle, seasonFolder(season.season_number ?? 1)) diff --git a/server/organize.ts b/server/organize.ts index b86bb9e..71adbfc 100644 --- a/server/organize.ts +++ b/server/organize.ts @@ -54,9 +54,13 @@ export async function scanMediaPath( for (const season of sd.seasons ?? []) { for (const ep of season.episodes ?? []) { for (const p of ep.paths ?? []) { + if (typeof p === 'string') { + // Legacy : pas d'infohash disponible, on skip pour le scan + continue + } const hash = p.infohash?.toLowerCase() if (!hash || !p.path) continue - const filename = p.path.split('/').pop() + const filename = p.path.replace(/\\/g, '/').split('/').pop() if (filename) filenameIndex.set(filename, hash) } }