diff --git a/server/index.ts b/server/index.ts index 978471b..aca2bf8 100644 --- a/server/index.ts +++ b/server/index.ts @@ -11,7 +11,7 @@ import transmissionDriver from './torrent-clients/transmission.js' import synologyDsDriver from './torrent-clients/synology-ds.js' import utorrentDriver from './torrent-clients/utorrent.js' import rtorrentDriver from './torrent-clients/rtorrent.js' -import { autoOrganizeAll, scanMediaPath } from './organize.js' +import { autoOrganizeAll, scanMediaPath, syncFilenameChanges } from './organize.js' import { logger } from './logger.js' import { DATA_DIR, BASE_DIR } from './config.js' import { readAvailable, readInfohashMap, loadEnrichedSeriesData } from './lib/github-cache.js' @@ -139,4 +139,17 @@ server.listen(PORT, async () => { checkNfoUpdates().catch(err => logger.error('nfo-update', `Vérif horaire échouée : ${err instanceof Error ? err.message : err}`)) }, 60 * 60_000) }, 30_000) + + // Sync automatique des noms de fichiers toutes les heures. + // Le TTL du cache GitHub est de 1h — ce setInterval tire toujours sur des données fraîches. + setInterval(async () => { + try { + const seriesData = await loadEnrichedSeriesData() + const { renamed } = await syncFilenameChanges(seriesData, path.join(DATA_DIR, 'organized.json')) + if (renamed > 0) + logger.info('api', `Sync noms auto — ${renamed} fichier(s) renommé(s)`) + } catch (err) { + logger.error('api', `Sync noms auto échoué : ${err instanceof Error ? err.message : err}`) + } + }, 60 * 60_000) })