aboutsummaryrefslogtreecommitdiff
path: root/src/lib/Media
diff options
context:
space:
mode:
authorFuwn <[email protected]>2024-07-22 16:33:36 -0700
committerFuwn <[email protected]>2024-07-22 16:33:36 -0700
commitb653365fb7705c3945139d5a00abd7fa1cf92879 (patch)
tree7eb9038398b619ebe3d44221b8d035fc3b423cec /src/lib/Media
parentfeat(Data): raw manga chapter count handler (diff)
downloaddue.moe-b653365fb7705c3945139d5a00abd7fa1cf92879.tar.xz
due.moe-b653365fb7705c3945139d5a00abd7fa1cf92879.zip
feat(Manga): allow preferring native chapter count
Diffstat (limited to 'src/lib/Media')
-rw-r--r--src/lib/Media/Manga/chapters.ts106
1 files changed, 57 insertions, 49 deletions
diff --git a/src/lib/Media/Manga/chapters.ts b/src/lib/Media/Manga/chapters.ts
index 7d774006..f9ae1b64 100644
--- a/src/lib/Media/Manga/chapters.ts
+++ b/src/lib/Media/Manga/chapters.ts
@@ -1,4 +1,5 @@
import { recentMediaActivities, type Media } from '$lib/Data/AniList/media';
+import { getChapterCount } from '$lib/Data/Manga/raw';
import proxy from '$lib/Utility/proxy';
import settings from '$stores/settings';
import type { UserIdentity } from '../../Data/AniList/identity';
@@ -117,74 +118,81 @@ export const chapterCount = async (
if (manga.format === 'NOVEL') return await tryRecentMediaActivities();
- const mangadexData = await getManga(
- manga.status,
- manga.startDate.year,
- manga.title.native,
- manga.title.english,
- manga.title.romaji
- );
+ let lastChapter = 0;
+ let completedVolumes = null;
+
+ if (!settings.get().calculatePreferNativeChapterCount) {
+ const mangadexData = await getManga(
+ manga.status,
+ manga.startDate.year,
+ manga.title.native,
+ manga.title.english,
+ manga.title.romaji
+ );
- if ((await mangadexData.clone().text()) === 'rate-limited') return -22;
+ if ((await mangadexData.clone().text()) === 'rate-limited') return -22;
- const mangadexDataJson = await mangadexData.json();
+ const mangadexDataJson = await mangadexData.json();
- if (mangadexDataJson['data'] === undefined || mangadexDataJson['data'].length === 0)
- return await tryRecentMediaActivities();
+ if (mangadexDataJson['data'] === undefined || mangadexDataJson['data'].length === 0)
+ return await tryRecentMediaActivities();
- const mangadexId = mangadexDataJson['data'][0]['id'];
- const lastChapterDataJson = await (
- await fetch(
- proxy(
- `https://api.mangadex.org/manga/${mangadexId}/feed?order[chapter]=desc&translatedLanguage[]=en&limit=1&contentRating[]=safe&contentRating[]=suggestive&contentRating[]=erotica&contentRating[]=pornographic`
+ const mangadexId = mangadexDataJson['data'][0]['id'];
+ const lastChapterDataJson = await (
+ await fetch(
+ proxy(
+ `https://api.mangadex.org/manga/${mangadexId}/feed?order[chapter]=desc&translatedLanguage[]=en&limit=1&contentRating[]=safe&contentRating[]=suggestive&contentRating[]=erotica&contentRating[]=pornographic`
+ )
)
- )
- ).json();
+ ).json();
- if (lastChapterDataJson['data'] === undefined || lastChapterDataJson['data'].length === 0)
- return await tryRecentMediaActivities();
+ if (lastChapterDataJson['data'] === undefined || lastChapterDataJson['data'].length === 0)
+ return await tryRecentMediaActivities();
- let lastChapter = lastChapterDataJson['data'][0]['attributes']['chapter'];
- let completedVolumes = null;
+ lastChapter = lastChapterDataJson['data'][0]['attributes']['chapter'];
+ completedVolumes = null;
- if ((manga.mediaListEntry || { progress: 0 }).progress > lastChapter && !disableGuessing) {
- const anilistData = await recentMediaActivities(
- identity,
- manga,
- settings.get().calculateGuessMethod
- );
+ if ((manga.mediaListEntry || { progress: 0 }).progress > lastChapter && !disableGuessing) {
+ const anilistData = await recentMediaActivities(
+ identity,
+ manga,
+ settings.get().calculateGuessMethod
+ );
- if (anilistData !== null && anilistData > lastChapter) lastChapter = anilistData;
- }
+ if (anilistData !== null && anilistData > lastChapter) lastChapter = anilistData;
+ }
- if (!settings.get().calculateDisableOutOfDateVolumeWarning) {
- const volumeOfChapterData = await (
- await fetch(
- proxy(
- `https://api.mangadex.org/chapter?manga=${mangadexId}&chapter=${manga.mediaListEntry?.progress}&contentRating[]=safe&contentRating[]=suggestive&contentRating[]=erotica&contentRating[]=pornographic&limit=1`
+ if (!settings.get().calculateDisableOutOfDateVolumeWarning) {
+ const volumeOfChapterData = await (
+ await fetch(
+ proxy(
+ `https://api.mangadex.org/chapter?manga=${mangadexId}&chapter=${manga.mediaListEntry?.progress}&contentRating[]=safe&contentRating[]=suggestive&contentRating[]=erotica&contentRating[]=pornographic&limit=1`
+ )
)
- )
- ).json();
- let lastAvailableVolume = lastChapterDataJson['data'][0]['attributes']['volume'];
+ ).json();
+ let lastAvailableVolume = lastChapterDataJson['data'][0]['attributes']['volume'];
- if (lastAvailableVolume === null) {
- let chapterIndex = 0;
+ if (lastAvailableVolume === null) {
+ let chapterIndex = 0;
- while (chapterIndex < lastChapterDataJson['data'].length && lastAvailableVolume === null) {
- if (lastChapterDataJson['data'][chapterIndex]['attributes']['volume'] !== null)
- lastAvailableVolume = lastChapterDataJson['data'][chapterIndex]['attributes']['volume'];
+ while (chapterIndex < lastChapterDataJson['data'].length && lastAvailableVolume === null) {
+ if (lastChapterDataJson['data'][chapterIndex]['attributes']['volume'] !== null)
+ lastAvailableVolume = lastChapterDataJson['data'][chapterIndex]['attributes']['volume'];
- chapterIndex += 1;
+ chapterIndex += 1;
+ }
}
- }
- if (volumeOfChapterData['data'] !== undefined && volumeOfChapterData['data'].length > 0) {
- const volumeOfChapter = volumeOfChapterData['data'][0]['attributes']['volume'];
+ if (volumeOfChapterData['data'] !== undefined && volumeOfChapterData['data'].length > 0) {
+ const volumeOfChapter = volumeOfChapterData['data'][0]['attributes']['volume'];
- if (volumeOfChapter !== null) completedVolumes = volumeOfChapter;
+ if (volumeOfChapter !== null) completedVolumes = volumeOfChapter;
- if (completedVolumes === volumeOfChapter) completedVolumes -= 1;
+ if (completedVolumes === volumeOfChapter) completedVolumes -= 1;
+ }
}
+ } else {
+ lastChapter = (await getChapterCount(manga.title.native)) || 0;
}
if (lastChapter == 0) lastChapter = -1;