aboutsummaryrefslogtreecommitdiff
path: root/src/lib/Reader/resource.ts
diff options
context:
space:
mode:
authorFuwn <[email protected]>2024-09-10 00:06:05 -0700
committerFuwn <[email protected]>2024-09-10 00:06:05 -0700
commitfcbc26f544a5ad7ec841561dec695aaceb63d709 (patch)
treec94210ebbdec428cac3cd7148ae2fb5929474d12 /src/lib/Reader/resource.ts
parentrefactor(reader): chapter list component (diff)
downloaddue.moe-fcbc26f544a5ad7ec841561dec695aaceb63d709.tar.xz
due.moe-fcbc26f544a5ad7ec841561dec695aaceb63d709.zip
feat(reader): add rawkuma chapter support
Diffstat (limited to 'src/lib/Reader/resource.ts')
-rw-r--r--src/lib/Reader/resource.ts40
1 files changed, 40 insertions, 0 deletions
diff --git a/src/lib/Reader/resource.ts b/src/lib/Reader/resource.ts
new file mode 100644
index 00000000..b96a890f
--- /dev/null
+++ b/src/lib/Reader/resource.ts
@@ -0,0 +1,40 @@
+export enum Resource {
+ MangaDex = 'MangaDex',
+ Rawkuma = 'Rawkuma'
+}
+
+export const identify = (url: string): Resource | undefined => {
+ if (url.match(/mangadex\.org\/title\/([a-f0-9-]+)\/?/)?.[1]) {
+ return Resource.MangaDex;
+ } else if (url.match(/rawkuma\.com\/manga\/([a-z0-9-]+)\/?/)?.[1]) {
+ return Resource.Rawkuma;
+ }
+
+ return undefined;
+};
+
+export const fetchResource = async (url: string) => {
+ const resource = identify(url);
+
+ if (resource === Resource.MangaDex) {
+ return await fetch(
+ `https://api.mangadex.org/manga/${
+ url.match(/mangadex\.org\/title\/([a-f0-9-]+)\/?/)?.[1]
+ }/feed?order[chapter]=desc&translatedLanguage[]=en`
+ );
+ } else if (resource === Resource.Rawkuma) {
+ return await fetch(url);
+ }
+
+ return fetch(url);
+};
+
+export const decodeResource = async (response: Response, url: string) => {
+ const resource = identify(url);
+
+ if (resource === Resource.MangaDex) {
+ return await response.json();
+ } else {
+ return await response.text();
+ }
+};