From fcbc26f544a5ad7ec841561dec695aaceb63d709 Mon Sep 17 00:00:00 2001
From: Fuwn <contact@fuwn.me>
Date: Tue, 10 Sep 2024 00:06:05 -0700
Subject: feat(reader): add rawkuma chapter support

---
 src/routes/reader/+page.svelte | 28 +++++++++++++++-------------
 1 file changed, 15 insertions(+), 13 deletions(-)

(limited to 'src/routes/reader/+page.svelte')

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>
-- 
cgit v1.2.3

