diff options
| author | Fuwn <[email protected]> | 2024-02-18 05:35:27 -0800 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2024-02-18 05:35:27 -0800 |
| commit | 1eb42f9d3aa001ff41b3bbee74746efcdaff9e81 (patch) | |
| tree | 41197e053f08646b2cef6298439fce8a143fa513 /src | |
| parent | fix(badges): return empty preferences (diff) | |
| download | due.moe-1eb42f9d3aa001ff41b3bbee74746efcdaff9e81.tar.xz due.moe-1eb42f9d3aa001ff41b3bbee74746efcdaff9e81.zip | |
fix(preferences): add preferences when not set
Diffstat (limited to 'src')
| -rw-r--r-- | src/lib/Database/userPreferences.ts | 6 | ||||
| -rw-r--r-- | src/routes/api/preferences/badges/+server.ts | 31 |
2 files changed, 2 insertions, 35 deletions
diff --git a/src/lib/Database/userPreferences.ts b/src/lib/Database/userPreferences.ts index 988ca0c0..d788ba52 100644 --- a/src/lib/Database/userPreferences.ts +++ b/src/lib/Database/userPreferences.ts @@ -65,11 +65,9 @@ export const toggleHololiveStreamPinning = async (userId: number, streamId: stri export const toggleHideMissingBadges = async (userId: number) => { const userPreferences = await getUserPreferences(userId); - if (!userPreferences) return null; - return await setUserPreferences(userId, { updated_at: new Date().toISOString(), - pinned_hololive_streams: userPreferences.pinned_hololive_streams, - hide_missing_badges: !userPreferences.hide_missing_badges + pinned_hololive_streams: userPreferences ? userPreferences.pinned_hololive_streams : [], + hide_missing_badges: userPreferences ? !userPreferences.hide_missing_badges : false }); }; diff --git a/src/routes/api/preferences/badges/+server.ts b/src/routes/api/preferences/badges/+server.ts deleted file mode 100644 index 24d4924b..00000000 --- a/src/routes/api/preferences/badges/+server.ts +++ /dev/null @@ -1,31 +0,0 @@ -import { userIdentity } from '$lib/Data/AniList/identity'; -import { toggleHideMissingBadges } from '$lib/Database/userPreferences'; - -const unauthorised = new Response('Unauthorised', { status: 401 }); - -export const PUT = async ({ cookies }) => { - const userCookie = cookies.get('user'); - - if (!userCookie) return unauthorised; - - const user = JSON.parse(userCookie); - - return Response.json( - await toggleHideMissingBadges( - ( - await userIdentity({ - tokenType: user['token_type'], - expiresIn: user['expires_in'], - accessToken: user['access_token'], - refreshToken: user['refresh_token'] - }) - ).id - ), - { - headers: { - method: 'PUT', - 'Access-Control-Allow-Origin': 'https://due.moe' - } - } - ); -}; |