Skip to content

Commit

Permalink
fix: clear mangal cache when checking out of sync chapters
Browse files Browse the repository at this point in the history
  • Loading branch information
oae committed Feb 7, 2023
1 parent 1ffdcae commit 6578201
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/server/trpc/router/manga.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { scheduleUpdateMetadata } from '../../queue/updateMetadata';
import { scanLibrary } from '../../utils/integration';
import {
bindTitleToAnilistId,
clearCache,
getAvailableSources,
getMangaDetail,
getMangaMetadata,
Expand Down Expand Up @@ -405,6 +406,7 @@ export const mangaRouter = t.router({
});
}
const { id } = input;
await clearCache();
if (id) {
await checkOutOfSyncChaptersQueue.add(nanoid(), { mangaId: id });
} else {
Expand Down
15 changes: 15 additions & 0 deletions src/server/utils/mangal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,21 @@ export const removeChapter = async (mangaDir: string, chapterFileName: string) =
await fs.rm(path.join(mangaDir, chapterFileName), { force: true });
};

export const clearCache = async () => {
try {
const { stdout, escapedCommand } = await execa('mangal', ['where', '--cache']);
logger.info(`Getting mangal cache path with following command: ${escapedCommand}`);
const cachedFiles = await fs.readdir(stdout);
await Promise.all(
cachedFiles
.filter((cachedFile) => cachedFile.endsWith('json') && cachedFile.indexOf('anilist') < 0)
.map(async (cachedJson) => fs.rm(path.join(stdout, cachedJson), { force: true })),
);
} catch (err) {
logger.error(`Failed to remove mangal cache. err: ${err}`);
}
};

export const getOutOfSyncChapters = async (mangaDir: string, source: string, title: string) => {
const localChapters = await getChaptersFromLocal(mangaDir);
const remoteChapters = await getChaptersFromRemote(source, title);
Expand Down

0 comments on commit 6578201

Please sign in to comment.