All checks were successful
Build and Push Container / build (push) Successful in 53s
60 lines
1.9 KiB
TypeScript
60 lines
1.9 KiB
TypeScript
import { getAllChapters, getLatestChapter } from './mangadex/chapters';
|
|
import { getManga } from './mangadex/manga';
|
|
import { getCover } from './mangadex/cover';
|
|
import { lazyKv } from './db/lazyKv';
|
|
import { sendWebhook } from './utils/webhook';
|
|
import { ChapterId } from './types';
|
|
import { getMangaToFetch } from './utils/get-manga-to-fetch';
|
|
import { getMangaTitle } from './utils/get-manga-title';
|
|
|
|
const config = new lazyKv('./config.json');
|
|
const mangaHistory = new lazyKv('./mangaHistory.json');
|
|
|
|
void (async () => {
|
|
const checkInterval = await config.get<number>('checkInterval', 900);
|
|
const userAgent = await config.get<string>(
|
|
'userAgent',
|
|
'https://git.pfy.ch/pfych/chapter-tracker (Missing custom userAgent? User Miss-configured!)',
|
|
);
|
|
|
|
const checkForUpdates = async () => {
|
|
const { uniqueMangaIds, mangaIdsToWebhooks } =
|
|
await getMangaToFetch(config);
|
|
|
|
for (const mangaId of uniqueMangaIds) {
|
|
const lastChapterId = await mangaHistory.get<ChapterId>(mangaId);
|
|
|
|
const manga = await getManga(mangaId, userAgent);
|
|
const chapters = await getAllChapters(mangaId, userAgent);
|
|
const latestChapter = getLatestChapter(chapters);
|
|
const cover = await getCover(manga, userAgent);
|
|
const title = getMangaTitle(manga);
|
|
|
|
if (lastChapterId !== latestChapter.id) {
|
|
console.log('Update found for manga:', title);
|
|
|
|
const webhooksForManga = mangaIdsToWebhooks[mangaId];
|
|
|
|
await Promise.all(
|
|
webhooksForManga.map(
|
|
async (webhookUrl) =>
|
|
await sendWebhook({
|
|
webhookUrl,
|
|
manga,
|
|
latestChapter,
|
|
cover,
|
|
}),
|
|
),
|
|
);
|
|
|
|
await mangaHistory.set(mangaId, latestChapter.id);
|
|
} else {
|
|
console.log('No Updates found for manga:', title);
|
|
}
|
|
}
|
|
};
|
|
|
|
setInterval(() => void checkForUpdates(), checkInterval * 1000);
|
|
await checkForUpdates();
|
|
})();
|