aboutsummaryrefslogtreecommitdiff
path: root/src/lib/Media
diff options
context:
space:
mode:
authorFuwn <[email protected]>2023-11-05 17:53:07 -0800
committerFuwn <[email protected]>2023-11-05 17:53:07 -0800
commit914623a2fc0804fd74b72cbddbe0d44d07a9e4ce (patch)
tree4998f4e780e81afbf61e67079432490128676b33 /src/lib/Media
parentfeat(list): display title as compliment (diff)
downloaddue.moe-914623a2fc0804fd74b72cbddbe0d44d07a9e4ce.tar.xz
due.moe-914623a2fc0804fd74b72cbddbe0d44d07a9e4ce.zip
feat(manga): display out-of-date volumes
Diffstat (limited to 'src/lib/Media')
-rw-r--r--src/lib/Media/chapters.ts3
-rw-r--r--src/lib/Media/manga.ts44
2 files changed, 41 insertions, 6 deletions
diff --git a/src/lib/Media/chapters.ts b/src/lib/Media/chapters.ts
index d580e6fa..a8a4d716 100644
--- a/src/lib/Media/chapters.ts
+++ b/src/lib/Media/chapters.ts
@@ -3,6 +3,7 @@ import Dexie, { type Table } from 'dexie';
export interface Chapter {
id: number;
chapters: number | null;
+ volumes: number | null;
}
export class ChapterDatabase extends Dexie {
@@ -11,7 +12,7 @@ export class ChapterDatabase extends Dexie {
constructor() {
super('chapterDatabase');
this.version(1).stores({
- chapters: 'id, chapters'
+ chapters: 'id, chapters, volumes'
});
this.chapters = this.table('chapters');
diff --git a/src/lib/Media/manga.ts b/src/lib/Media/manga.ts
index 3c0cf837..13f251eb 100644
--- a/src/lib/Media/manga.ts
+++ b/src/lib/Media/manga.ts
@@ -11,6 +11,9 @@ export const pruneAllManga = async () => {
await chapterDatabase.chapters.bulkDelete(ids);
};
+export const volumeCount = async (manga: Media): Promise<number | null> =>
+ (await chapterDatabase.chapters.get(manga.id))?.volumes as number | null;
+
export const chapterCount = async (
identity: UserIdentity,
manga: Media,
@@ -36,7 +39,8 @@ export const chapterCount = async (
await chapterDatabase.chapters.put({
id: manga.id,
- chapters: anilistData ? anilistData : -1
+ chapters: anilistData ? anilistData : -1,
+ volumes: null
});
return anilistData;
@@ -56,15 +60,15 @@ export const chapterCount = async (
return await tryRecentMediaActivities();
}
- const lastChapterData = await (
- await fetch(`/api/mangadex/feed?id=${mangadexData['data'][0]['id']}`)
- ).json();
+ const mangadexId = mangadexData['data'][0]['id'];
+ const lastChapterData = await (await fetch(`/api/mangadex/feed?id=${mangadexId}`)).json();
if (lastChapterData['data'] === undefined || lastChapterData['data'].length === 0) {
return await tryRecentMediaActivities();
}
let lastChapter = lastChapterData['data'][0]['attributes']['chapter'];
+ let completedVolumes = null;
if ((manga.mediaListEntry || { progress: 0 }).progress > lastChapter) {
const anilistData = await recentMediaActivities(identity, manga);
@@ -74,13 +78,43 @@ export const chapterCount = async (
}
}
+ const volumeOfChapterData = await (
+ await fetch(`/api/mangadex/chapter?id=${mangadexId}&chapter=${manga.mediaListEntry?.progress}`)
+ ).json();
+ let lastAvailableVolume = lastChapterData['data'][0]['attributes']['volume'];
+
+ if (lastAvailableVolume === null) {
+ let chapterIndex = 0;
+
+ while (chapterIndex < lastChapterData['data'].length && lastAvailableVolume === null) {
+ if (lastChapterData['data'][chapterIndex]['attributes']['volume'] !== null) {
+ lastAvailableVolume = lastChapterData['data'][chapterIndex]['attributes']['volume'];
+ }
+
+ chapterIndex += 1;
+ }
+ }
+
+ if (volumeOfChapterData['data'] !== undefined && volumeOfChapterData['data'].length > 0) {
+ const volumeOfChapter = volumeOfChapterData['data'][0]['attributes']['volume'];
+
+ if (volumeOfChapter !== null) {
+ completedVolumes = volumeOfChapter;
+ }
+
+ if (completedVolumes === volumeOfChapter) {
+ completedVolumes -= 1;
+ }
+ }
+
if (lastChapter == 0) {
lastChapter = -1;
}
await chapterDatabase.chapters.put({
id: manga.id,
- chapters: Number(lastChapter)
+ chapters: Number(lastChapter),
+ volumes: completedVolumes
});
return Number(lastChapter);