From 83b427f976abff65538222089a407967e6f8aaf1 Mon Sep 17 00:00:00 2001 From: ZXY101 Date: Mon, 4 Sep 2023 09:52:22 +0200 Subject: [PATCH] Handle updating catalog --- src/lib/upload/index.ts | 16 +++++++++++++++- src/routes/upload/+page.svelte | 3 ++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/lib/upload/index.ts b/src/lib/upload/index.ts index 2c4eff4..827a5c6 100644 --- a/src/lib/upload/index.ts +++ b/src/lib/upload/index.ts @@ -114,7 +114,21 @@ export async function processFiles(fileList: FileList) { if (!valid.includes(false)) { await requestPersistentStorage(); - await db.catalog.put({ id: vols[0].mokuroData.title_uuid, manga: vols }) + + const key = vols[0].mokuroData.title_uuid; + const existingCatalog = await db.catalog.get(key); + + if (existingCatalog) { + const filtered = vols.filter((vol) => { + return !existingCatalog.manga.some(manga => { + return manga.mokuroData.volume_uuid === vol.mokuroData.volume_uuid + }) + }) + await db.catalog.update(key, { manga: [...existingCatalog.manga, ...filtered] }) + } else { + await db.catalog.put({ id: key, manga: vols }) + } + showSnackbar('Catalog updated successfully') } } diff --git a/src/routes/upload/+page.svelte b/src/routes/upload/+page.svelte index 8fd478d..0aa477e 100644 --- a/src/routes/upload/+page.svelte +++ b/src/routes/upload/+page.svelte @@ -16,5 +16,6 @@ {#await promise}

Loading...

+{:then} + {/await} -