diff options
| author | Fuwn <[email protected]> | 2024-11-18 19:34:30 -0800 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2024-11-18 19:34:36 -0800 |
| commit | 43ecb0640c085971a77f243d72b9d62d961feecd (patch) | |
| tree | 1907adb4220b1a4df1b958b848317b5dcc1cacb3 | |
| parent | fix(CleanAnimeList): completed total chapter count calculation (diff) | |
| download | due.moe-43ecb0640c085971a77f243d72b9d62d961feecd.tar.xz due.moe-43ecb0640c085971a77f243d72b9d62d961feecd.zip | |
refactor(authorised): move authorised user functionality to module
| -rw-r--r-- | src/graphql/user/resolvers.ts | 8 | ||||
| -rw-r--r-- | src/lib/List/Manga/MangaListTemplate.svelte | 4 | ||||
| -rw-r--r-- | src/lib/Utility/privilegedUser.ts | 5 | ||||
| -rw-r--r-- | src/routes/api/badges/+server.ts | 10 |
4 files changed, 16 insertions, 11 deletions
diff --git a/src/graphql/user/resolvers.ts b/src/graphql/user/resolvers.ts index 731b5f94..30f48cd1 100644 --- a/src/graphql/user/resolvers.ts +++ b/src/graphql/user/resolvers.ts @@ -10,7 +10,6 @@ import { } from '$lib/Database/SB/User/badges'; import type { WithIndex } from '../$types'; import type { Resolvers, Badge } from './$types'; -import authorisedJson from '$lib/Data/Static/authorised.json'; import type { RequestEvent } from '@sveltejs/kit'; import { getUserPreferences, @@ -23,6 +22,7 @@ import { togglePinnedBadgeWallCategory, type UserPreferences } from '$lib/Database/SB/User/preferences'; +import privilegedUser from '$lib/Utility/privilegedUser'; type Context = RequestEvent<Partial<Record<string, string>>, string | null>; @@ -49,7 +49,7 @@ const authenticatedBadgesOperation = async ( if (identity instanceof Error) return []; - const authorised = authorisedJson.includes(identity.id); + const authorised = privilegedUser(identity.id) await operation(identity, authorised); @@ -71,7 +71,7 @@ const authenticatedPreferencesOperation = async ( if (identity instanceof Error) return []; - const authorised = authorisedJson.includes(identity.id); + const authorised = privilegedUser(identity.id) return { id: identity.id, @@ -129,7 +129,7 @@ export const resolvers: WithIndex<Resolvers> = { allBadges .filter((badge) => badge.category === category) .filter((badge) => badge.hidden).length > - allBadges.filter((badge) => badge.category === category).length / 2 + allBadges.filter((badge) => badge.category === category).length / 2 ? false : true }); diff --git a/src/lib/List/Manga/MangaListTemplate.svelte b/src/lib/List/Manga/MangaListTemplate.svelte index 1303419f..d1a6a944 100644 --- a/src/lib/List/Manga/MangaListTemplate.svelte +++ b/src/lib/List/Manga/MangaListTemplate.svelte @@ -12,7 +12,6 @@ import ListTitle from '../ListTitle.svelte'; import Error from '$lib/Error/RateLimited.svelte'; import CleanMangaList from './CleanMangaList.svelte'; - import authorisedJson from '$lib/Data/Static/authorised.json'; import { incrementMediaProgress } from '$lib/Media/Anime/cache'; import { getNotificationsContext } from 'svelte-notifications'; import { options } from '$lib/Notification/options'; @@ -20,6 +19,7 @@ import locale from '$stores/locale'; import { browser } from '$app/environment'; import identity from '$stores/identity'; + import privilegedUser from '$lib/Utility/privilegedUser'; export let user: AniListAuthorisation = { accessToken: '', @@ -32,7 +32,7 @@ export let dummy = $settings.debugDummyLists || false; const { addNotification } = getNotificationsContext(); - const authorised = authorisedJson.includes($identity.id); + const authorised = privilegedUser($identity.id); let mangaLists: Promise<Media[]>; let startTime: number; let endTime: number; diff --git a/src/lib/Utility/privilegedUser.ts b/src/lib/Utility/privilegedUser.ts new file mode 100644 index 00000000..769032b9 --- /dev/null +++ b/src/lib/Utility/privilegedUser.ts @@ -0,0 +1,5 @@ +import authorisedJson from '$lib/Data/Static/authorised.json'; + +const privilegedUser = (id: number) => authorisedJson.includes(id); + +export default privilegedUser; diff --git a/src/routes/api/badges/+server.ts b/src/routes/api/badges/+server.ts index 7c62285d..9d5cb9a0 100644 --- a/src/routes/api/badges/+server.ts +++ b/src/routes/api/badges/+server.ts @@ -11,7 +11,7 @@ import { setShadowHiddenBadge, incrementClickCount } from '$lib/Database/SB/User/badges'; -import authorisedJson from '$lib/Data/Static/authorised.json'; +import privilegedUser from '$lib/Utility/privilegedUser'; const unauthorised = new Response('Unauthorised', { status: 401 }); @@ -66,7 +66,7 @@ export const PUT = async ({ cookies, url, request }) => { accessToken: user['access_token'], refreshToken: user['refresh_token'] }); - const authorised = authorisedJson.includes(identity.id); + const authorised = privilegedUser(identity.id); if (url.searchParams.get('shadowHide')) setShadowHidden(Number(url.searchParams.get('shadowHide')), authorised); @@ -100,9 +100,9 @@ export const PUT = async ({ cookies, url, request }) => { allBadges .filter((badge) => badge.category === (url.searchParams.get('category') || '')) .filter((badge) => badge.hidden).length > - allBadges.filter( - (badge) => badge.category === (url.searchParams.get('category') || '') - ).length / + allBadges.filter( + (badge) => badge.category === (url.searchParams.get('category') || '') + ).length / 2 ? false : true |