aboutsummaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
authorFuwn <[email protected]>2023-10-24 19:11:21 -0700
committerFuwn <[email protected]>2023-10-24 19:11:21 -0700
commit7051fd67e98be0166d4f093f111dfa5dfa28bc0a (patch)
tree61395da21f35395a88950428990f21ca9c12d261 /src/lib
parentfeat: badge wall (diff)
parentchore(git): ignore data folder (diff)
downloaddue.moe-7051fd67e98be0166d4f093f111dfa5dfa28bc0a.tar.xz
due.moe-7051fd67e98be0166d4f093f111dfa5dfa28bc0a.zip
merge: main into badges
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/AniList/forum.ts58
-rw-r--r--src/lib/AniList/user.ts5
-rw-r--r--src/lib/List/Anime/CleanAnimeList.svelte10
-rw-r--r--src/lib/List/CleanMangaList.svelte2
-rw-r--r--src/lib/List/Template/MangaListTemplate.svelte4
-rw-r--r--src/lib/Media/manga.ts13
-rw-r--r--src/lib/Settings/SettingCheckboxToggle.svelte54
-rw-r--r--src/lib/Tools/EpisodeDiscussionCollector.svelte44
-rw-r--r--src/lib/userBadgesDatabase.ts8
9 files changed, 182 insertions, 16 deletions
diff --git a/src/lib/AniList/forum.ts b/src/lib/AniList/forum.ts
new file mode 100644
index 00000000..6b95fa07
--- /dev/null
+++ b/src/lib/AniList/forum.ts
@@ -0,0 +1,58 @@
+import { user } from './user';
+
+export interface Thread {
+ id: number;
+ title: string;
+ createdAt: number;
+}
+
+export interface ThreadPage {
+ data: {
+ Page: {
+ threads: Thread[];
+ pageInfo: {
+ hasNextPage: boolean;
+ currentPage: number;
+ };
+ };
+ };
+}
+
+const threadPage = async (page: number, userId: number): Promise<ThreadPage> =>
+ await (
+ await fetch('https://graphql.anilist.co', {
+ method: 'POST',
+ headers: {
+ 'Content-Type': 'application/json',
+ Accept: 'application/json'
+ },
+ body: JSON.stringify({
+ query: `{ Page(perPage: 50, page: ${page}) {
+ threads(userId: ${userId}) { id title createdAt }
+ pageInfo { hasNextPage }
+} }`
+ })
+ })
+ ).json();
+
+export const threads = async (username: string): Promise<Thread[]> => {
+ const allThreads = [];
+ const userId = (await user(username)).id;
+ let page = 1;
+ let currentPage = await threadPage(page, userId);
+
+ for (const thread of currentPage.data.Page.threads) {
+ allThreads.push(thread);
+ }
+
+ while (currentPage.data.Page.pageInfo.hasNextPage) {
+ page += 1;
+ currentPage = await threadPage(page, userId);
+
+ for (const thread of currentPage.data.Page.threads) {
+ allThreads.push(thread);
+ }
+ }
+
+ return allThreads;
+};
diff --git a/src/lib/AniList/user.ts b/src/lib/AniList/user.ts
index dd9995fd..fdc98a58 100644
--- a/src/lib/AniList/user.ts
+++ b/src/lib/AniList/user.ts
@@ -15,6 +15,9 @@ export interface User {
volumesRead: number;
};
};
+ avatar: {
+ large: string;
+ };
}
export const user = async (username: string): Promise<User> => {
@@ -28,7 +31,7 @@ export const user = async (username: string): Promise<User> => {
},
body: JSON.stringify({
query: `{ User(name: "${username}") {
- name id statistics {
+ name id avatar { large } statistics {
anime {
count meanScore minutesWatched episodesWatched
}
diff --git a/src/lib/List/Anime/CleanAnimeList.svelte b/src/lib/List/Anime/CleanAnimeList.svelte
index ffd34788..30443e83 100644
--- a/src/lib/List/Anime/CleanAnimeList.svelte
+++ b/src/lib/List/Anime/CleanAnimeList.svelte
@@ -37,14 +37,14 @@
{@const progress = (anime.mediaListEntry || { progress: 0 }).progress}
<li>
<a
- href={$settings.linkToAniList
- ? `https://anilist.co/anime/${anime.id}`
- : `https://www.livechart.me/search?q=${
+ href={$settings.linkToLiveChart
+ ? `https://www.livechart.me/search?q=${
anime.title.native || anime.title.english || anime.title.romaji
- }`}
+ }`
+ : `https://anilist.co/anime/${anime.id}`}
target="_blank"
>
- {#if lastUpdatedMedia === anime.id}
+ {#if lastUpdatedMedia === anime.id && anime.episodes !== progress}
<span style="color: lightcoral">
{anime.title.english || anime.title.romaji || anime.title.native}
</span>
diff --git a/src/lib/List/CleanMangaList.svelte b/src/lib/List/CleanMangaList.svelte
index a56a1c81..180c12f2 100644
--- a/src/lib/List/CleanMangaList.svelte
+++ b/src/lib/List/CleanMangaList.svelte
@@ -33,7 +33,7 @@
<li>
<a href={`https://anilist.co/manga/${manga.id}`} target="_blank">
- {#if lastUpdatedMedia === manga.id}
+ {#if lastUpdatedMedia === manga.id && manga.chapters !== progress}
<span style="color: lightcoral">
{manga.title.english || manga.title.romaji || manga.title.native}
</span>
diff --git a/src/lib/List/Template/MangaListTemplate.svelte b/src/lib/List/Template/MangaListTemplate.svelte
index 9823f97f..a0b48bdf 100644
--- a/src/lib/List/Template/MangaListTemplate.svelte
+++ b/src/lib/List/Template/MangaListTemplate.svelte
@@ -69,7 +69,9 @@
($settings.displayNotStarted === true ? 0 : 1)
);
let finalMedia = releasingMedia;
- const chapterPromises = finalMedia.map((m: Media) => chapterCount(identity, m));
+ const chapterPromises = finalMedia.map((m: Media) =>
+ chapterCount(identity, m, $settings.disableGuessing)
+ );
const chapterCounts = await Promise.all(chapterPromises);
finalMedia.forEach((m: Media, i) => {
diff --git a/src/lib/Media/manga.ts b/src/lib/Media/manga.ts
index 9d0e08a6..3c0cf837 100644
--- a/src/lib/Media/manga.ts
+++ b/src/lib/Media/manga.ts
@@ -14,7 +14,8 @@ export const pruneAllManga = async () => {
export const chapterCount = async (
identity: UserIdentity,
manga: Media,
- preferActivity = false
+ disableGuessing: boolean
+ // preferActivity = false
): Promise<number | null> => {
const chapters = await chapterDatabase.chapters.get(manga.id);
@@ -22,11 +23,15 @@ export const chapterCount = async (
return chapters.chapters === -1 ? null : chapters.chapters;
}
- if (preferActivity) {
- return await recentMediaActivities(identity, manga);
- }
+ // if (preferActivity) {
+ // return await recentMediaActivities(identity, manga);
+ // }
const tryRecentMediaActivities = async () => {
+ if (disableGuessing) {
+ return null;
+ }
+
const anilistData = await recentMediaActivities(identity, manga);
await chapterDatabase.chapters.put({
diff --git a/src/lib/Settings/SettingCheckboxToggle.svelte b/src/lib/Settings/SettingCheckboxToggle.svelte
new file mode 100644
index 00000000..ab603278
--- /dev/null
+++ b/src/lib/Settings/SettingCheckboxToggle.svelte
@@ -0,0 +1,54 @@
+<script lang="ts">
+ import settings, { type Settings } from '../../stores/settings';
+
+ type BooleanSettingsKeys<T> = {
+ [K in keyof T]: T[K] extends boolean ? K : never;
+ };
+ type SettingsBooleanKeys = BooleanSettingsKeys<Settings>;
+
+ export let sectionBreak = false;
+ export let disabled = false;
+ export let text: string;
+ export let setting: SettingsBooleanKeys[keyof SettingsBooleanKeys];
+
+ // const toggler = (key: keyof Settings) => [
+ // () =>
+ // settings.update((s) => {
+ // (s[key] as boolean) = true;
+
+ // $settings = s;
+
+ // return s;
+ // }),
+ // () =>
+ // settings.update((s) => {
+ // (s[key] as boolean) = false;
+
+ // $settings = s;
+
+ // return s;
+ // })
+ // ];
+
+ const check = (e: Event & { currentTarget: EventTarget & HTMLInputElement }): void => {
+ settings.setKey(setting, (e.target as HTMLInputElement).checked);
+ };
+</script>
+
+<input type="checkbox" on:change={check} bind:checked={$settings[setting]} />
+
+{#if disabled}
+ <strike>
+ {text}
+ </strike>
+ <slot />
+{:else}
+ {text}
+ <slot />
+{/if}
+
+<br />
+
+{#if sectionBreak}
+ <p />
+{/if}
diff --git a/src/lib/Tools/EpisodeDiscussionCollector.svelte b/src/lib/Tools/EpisodeDiscussionCollector.svelte
new file mode 100644
index 00000000..a9acd8ae
--- /dev/null
+++ b/src/lib/Tools/EpisodeDiscussionCollector.svelte
@@ -0,0 +1,44 @@
+<script lang="ts">
+ import { threads } from '$lib/AniList/forum';
+
+ let searchInput = '';
+ let searchInputFinal = '';
+</script>
+
+<p>
+ <input type="text" placeholder="Username" bind:value={searchInput} />
+ <a href={`#`} on:click={() => (searchInputFinal = searchInput)}>Search</a>
+</p>
+
+{#if searchInputFinal !== ''}
+ {#await threads(searchInputFinal)}
+ Loading ...
+ {:then threads}
+ <ul>
+ {#each threads
+ .filter((thread) => thread.title.includes('[Spoilers]') && thread.title.includes('Episode'))
+ .sort((a, b) => b.createdAt - a.createdAt) as thread}
+ <li>
+ <a href={`https://anilist.co/forum/thread/${thread.id}`} target="_blank">
+ {thread.title.replace('[Spoilers]', '')}
+ </a>
+ </li>
+ {/each}
+ </ul>
+ {:catch}
+ <p>
+ Threads could not be loaded. You might have been <a
+ href="https://en.wikipedia.org/wiki/Rate_limiting"
+ target="_blank">rate limited</a
+ >.
+ </p>
+ <p>
+ Try again in a few minutes. If the problem persists, please contact <a
+ href="https://anilist.co/user/fuwn"
+ target="_blank">@fuwn</a
+ > on AniList.
+ </p>
+ {/await}
+{:else}
+ <p>Enter a username to search for to continue.</p>
+{/if}
diff --git a/src/lib/userBadgesDatabase.ts b/src/lib/userBadgesDatabase.ts
index c129770e..78655cd3 100644
--- a/src/lib/userBadgesDatabase.ts
+++ b/src/lib/userBadgesDatabase.ts
@@ -8,16 +8,16 @@ export interface Badge {
id?: number;
}
-const database = new Database('./due_moe.sqlite3', {
+const database = new Database('./data/due_moe.sqlite3', {
verbose: dev ? console.log : undefined
});
database.exec(`create table if not exists user_badges (
id integer primary key,
user_id integer not null,
- post text not null,
- image text not null,
- description text default null,
+ post text(1000) not null,
+ image text(1000) not null,
+ description text(1000) default null,
time timestamp default current_timestamp
)`);