aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/lib/List/Manga/CleanMangaList.svelte6
-rw-r--r--src/lib/List/Manga/MangaListTemplate.svelte14
-rw-r--r--src/lib/Media/manga.ts50
-rw-r--r--src/routes/api/mangadex/chapter/+server.ts26
-rw-r--r--src/routes/api/mangadex/feed/+server.ts22
-rw-r--r--src/routes/api/mangadex/manga/+server.ts21
6 files changed, 90 insertions, 49 deletions
diff --git a/src/lib/List/Manga/CleanMangaList.svelte b/src/lib/List/Manga/CleanMangaList.svelte
index 8f36f244..40082809 100644
--- a/src/lib/List/Manga/CleanMangaList.svelte
+++ b/src/lib/List/Manga/CleanMangaList.svelte
@@ -1,5 +1,6 @@
<script lang="ts">
import type { Media } from '$lib/AniList/media';
+ import Error from '$lib/Error.svelte';
import { volumeCount } from '$lib/Media/manga';
import { outboundLink } from '$lib/Media/media';
import settings from '../../../stores/settings';
@@ -17,12 +18,17 @@
) => Promise<void>;
export let pendingUpdate: number | null;
export let due: boolean;
+ export let rateLimited: boolean;
</script>
<ListTitle count={media.length} time={endTime / 1000}>
<a href={'#'} title="Force a full refresh" on:click={cleanCache}>Refresh</a>
</ListTitle>
+{#if rateLimited}
+ <Error />
+{/if}
+
{#if media.length === 0}
<ul>
<li>No manga to display. <a href={'#'} on:click={cleanCache}>Force refresh</a></li>
diff --git a/src/lib/List/Manga/MangaListTemplate.svelte b/src/lib/List/Manga/MangaListTemplate.svelte
index 370cfd72..c6ea8b7d 100644
--- a/src/lib/List/Manga/MangaListTemplate.svelte
+++ b/src/lib/List/Manga/MangaListTemplate.svelte
@@ -23,6 +23,7 @@
let previousMangaList: Media[];
let pendingUpdate: number | null = null;
let progress = 0;
+ let rateLimited = false;
const keyCacher = setInterval(() => {
startTime = performance.now();
@@ -84,7 +85,15 @@
const chapterCounts: (number | null)[] = [];
for (let i = 0; i < chapterPromises.length; i++) {
- chapterCounts.push(await chapterPromises[i]);
+ const count = await chapterPromises[i];
+
+ if (count === -22) {
+ rateLimited = true;
+
+ break;
+ }
+
+ chapterCounts.push(count);
progress += progressStep;
}
@@ -168,6 +177,7 @@
{updateMedia}
{pendingUpdate}
{due}
+ {rateLimited}
/>
{:else}
<ListTitle />
@@ -185,6 +195,7 @@
{updateMedia}
{pendingUpdate}
{due}
+ {rateLimited}
/>
{:else}
<ListTitle />
@@ -200,6 +211,7 @@
{updateMedia}
{pendingUpdate}
{due}
+ {rateLimited}
/>
{:catch}
<ListTitle count={-1337} time={0} />
diff --git a/src/lib/Media/manga.ts b/src/lib/Media/manga.ts
index af08d4eb..b8afbc96 100644
--- a/src/lib/Media/manga.ts
+++ b/src/lib/Media/manga.ts
@@ -51,24 +51,28 @@ export const chapterCount = async (
return await tryRecentMediaActivities();
}
- const mangadexData = await (
- await fetch(
- `/api/mangadex/manga?english=${manga.title.english}&year=${manga.startDate.year}&romaji=${manga.title.romaji}&native=${manga.title.native}&status=${manga.status}`
- )
- ).json();
+ const mangadexData = await fetch(
+ `/api/mangadex/manga?english=${manga.title.english}&year=${manga.startDate.year}&romaji=${manga.title.romaji}&native=${manga.title.native}&status=${manga.status}`
+ );
- if (mangadexData['data'] === undefined || mangadexData['data'].length === 0) {
+ if ((await mangadexData.clone().text()) === 'rate-limited') return -22;
+
+ const mangadexDataJson = await mangadexData.json();
+
+ if (mangadexDataJson['data'] === undefined || mangadexDataJson['data'].length === 0)
return await tryRecentMediaActivities();
- }
- const mangadexId = mangadexData['data'][0]['id'];
- const lastChapterData = await (await fetch(`/api/mangadex/feed?id=${mangadexId}`)).json();
+ const mangadexId = mangadexDataJson['data'][0]['id'];
+ const lastChapterData = await fetch(`/api/mangadex/feed?id=${mangadexId}`);
+
+ if ((await lastChapterData.clone().text()) === 'rate-limited') return -22;
+
+ const lastChapterDataJson = await lastChapterData.json();
- if (lastChapterData['data'] === undefined || lastChapterData['data'].length === 0) {
+ if (lastChapterDataJson['data'] === undefined || lastChapterDataJson['data'].length === 0)
return await tryRecentMediaActivities();
- }
- let lastChapter = lastChapterData['data'][0]['attributes']['chapter'];
+ let lastChapter = lastChapterDataJson['data'][0]['attributes']['chapter'];
let completedVolumes = null;
if ((manga.mediaListEntry || { progress: 0 }).progress > lastChapter) {
@@ -80,19 +84,23 @@ export const chapterCount = async (
}
if (!settings.get().disableOutOfDateVolumeWarning) {
- const volumeOfChapterData = await (
- await fetch(
- `/api/mangadex/chapter?id=${mangadexId}&chapter=${manga.mediaListEntry?.progress}`
- )
- ).json();
- let lastAvailableVolume = lastChapterData['data'][0]['attributes']['volume'];
+ const volumeOfChapterDataResponse = await fetch(
+ `/api/mangadex/chapter?id=${mangadexId}&chapter=${manga.mediaListEntry?.progress}`
+ );
+
+ if ((await volumeOfChapterDataResponse.clone().text()) === 'rate-limited') {
+ return -22;
+ }
+
+ const volumeOfChapterData = await volumeOfChapterDataResponse.json();
+ let lastAvailableVolume = lastChapterDataJson['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'];
+ while (chapterIndex < lastChapterDataJson['data'].length && lastAvailableVolume === null) {
+ if (lastChapterDataJson['data'][chapterIndex]['attributes']['volume'] !== null) {
+ lastAvailableVolume = lastChapterDataJson['data'][chapterIndex]['attributes']['volume'];
}
chapterIndex += 1;
diff --git a/src/routes/api/mangadex/chapter/+server.ts b/src/routes/api/mangadex/chapter/+server.ts
index b4b1a11d..602427ba 100644
--- a/src/routes/api/mangadex/chapter/+server.ts
+++ b/src/routes/api/mangadex/chapter/+server.ts
@@ -1,13 +1,17 @@
export const GET = async ({ url }) => {
- return Response.json(
- await (
- await fetch(
- `https://api.mangadex.org/chapter?manga=${url.searchParams.get(
- 'id'
- )}&chapter=${url.searchParams.get(
- 'chapter'
- )}&contentRating[]=safe&contentRating[]=suggestive&contentRating[]=erotica&contentRating[]=pornographic&limit=1`
- )
- ).json()
- );
+ try {
+ return Response.json(
+ await (
+ await fetch(
+ `https://api.mangadex.org/chapter?manga=${url.searchParams.get(
+ 'id'
+ )}&chapter=${url.searchParams.get(
+ 'chapter'
+ )}&contentRating[]=safe&contentRating[]=suggestive&contentRating[]=erotica&contentRating[]=pornographic&limit=1`
+ )
+ ).json()
+ );
+ } catch {
+ return new Response('rate-limited');
+ }
};
diff --git a/src/routes/api/mangadex/feed/+server.ts b/src/routes/api/mangadex/feed/+server.ts
index 862ef5e4..ab28ba2b 100644
--- a/src/routes/api/mangadex/feed/+server.ts
+++ b/src/routes/api/mangadex/feed/+server.ts
@@ -1,11 +1,15 @@
export const GET = async ({ url }) => {
- return Response.json(
- await (
- await fetch(
- `https://api.mangadex.org/manga/${url.searchParams.get(
- 'id'
- )}/feed?order[chapter]=desc&translatedLanguage[]=en&limit=1&contentRating[]=safe&contentRating[]=suggestive&contentRating[]=erotica&contentRating[]=pornographic`
- )
- ).json()
- );
+ try {
+ return Response.json(
+ await (
+ await fetch(
+ `https://api.mangadex.org/manga/${url.searchParams.get(
+ 'id'
+ )}/feed?order[chapter]=desc&translatedLanguage[]=en&limit=1&contentRating[]=safe&contentRating[]=suggestive&contentRating[]=erotica&contentRating[]=pornographic`
+ )
+ ).json()
+ );
+ } catch {
+ return new Response('rate-limited');
+ }
};
diff --git a/src/routes/api/mangadex/manga/+server.ts b/src/routes/api/mangadex/manga/+server.ts
index c2c75082..e80d0b6a 100644
--- a/src/routes/api/mangadex/manga/+server.ts
+++ b/src/routes/api/mangadex/manga/+server.ts
@@ -1,5 +1,6 @@
export const GET = async ({ url }) => {
let status = '';
+ let error = false;
switch (url.searchParams.get('status')) {
case 'FINISHED':
@@ -26,13 +27,17 @@ export const GET = async ({ url }) => {
const nullIfNullString = (s: string | null) => (s == 'null' ? null : s);
const get = async (title: string) => {
- return await (
- await fetch(
- `https://api.mangadex.org/manga?title=${encodeURIComponent(
- title
- )}&year=${url.searchParams.get('year')}&status[]=${status}`
- )
- ).json();
+ try {
+ return await (
+ await fetch(
+ `https://api.mangadex.org/manga?title=${encodeURIComponent(
+ title
+ )}&year=${url.searchParams.get('year')}&status[]=${status}`
+ )
+ ).json();
+ } catch {
+ error = true;
+ }
};
let mangadexData = await get(
@@ -42,6 +47,8 @@ export const GET = async ({ url }) => {
''
);
+ if (error) return new Response('rate-limited');
+
if (mangadexData['data'] === undefined || mangadexData['data'].length === 0) {
mangadexData = await get(nullIfNullString(url.searchParams.get('english')) || '');