refactor: formatting

This commit is contained in:
wea_ondara
2023-11-25 16:59:36 +01:00
parent d8bb97805c
commit 96150718e0
3 changed files with 10 additions and 13 deletions

View File

@@ -78,11 +78,13 @@ export class MangaUpdatesCache {
.filter(([title, entry]) => entry.lastUpdateMs + this.MAX_CACHE_AGE_SEARCH_BY_TITLE < Date.now()) .filter(([title, entry]) => entry.lastUpdateMs + this.MAX_CACHE_AGE_SEARCH_BY_TITLE < Date.now())
.map(([title, entry]) => title); .map(([title, entry]) => title);
} }
getOutOfDateSeries(): string[] { getOutOfDateSeries(): string[] {
return Array.from(this._seriesById.entries()) return Array.from(this._seriesById.entries())
.filter(([title, entry]) => entry.lastUpdateMs + this.MAX_CACHE_AGE_SERIES_BY_ID < Date.now()) .filter(([title, entry]) => entry.lastUpdateMs + this.MAX_CACHE_AGE_SERIES_BY_ID < Date.now())
.map(([title, entry]) => title); .map(([title, entry]) => title);
} }
getOutOfDateSeriesGroups(): string[] { getOutOfDateSeriesGroups(): string[] {
return Array.from(this._seriesGroupsById.entries()) return Array.from(this._seriesGroupsById.entries())
.filter(([title, entry]) => entry.lastUpdateMs + this.MAX_CACHE_AGE_SERIES_GROUPS_BY_ID < Date.now()) .filter(([title, entry]) => entry.lastUpdateMs + this.MAX_CACHE_AGE_SERIES_GROUPS_BY_ID < Date.now())

View File

@@ -8,7 +8,7 @@ import * as fs from 'fs';
import {MangaDexCache} from './cache/MangaDexCache'; import {MangaDexCache} from './cache/MangaDexCache';
import mangaDexRouter from './router/MangaDexRouter'; import mangaDexRouter from './router/MangaDexRouter';
const config = JSON.parse(fs.readFileSync('config.json').toString()) const config = JSON.parse(fs.readFileSync('config.json').toString());
const app = express(); const app = express();
const mangaDexCache = new MangaDexCache(); const mangaDexCache = new MangaDexCache();
@@ -25,7 +25,7 @@ app.use(express.json());
app.use('/anilist', aniListRouter()); app.use('/anilist', aniListRouter());
app.use('/mangadex', mangaDexRouter(mangaDexCache)); app.use('/mangadex', mangaDexRouter(mangaDexCache));
app.use('/mangaupdates', mangaUpdatesRouter(mangaUpdatesCache)); app.use('/mangaupdates', mangaUpdatesRouter(mangaUpdatesCache));
app.use(express.static('_client')) //for production app.use(express.static('_client')); //for production
//start //start
app.listen(config.port, config.host, () => { app.listen(config.port, config.host, () => {

View File

@@ -16,17 +16,11 @@ export default class MangaUpdatesDataService {
const mangaStore = new MangaStore(); const mangaStore = new MangaStore();
const dbStore = new DbStore(); const dbStore = new DbStore();
return this.findMissingRelations(mangaStore, dbStore, progress) return this.findMissingRelations(mangaStore, dbStore, progress)
.catch(err => { .catch(err => console.error(err))
console.error(err);
})
.then(_ => this.fetchSeriesUpdates(mangaStore, dbStore, progress)) .then(_ => this.fetchSeriesUpdates(mangaStore, dbStore, progress))
.catch(err => { .catch(err => console.error(err))
console.error(err);
})
.then(_ => this.fetchSeriesChapterUpdates(mangaStore, dbStore, progress)) .then(_ => this.fetchSeriesChapterUpdates(mangaStore, dbStore, progress))
.catch(err => { .catch(err => console.error(err))
console.error(err);
})
.then(_ => progress.onFinished()); .then(_ => progress.onFinished());
} }
@@ -73,6 +67,7 @@ export default class MangaUpdatesDataService {
} }
break; break;
} }
if (matching.length === 0) { if (matching.length === 0) {
continue; continue;
} }
@@ -117,7 +112,7 @@ export default class MangaUpdatesDataService {
const series = await dbStore.mangaUpdatesRepository.getSeries(); const series = await dbStore.mangaUpdatesRepository.getSeries();
let i = 0; let i = 0;
const cachedChapterUpdates: MangaUpdatesChapter[] = [] const cachedChapterUpdates: MangaUpdatesChapter[] = [];
for (const s of series) { for (const s of series) {
try { try {
let groups; let groups;
@@ -146,7 +141,7 @@ export default class MangaUpdatesDataService {
//only keep chapter with the highest chapter number per group //only keep chapter with the highest chapter number per group
const filtered = Array.from(groupBy(updates, c => c.group).values()) const filtered = Array.from(groupBy(updates, c => c.group).values())
.map(chaptersOfGroup => chaptersOfGroup.reduce((l, r) => l.chapter > r.chapter ? l : r, chaptersOfGroup[0])); .map(chaptersOfGroup => chaptersOfGroup.reduce((l, r) => l.chapter > r.chapter ? l : r, chaptersOfGroup[0]));
cachedChapterUpdates.push(...filtered) cachedChapterUpdates.push(...filtered);
} finally { } finally {
await progress.onProgress('mangaUpdates.chapters', ++i, series.length); await progress.onProgress('mangaUpdates.chapters', ++i, series.length);
} }