aboutsummaryrefslogtreecommitdiff
path: root/src/lib/AniList
diff options
context:
space:
mode:
authorFuwn <[email protected]>2023-12-15 23:54:53 -0800
committerFuwn <[email protected]>2023-12-15 23:54:53 -0800
commitf056a1e19470967198b1dab61cf6133047f07afd (patch)
treeea3ac4647037c257d1866aff7ff23cf64d9f9f3b /src/lib/AniList
parentfeat(media): multiple dueincludes (diff)
downloaddue.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.ts33
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'];
};