diff options
| author | Fuwn <[email protected]> | 2023-12-15 23:54:53 -0800 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2023-12-15 23:54:53 -0800 |
| commit | f056a1e19470967198b1dab61cf6133047f07afd (patch) | |
| tree | ea3ac4647037c257d1866aff7ff23cf64d9f9f3b /src/lib/AniList | |
| parent | feat(media): multiple dueincludes (diff) | |
| download | due.moe-f056a1e19470967198b1dab61cf6133047f07afd.tar.xz due.moe-f056a1e19470967198b1dab61cf6133047f07afd.zip | |
feat(notifications): refresh token
Diffstat (limited to 'src/lib/AniList')
| -rw-r--r-- | src/lib/AniList/notifications.ts | 33 |
1 files changed, 17 insertions, 16 deletions
diff --git a/src/lib/AniList/notifications.ts b/src/lib/AniList/notifications.ts index 4fdb9cb5..bebf1b42 100644 --- a/src/lib/AniList/notifications.ts +++ b/src/lib/AniList/notifications.ts @@ -30,7 +30,7 @@ export interface Notification { | 'THREAD_LIKE'; } -export const notifications = async (accessToken: string): Promise<Notification[]> => { +export const notifications = async (accessToken: string): Promise<Notification[] | null> => { const activityNotification = (type: string, extend = '') => `... on ${type} { id user { name avatar { large } } context createdAt type ${extend} }`; @@ -45,18 +45,16 @@ export const notifications = async (accessToken: string): Promise<Notification[] )}`; const threadNotification = (type: string) => `${activityNotification(type, `thread { title id }`)}`; - - return ( - await ( - await fetch('https://graphql.anilist.co', { - method: 'POST', - headers: { - 'Content-Type': 'application/json', - Authorization: `Bearer ${accessToken}`, - Accept: 'application/json' - }, - body: JSON.stringify({ - query: `{ Page(page: 1, perPage: 50) { notifications { + const data = await ( + await fetch('https://graphql.anilist.co', { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + Authorization: `Bearer ${accessToken}`, + Accept: 'application/json' + }, + body: JSON.stringify({ + query: `{ Page(page: 1, perPage: 50) { notifications { ${activityNotification('FollowingNotification')} ${activityNotification('ActivityMessageNotification')} ${richActivityNotification('ActivityMentionNotification')} @@ -70,8 +68,11 @@ export const notifications = async (accessToken: string): Promise<Notification[] ${threadNotification('ThreadCommentLikeNotification')} ${threadNotification('ThreadLikeNotification')} } } }` - }) }) - ).json() - )['data']['Page']['notifications']; + }) + ).json(); + + if (data['errors']) return null; + + return data['data']['Page']['notifications']; }; |