diff options
| author | Fuwn <[email protected]> | 2023-12-22 20:39:45 -0800 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2023-12-22 20:39:45 -0800 |
| commit | 13cf33feb685378cdebe97522f0b78e1cfe882a3 (patch) | |
| tree | 0b3fdf8452f376f3ff449b10fb8c5780779ade6b /src/lib | |
| parent | fix(wrapped): category for grid (diff) | |
| download | due.moe-13cf33feb685378cdebe97522f0b78e1cfe882a3.tar.xz due.moe-13cf33feb685378cdebe97522f0b78e1cfe882a3.zip | |
feat(manga): naive auto-authorisation
Diffstat (limited to 'src/lib')
| -rw-r--r-- | src/lib/List/Manga/CleanMangaList.svelte | 13 | ||||
| -rw-r--r-- | src/lib/List/Manga/MangaListTemplate.svelte | 127 | ||||
| -rw-r--r-- | src/lib/authorised.json | 1 |
3 files changed, 84 insertions, 57 deletions
diff --git a/src/lib/List/Manga/CleanMangaList.svelte b/src/lib/List/Manga/CleanMangaList.svelte index a41c8998..5254ad71 100644 --- a/src/lib/List/Manga/CleanMangaList.svelte +++ b/src/lib/List/Manga/CleanMangaList.svelte @@ -4,12 +4,12 @@ import { volumeCount } from '$lib/Media/Manga/volumes'; import { outboundLink } from '$lib/Media/links'; import settings from '../../../stores/settings'; - // import ListTitle from '../ListTitle.svelte'; + import ListTitle from '../ListTitle.svelte'; import MediaTitle from '../MediaTitleDisplay.svelte'; export let media: Media[]; export let cleanCache: () => void; - // export let endTime: number; + export let endTime: number; export let lastUpdatedMedia: number; export let updateMedia: ( id: number, @@ -19,11 +19,14 @@ export let pendingUpdate: number | null; export let due: boolean; export let rateLimited: boolean; + export let authorised: boolean; </script> -<!-- <ListTitle count={media.length} time={endTime / 1000}> - <a href={'#'} title="Force a full refresh" on:click={cleanCache}>Refresh</a> -</ListTitle> --> +{#if authorised} + <ListTitle count={media.length} time={endTime / 1000}> + <a href={'#'} title="Force a full refresh" on:click={cleanCache}>Refresh</a> + </ListTitle> +{/if} {#if rateLimited} <Error /> diff --git a/src/lib/List/Manga/MangaListTemplate.svelte b/src/lib/List/Manga/MangaListTemplate.svelte index 2cdeb094..5409a3d9 100644 --- a/src/lib/List/Manga/MangaListTemplate.svelte +++ b/src/lib/List/Manga/MangaListTemplate.svelte @@ -11,12 +11,14 @@ import ListTitle from '../ListTitle.svelte'; import Error from '$lib/Error.svelte'; import CleanMangaList from './CleanMangaList.svelte'; + import authorisedJson from '$lib/authorised.json'; export let user: AniListAuthorisation; export let identity: UserIdentity; export let displayUnresolved: boolean; export let due: boolean; + const authorised = authorisedJson.includes(identity.id); let mangaLists: Promise<Media[]>; let startTime: number; let endTime: number; @@ -45,22 +47,25 @@ if (manga === undefined) return []; - if ((await database.chapters.toArray()).length <= 0 && !force) return []; - - // if ($lastPruneTimes.chapters === 1) lastPruneTimes.setKey('chapters', new Date().getTime()); - // else { - // const currentDate = new Date(); - - // if ( - // (currentDate.getTime() - $lastPruneTimes.chapters) / 1000 / 60 > - // Math.max($settings.cacheMangaMinutes, 5) - // ) { - // lastPruneTimes.setKey('chapters', currentDate.getTime()); - // (async () => { - // await database.chapters.bulkDelete((await database.chapters.toArray()).map((m) => m.id)); - // })(); - // } - // } + if (!authorised && (await database.chapters.toArray()).length <= 0 && !force) return []; + + if (authorised) { + if ($lastPruneTimes.chapters === 1) lastPruneTimes.setKey('chapters', new Date().getTime()); + else { + const currentDate = new Date(); + if ( + (currentDate.getTime() - $lastPruneTimes.chapters) / 1000 / 60 > + Math.max($settings.cacheMangaMinutes, 5) + ) { + lastPruneTimes.setKey('chapters', currentDate.getTime()); + (async () => { + await database.chapters.bulkDelete( + (await database.chapters.toArray()).map((m) => m.id) + ); + })(); + } + } + } const releasingMedia = manga.filter( (media: Media) => @@ -173,17 +178,19 @@ </script> {#await mangaLists} - <ListTitle count={0} time={endTime / 1000}> - <a - href={'#'} - title="Force a full refresh" - on:click={() => { - cleanCache(); - - forceFlag = true; - }}>Refresh</a - > - </ListTitle> + {#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 @@ -191,28 +198,34 @@ {cleanCache} {lastUpdatedMedia} {updateMedia} + {endTime} {pendingUpdate} {due} {rateLimited} + {authorised} /> {:else} - <!-- <ListTitle /> --> + {#if authorised} + <ListTitle /> + {/if} <ul><li>Loading {progress.toFixed(0)}% ...</li></ul> {/if} {:then media} {#await cleanMedia(media, displayUnresolved, forceFlag)} - <ListTitle count={0} time={endTime / 1000}> - <a - href={'#'} - title="Force a full refresh" - on:click={() => { - cleanCache(); - - forceFlag = true; - }}>Refresh</a - > - </ListTitle> + {#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 @@ -220,39 +233,49 @@ {cleanCache} {lastUpdatedMedia} {updateMedia} + {endTime} {pendingUpdate} {due} {rateLimited} + {authorised} /> {:else} - <!-- <ListTitle /> --> + {#if authorised} + <ListTitle /> + {/if} <ul><li>Loading {progress.toFixed(0)}% ...</li></ul> {/if} {:then cleanedMedia} - <ListTitle count={cleanedMedia.length} time={endTime / 1000}> - <a - href={'#'} - title="Force a full refresh" - on:click={() => { - cleanCache(); - - forceFlag = true; - }}>Refresh</a - > - </ListTitle> + {#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} <CleanMangaList media={cleanedMedia} {cleanCache} {lastUpdatedMedia} {updateMedia} + {endTime} {pendingUpdate} {due} {rateLimited} + {authorised} /> {:catch} - <!-- <ListTitle count={-1337} time={0} /> --> + {#if authorised} + <ListTitle count={-1337} time={0} /> + {/if} <Error /> {/await} diff --git a/src/lib/authorised.json b/src/lib/authorised.json new file mode 100644 index 00000000..94f6762b --- /dev/null +++ b/src/lib/authorised.json @@ -0,0 +1 @@ +[5678223] |