diff options
| author | Fuwn <[email protected]> | 2024-02-04 21:12:49 -0800 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2024-02-04 21:12:49 -0800 |
| commit | 6b54894503af2e1ae1a7ecdd9a6c0934586ce355 (patch) | |
| tree | 1fe2e8bacfa5c95139e95fa7932edaee8ab5841a /src/routes/api/badges | |
| parent | feat(badges): import mode (diff) | |
| download | due.moe-6b54894503af2e1ae1a7ecdd9a6c0934586ce355.tar.xz due.moe-6b54894503af2e1ae1a7ecdd9a6c0934586ce355.zip | |
fix(badges): batch import single identity
Diffstat (limited to 'src/routes/api/badges')
| -rw-r--r-- | src/routes/api/badges/+server.ts | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/src/routes/api/badges/+server.ts b/src/routes/api/badges/+server.ts index 4b52a17b..dedb84b3 100644 --- a/src/routes/api/badges/+server.ts +++ b/src/routes/api/badges/+server.ts @@ -1,5 +1,5 @@ import { userIdentity } from '$lib/AniList/identity'; -import { removeUserBadge, updateUserBadge } from '$lib/Database/badges'; +import { removeUserBadge, updateUserBadge, type Badge } from '$lib/Database/badges'; import { getUserBadges } from '$lib/Database/badges'; import { addUserBadge } from '$lib/Database/badges'; @@ -34,7 +34,7 @@ export const DELETE = async ({ url, cookies }) => { return await badges(identity.id); }; -export const PUT = async ({ cookies, url }) => { +export const PUT = async ({ cookies, url, request }) => { const userCookie = cookies.get('user'); if (!userCookie) return unauthorised; @@ -46,6 +46,15 @@ export const PUT = async ({ cookies, url }) => { accessToken: user['access_token'], refreshToken: user['refresh_token'] }); + + if (url.searchParams.get('import') || undefined) { + await Promise.all( + (await request.json()).map(async (badge: Badge) => await addUserBadge(identity.id, badge)) + ); + + return await badges(identity.id); + } + const badge = { post: url.searchParams.get('post') || undefined, image: url.searchParams.get('image') || undefined, |