aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFuwn <[email protected]>2023-12-26 23:44:41 -0800
committerFuwn <[email protected]>2023-12-26 23:44:41 -0800
commit4792d6c5fd628e9a455ef461d89b268a7ef114b3 (patch)
tree864c73df2c99c4cf48ea478461b9393041402d8d
parentstyle(settings.json): prettier (diff)
downloaddue.moe-4792d6c5fd628e9a455ef461d89b268a7ef114b3.tar.xz
due.moe-4792d6c5fd628e9a455ef461d89b268a7ef114b3.zip
feat(manga): distributed proxy
-rwxr-xr-xbun.lockbbin126026 -> 126395 bytes
-rw-r--r--package.json95
-rw-r--r--src/lib/List/Manga/MangaListTemplate.svelte139
-rw-r--r--src/lib/Media/Manga/chapters.ts99
-rw-r--r--src/lib/settings.json3
5 files changed, 198 insertions, 138 deletions
diff --git a/bun.lockb b/bun.lockb
index cf7e9157..095f7b28 100755
--- a/bun.lockb
+++ b/bun.lockb
Binary files differ
diff --git a/package.json b/package.json
index 8949b0f8..ab97fd5a 100644
--- a/package.json
+++ b/package.json
@@ -1,49 +1,50 @@
{
- "name": "due.moe",
- "version": "0.0.0",
- "private": true,
- "scripts": {
- "dev": "vite dev",
- "build": "vite build",
- "preview": "vite preview",
- "check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json",
- "check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch",
- "lint": "prettier --plugin-search-dir . --check . && eslint .",
- "format": "prettier --plugin-search-dir . --write ."
- },
- "devDependencies": {
- "@sveltejs/adapter-auto": "^2.0.0",
- "@sveltejs/kit": "^1.20.4",
- "@types/dom-to-image": "^2.6.5",
- "@types/fast-levenshtein": "^0.0.4",
- "@types/file-saver": "^2.0.5",
- "@types/jsdom": "^21.1.6",
- "@typescript-eslint/eslint-plugin": "^5.45.0",
- "@typescript-eslint/parser": "^5.45.0",
- "eslint": "^8.28.0",
- "eslint-config-prettier": "^8.5.0",
- "eslint-plugin-svelte": "^2.30.0",
- "prettier": "^2.8.0",
- "prettier-plugin-svelte": "^2.10.1",
- "svelte": "^4.0.5",
- "svelte-adapter-bun": "^0.5.0",
- "svelte-check": "^3.4.3",
- "sveltekit-rate-limiter": "^0.4.2",
- "tslib": "^2.4.1",
- "typescript": "^5.0.0",
- "vite": "^4.4.2"
- },
- "type": "module",
- "dependencies": {
- "bun-types": "^1.0.15",
- "dexie": "^4.0.1-alpha.25",
- "fast-levenshtein": "^3.0.0",
- "html2canvas": "^1.4.1",
- "jsdom": "^23.0.1",
- "modern-screenshot": "^4.4.33",
- "rss-parser": "^3.13.0",
- "socket.io": "^4.7.2",
- "socket.io-client": "^4.7.2",
- "wanakana": "^5.3.1"
- }
+ "name": "due.moe",
+ "version": "0.0.0",
+ "private": true,
+ "scripts": {
+ "dev": "vite dev",
+ "build": "vite build",
+ "preview": "vite preview",
+ "check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json",
+ "check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch",
+ "lint": "prettier --plugin-search-dir . --check . && eslint .",
+ "format": "prettier --plugin-search-dir . --write ."
+ },
+ "devDependencies": {
+ "@sveltejs/adapter-auto": "^2.0.0",
+ "@sveltejs/kit": "^1.20.4",
+ "@types/dom-to-image": "^2.6.5",
+ "@types/fast-levenshtein": "^0.0.4",
+ "@types/file-saver": "^2.0.5",
+ "@types/jsdom": "^21.1.6",
+ "@typescript-eslint/eslint-plugin": "^5.45.0",
+ "@typescript-eslint/parser": "^5.45.0",
+ "eslint": "^8.28.0",
+ "eslint-config-prettier": "^8.5.0",
+ "eslint-plugin-svelte": "^2.30.0",
+ "prettier": "^2.8.0",
+ "prettier-plugin-svelte": "^2.10.1",
+ "svelte": "^4.0.5",
+ "svelte-adapter-bun": "^0.5.0",
+ "svelte-check": "^3.4.3",
+ "sveltekit-rate-limiter": "^0.4.2",
+ "tslib": "^2.4.1",
+ "typescript": "^5.0.0",
+ "vite": "^4.4.2"
+ },
+ "type": "module",
+ "dependencies": {
+ "bun-types": "^1.0.15",
+ "dexie": "^4.0.1-alpha.25",
+ "fast-levenshtein": "^3.0.0",
+ "fetch-jsonp": "^1.3.0",
+ "html2canvas": "^1.4.1",
+ "jsdom": "^23.0.1",
+ "modern-screenshot": "^4.4.33",
+ "rss-parser": "^3.13.0",
+ "socket.io": "^4.7.2",
+ "socket.io-client": "^4.7.2",
+ "wanakana": "^5.3.1"
+ }
}
diff --git a/src/lib/List/Manga/MangaListTemplate.svelte b/src/lib/List/Manga/MangaListTemplate.svelte
index 256a4900..4e92acd8 100644
--- a/src/lib/List/Manga/MangaListTemplate.svelte
+++ b/src/lib/List/Manga/MangaListTemplate.svelte
@@ -12,7 +12,6 @@
import Error from '$lib/Error/RateLimited.svelte';
import CleanMangaList from './CleanMangaList.svelte';
import authorisedJson from '$lib/authorised.json';
- import serviceSettings from '$lib/settings.json';
export let user: AniListAuthorisation;
export let identity: UserIdentity;
@@ -168,14 +167,42 @@
};
</script>
-{#if serviceSettings.disabled}
- <ListTitle />
+{#await mangaLists}
+ {#if !authorised}
+ <ListTitle count={0} time={endTime / 1000}>
+ <a
+ href={'#'}
+ title="Force a full refresh"
+ on:click={() => {
+ cleanCache();
+
+ forceFlag = true;
+ }}>Refresh</a
+ >
+ </ListTitle>
+ {/if}
+
+ {#if previousMangaList}
+ <CleanMangaList
+ media={previousMangaList}
+ {cleanCache}
+ {lastUpdatedMedia}
+ {updateMedia}
+ {endTime}
+ {pendingUpdate}
+ {due}
+ {rateLimited}
+ {authorised}
+ />
+ {:else}
+ {#if authorised}
+ <ListTitle />
+ {/if}
- <ul>
- <li>Manga is currently unavailable due to API abuse. Check back later.</li>
- </ul>
-{:else}
- {#await mangaLists}
+ <ul><li>Loading {progress.toFixed(0)}% ...</li></ul>
+ {/if}
+{:then media}
+ {#await cleanMedia(media, displayUnresolved, forceFlag)}
{#if !authorised}
<ListTitle count={0} time={endTime / 1000}>
<a
@@ -209,73 +236,37 @@
<ul><li>Loading {progress.toFixed(0)}% ...</li></ul>
{/if}
- {:then media}
- {#await cleanMedia(media, displayUnresolved, forceFlag)}
- {#if !authorised}
- <ListTitle count={0} time={endTime / 1000}>
- <a
- href={'#'}
- title="Force a full refresh"
- on:click={() => {
- cleanCache();
-
- forceFlag = true;
- }}>Refresh</a
- >
- </ListTitle>
- {/if}
+ {:then cleanedMedia}
+ {#if !authorised}
+ <ListTitle count={cleanedMedia.length} time={endTime / 1000}>
+ <a
+ href={'#'}
+ title="Force a full refresh"
+ on:click={() => {
+ cleanCache();
- {#if previousMangaList}
- <CleanMangaList
- media={previousMangaList}
- {cleanCache}
- {lastUpdatedMedia}
- {updateMedia}
- {endTime}
- {pendingUpdate}
- {due}
- {rateLimited}
- {authorised}
- />
- {:else}
- {#if authorised}
- <ListTitle />
- {/if}
-
- <ul><li>Loading {progress.toFixed(0)}% ...</li></ul>
- {/if}
- {:then cleanedMedia}
- {#if !authorised}
- <ListTitle count={cleanedMedia.length} time={endTime / 1000}>
- <a
- href={'#'}
- title="Force a full refresh"
- on:click={() => {
- cleanCache();
-
- forceFlag = true;
- }}>Refresh</a
- >
- </ListTitle>
- {/if}
+ forceFlag = true;
+ }}>Refresh</a
+ >
+ </ListTitle>
+ {/if}
- <CleanMangaList
- media={cleanedMedia}
- {cleanCache}
- {lastUpdatedMedia}
- {updateMedia}
- {endTime}
- {pendingUpdate}
- {due}
- {rateLimited}
- {authorised}
- />
- {:catch}
- {#if authorised}
- <ListTitle count={-1337} time={0} />
- {/if}
+ <CleanMangaList
+ media={cleanedMedia}
+ {cleanCache}
+ {lastUpdatedMedia}
+ {updateMedia}
+ {endTime}
+ {pendingUpdate}
+ {due}
+ {rateLimited}
+ {authorised}
+ />
+ {:catch}
+ {#if authorised}
+ <ListTitle count={-1337} time={0} />
+ {/if}
- <Error />
- {/await}
+ <Error />
{/await}
-{/if}
+{/await}
diff --git a/src/lib/Media/Manga/chapters.ts b/src/lib/Media/Manga/chapters.ts
index 2e3c6678..36942ce4 100644
--- a/src/lib/Media/Manga/chapters.ts
+++ b/src/lib/Media/Manga/chapters.ts
@@ -3,6 +3,75 @@ import settings from '../../../stores/settings';
import type { UserIdentity } from '../../AniList/identity';
import { database } from '../../Database/chapters';
+const getManga = async (
+ statusIn: string,
+ year: number,
+ native: string | null,
+ english: string | null,
+ romaji: string | null
+) => {
+ let status = '';
+ let error = false;
+
+ switch (statusIn) {
+ case 'FINISHED':
+ {
+ status = 'completed';
+ }
+ break;
+ case 'RELEASING':
+ {
+ status = 'ongoing';
+ }
+ break;
+ case 'HIATUS':
+ {
+ status = 'hiatus';
+ }
+ break;
+ case 'CANCELLED':
+ {
+ status = 'cancelled';
+ }
+ break;
+ }
+
+ const nullIfNullString = (s: string | null) => (s == 'null' ? null : s);
+ const get = async (title: string) => {
+ try {
+ return await (
+ await fetch(
+ `https://due-proxy.fuwn.workers.dev/?q=https://api.mangadex.org/manga?title=${encodeURIComponent(
+ title
+ )}&year=${year}&status[]=${status}`
+ )
+ ).json();
+ } catch {
+ error = true;
+ }
+ };
+
+ let mangadexData = await get(
+ nullIfNullString(native) || nullIfNullString(english) || nullIfNullString(romaji) || ''
+ );
+
+ if (error) return new Response('rate-limited');
+
+ if (mangadexData['data'] === undefined || mangadexData['data'].length === 0) {
+ mangadexData = await get(nullIfNullString(english) || '');
+
+ if (mangadexData['data'] === undefined || mangadexData['data'].length === 0) {
+ mangadexData = await get(nullIfNullString(romaji) || '');
+ }
+ }
+
+ return Response.json(mangadexData, {
+ headers: {
+ 'Cache-Control': 'max-age=300'
+ }
+ });
+};
+
export const chapterCount = async (
identity: UserIdentity,
manga: Media,
@@ -37,8 +106,12 @@ export const chapterCount = async (
if (manga.format === 'NOVEL') return await tryRecentMediaActivities();
- 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}`
+ 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;
@@ -49,11 +122,11 @@ export const chapterCount = async (
return await tryRecentMediaActivities();
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();
+ const lastChapterDataJson = await (
+ await fetch(
+ `https://due-proxy.fuwn.workers.dev/?q=https://api.mangadex.org/manga/${mangadexId}/feed?order[chapter]=desc&translatedLanguage[]=en&limit=1&contentRating[]=safe&contentRating[]=suggestive&contentRating[]=erotica&contentRating[]=pornographic`
+ )
+ ).json();
if (lastChapterDataJson['data'] === undefined || lastChapterDataJson['data'].length === 0)
return await tryRecentMediaActivities();
@@ -72,13 +145,11 @@ export const chapterCount = async (
}
if (!settings.get().calculateDisableOutOfDateVolumeWarning) {
- 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();
+ const volumeOfChapterData = await (
+ await fetch(
+ `https://due-proxy.fuwn.workers.dev/?q=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'];
if (lastAvailableVolume === null) {
diff --git a/src/lib/settings.json b/src/lib/settings.json
deleted file mode 100644
index 5d318736..00000000
--- a/src/lib/settings.json
+++ /dev/null
@@ -1,3 +0,0 @@
-{
- "disabled": true
-}