From bc23628890ba6d5aa77d93e4e738de27b3fc3fdf Mon Sep 17 00:00:00 2001 From: Viren070 Date: Sun, 19 Oct 2025 22:54:42 +0100 Subject: [PATCH] fix(anime-database): force refresh on failure during load --- packages/core/src/utils/anime-database.ts | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/packages/core/src/utils/anime-database.ts b/packages/core/src/utils/anime-database.ts index 8ea6233c..4299d13e 100644 --- a/packages/core/src/utils/anime-database.ts +++ b/packages/core/src/utils/anime-database.ts @@ -708,8 +708,9 @@ export class AnimeDatabase { const isDbMissing = !(await this.fileExists(source.filePath)); const isOutOfDate = !remoteEtag || !localEtag || remoteEtag !== localEtag; + const fetchFromRemote = isDbMissing || isOutOfDate; - if (isDbMissing || isOutOfDate) { + if (fetchFromRemote) { logger.info( `[${source.name}] Source is missing or out of date. Downloading...` ); @@ -722,7 +723,19 @@ export class AnimeDatabase { } else { logger.info(`[${source.name}] Source is up to date.`); } - await this[source.loader](); + try { + await this[source.loader](); + } catch (error) { + // if we didnt fetch from remote and loading it failed, force a refresh next time by deleting the local file and etag + if (!fetchFromRemote) { + logger.debug( + `[${source.name}] Deleting local file and etag due to error.` + ); + await fs.unlink(source.etagPath); + await fs.unlink(source.filePath); + } + throw error; + } }, { getContext: () => source.name,