Skip to content
This repository was archived by the owner on Feb 3, 2025. It is now read-only.

Commit 6578201

Browse files
committed
fix: clear mangal cache when checking out of sync chapters
1 parent 1ffdcae commit 6578201

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

src/server/trpc/router/manga.ts

+2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { scheduleUpdateMetadata } from '../../queue/updateMetadata';
1212
import { scanLibrary } from '../../utils/integration';
1313
import {
1414
bindTitleToAnilistId,
15+
clearCache,
1516
getAvailableSources,
1617
getMangaDetail,
1718
getMangaMetadata,
@@ -405,6 +406,7 @@ export const mangaRouter = t.router({
405406
});
406407
}
407408
const { id } = input;
409+
await clearCache();
408410
if (id) {
409411
await checkOutOfSyncChaptersQueue.add(nanoid(), { mangaId: id });
410412
} else {

src/server/utils/mangal.ts

+15
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,21 @@ export const removeChapter = async (mangaDir: string, chapterFileName: string) =
378378
await fs.rm(path.join(mangaDir, chapterFileName), { force: true });
379379
};
380380

381+
export const clearCache = async () => {
382+
try {
383+
const { stdout, escapedCommand } = await execa('mangal', ['where', '--cache']);
384+
logger.info(`Getting mangal cache path with following command: ${escapedCommand}`);
385+
const cachedFiles = await fs.readdir(stdout);
386+
await Promise.all(
387+
cachedFiles
388+
.filter((cachedFile) => cachedFile.endsWith('json') && cachedFile.indexOf('anilist') < 0)
389+
.map(async (cachedJson) => fs.rm(path.join(stdout, cachedJson), { force: true })),
390+
);
391+
} catch (err) {
392+
logger.error(`Failed to remove mangal cache. err: ${err}`);
393+
}
394+
};
395+
381396
export const getOutOfSyncChapters = async (mangaDir: string, source: string, title: string) => {
382397
const localChapters = await getChaptersFromLocal(mangaDir);
383398
const remoteChapters = await getChaptersFromRemote(source, title);

0 commit comments

Comments
 (0)