aboutsummaryrefslogtreecommitdiff
path: root/src/routes/reader
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/routes/reader
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/routes/reader')
-rw-r--r--src/routes/reader/+page.svelte28
1 files changed, 15 insertions, 13 deletions
diff --git a/src/routes/reader/+page.svelte b/src/routes/reader/+page.svelte
index 05e47274..98c3ae1c 100644
--- a/src/routes/reader/+page.svelte
+++ b/src/routes/reader/+page.svelte
@@ -1,34 +1,36 @@
<script>
import Notice from '$lib/Error/Notice.svelte';
import Message from '$lib/Loading/Message.svelte';
- import Chapters from '$lib/Reader/Chapters.svelte';
+ import MangaDexChapters from '$lib/Reader/Chapters/MangaDex.svelte';
+ import RawkumaChapters from '$lib/Reader/Chapters/Rawkuma.svelte';
+ import { decodeResource, fetchResource, identify, Resource } from '$lib/Reader/resource';
import InputTemplate from '$lib/Tools/InputTemplate.svelte';
let submission = '';
- $: mangaDexID = submission.match(/mangadex\.org\/title\/([a-f0-9-]+)\/?/)?.[1];
+ $: resourceIdentity = identify(submission);
</script>
-<InputTemplate field="MangaDex URL" bind:submission submitText="Read" preserveCase>
- {#if mangaDexID}
- {#await fetch(`https://api.mangadex.org/manga/${mangaDexID}/feed?order[chapter]=desc&translatedLanguage[]=en`)}
+<InputTemplate field="Manga URL" bind:submission submitText="Read" preserveCase>
+ {#if resourceIdentity}
+ {#await fetchResource(submission)}
<Message message="Loading chapters ..." />
{:then response}
{#if response.ok}
- {#await response.json() then data}
- {#if data.data}
- <Chapters {data} />
- {:else}
- <p class="opaque">(⌣_⌣”)</p>
+ {#await decodeResource(response, submission) then data}
+ {#if resourceIdentity === Resource.MangaDex}
+ <MangaDexChapters {data} />
+ {:else if resourceIdentity === Resource.Rawkuma}
+ <RawkumaChapters {data} />
{/if}
{:catch error}
<Notice>{error}</Notice>
{/await}
{:else}
- <Notice>Failed to fetch data from MangaDex</Notice>
+ <Notice>Failed to fetch data</Notice>
{/if}
- {:catch error}
- {error}
+ {:catch}
+ <Notice>An unknown error has occurred.</Notice>
{/await}
{:else}
<Notice>Invalid URL</Notice>