diff options
| author | Fuwn <[email protected]> | 2024-01-04 00:51:36 -0800 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2024-01-04 00:51:36 -0800 |
| commit | 4a1c72dfdc48fa55e65e3e91426448abfeaff478 (patch) | |
| tree | cd54b5cda2bb2267dfbe0be7f0d451540d96aa2e /src | |
| parent | refactor(manga): use built-in increment (diff) | |
| download | due.moe-4a1c72dfdc48fa55e65e3e91426448abfeaff478.tar.xz due.moe-4a1c72dfdc48fa55e65e3e91426448abfeaff478.zip | |
refactor(media): client-side increment
Diffstat (limited to 'src')
| -rw-r--r-- | src/lib/List/Anime/CleanAnimeList.svelte | 2 | ||||
| -rw-r--r-- | src/lib/List/Manga/MangaListTemplate.svelte | 2 | ||||
| -rw-r--r-- | src/lib/Media/Anime/cache.ts | 15 | ||||
| -rw-r--r-- | src/routes/api/anilist/increment/+server.ts | 27 |
4 files changed, 16 insertions, 30 deletions
diff --git a/src/lib/List/Anime/CleanAnimeList.svelte b/src/lib/List/Anime/CleanAnimeList.svelte index caae9b2f..7e97ba59 100644 --- a/src/lib/List/Anime/CleanAnimeList.svelte +++ b/src/lib/List/Anime/CleanAnimeList.svelte @@ -114,7 +114,7 @@ lastUpdatedMedia = anime.id; pendingUpdate = anime.id; - incrementMediaProgress(anime.id, anime.mediaListEntry?.progress, () => { + incrementMediaProgress(anime.id, anime.mediaListEntry?.progress, user, () => { const mediaListEntry = media.find((m) => m.id === anime.id)?.mediaListEntry; if (mediaListEntry) mediaListEntry.progress = progress + 1; diff --git a/src/lib/List/Manga/MangaListTemplate.svelte b/src/lib/List/Manga/MangaListTemplate.svelte index 85118811..2b12a14d 100644 --- a/src/lib/List/Manga/MangaListTemplate.svelte +++ b/src/lib/List/Manga/MangaListTemplate.svelte @@ -142,7 +142,7 @@ await database.chapters.delete(id); - incrementMediaProgress(id, progress, () => { + incrementMediaProgress(id, progress, user, () => { previousMangaList = media; const foundEntry = media.find((m) => m.id === id); diff --git a/src/lib/Media/Anime/cache.ts b/src/lib/Media/Anime/cache.ts index e7e7aceb..f5dff12a 100644 --- a/src/lib/Media/Anime/cache.ts +++ b/src/lib/Media/Anime/cache.ts @@ -12,7 +12,20 @@ export const cleanCache = (user: AniListAuthorisation, identity: UserIdentity) = export const incrementMediaProgress = ( id: number, progress: number | undefined, + user: AniListAuthorisation, callback: () => void ) => { - fetch(`/api/anilist/increment?id=${id}&progress=${(progress || 0) + 1}`).then(callback); + fetch('https://graphql.anilist.co', { + method: 'POST', + headers: { + Authorization: `${user.tokenType} ${user.accessToken}`, + 'Content-Type': 'application/json', + Accept: 'application/json' + }, + body: JSON.stringify({ + query: `mutation { SaveMediaListEntry(mediaId: ${id}, progress: ${ + (progress || 0) + 1 + }) { id } }` + }) + }).then(callback); }; diff --git a/src/routes/api/anilist/increment/+server.ts b/src/routes/api/anilist/increment/+server.ts deleted file mode 100644 index 4680236b..00000000 --- a/src/routes/api/anilist/increment/+server.ts +++ /dev/null @@ -1,27 +0,0 @@ -export const GET = async ({ url, cookies }) => { - const userCookie = cookies.get('user'); - - if (!userCookie) { - return new Response('Unauthenticated', { status: 401 }); - } - - const user = JSON.parse(userCookie); - - return Response.json( - await ( - await fetch('https://graphql.anilist.co', { - method: 'POST', - headers: { - Authorization: `${user['token_type']} ${user['access_token']}`, - 'Content-Type': 'application/json', - Accept: 'application/json' - }, - body: JSON.stringify({ - query: `mutation { SaveMediaListEntry(mediaId: ${ - url.searchParams.get('id') || 'null' - }, progress: ${url.searchParams.get('progress') || 'null'}) { id } }` - }) - }) - ).json() - ); -}; |