diff options
| author | Fuwn <[email protected]> | 2023-09-17 19:58:24 -0700 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2023-09-17 19:58:24 -0700 |
| commit | cd49dd513c27cb8d856d822dcc778a77cf7d670e (patch) | |
| tree | df75c622e91c7f3877cb740bbcabfd2aab121f1d /src/lib | |
| parent | feat(oauth): refresh token route (diff) | |
| download | due.moe-cd49dd513c27cb8d856d822dcc778a77cf7d670e.tar.xz due.moe-cd49dd513c27cb8d856d822dcc778a77cf7d670e.zip | |
feat(routes): rss feed git status
Diffstat (limited to 'src/lib')
| -rw-r--r-- | src/lib/AniList/notifications.ts | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/src/lib/AniList/notifications.ts b/src/lib/AniList/notifications.ts new file mode 100644 index 00000000..8640e105 --- /dev/null +++ b/src/lib/AniList/notifications.ts @@ -0,0 +1,62 @@ +export interface Notification { + user: { + name: string; + avatar: { + large: string; + }; + }; + context: string; + id: number; + createdAt: number; + type: + | 'FOLLOWING' + | 'ACTIVITY_MESSAGE' + | 'ACTIVITY_MENTION' + | 'ACTIVITY_REPLY' + | 'ACTIVITY_REPLY_SUBSCRIBED' + | 'ACTIVITY_LIKE' + | 'ACTIVITY_REPLY_LIKE' + | 'THREAD_COMMENT_MENTION' + | 'THREAD_COMMENT_REPLY' + | 'THREAD_SUBSCRIBED' + | 'THREAD_COMMENT_LIKE' + | 'THREAD_LIKE'; +} + +export const notifications = async (accessToken: string): Promise<Notification[]> => { + const activityNotification = (type: string) => `... on ${type} { + id user { name avatar { large } } context createdAt type + }`; + const threadNotification = (type: string) => `... on ${type} { + id user { name avatar { large } } context createdAt type thread { title } + }`; + + 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 { + ${activityNotification('FollowingNotification')} + ${activityNotification('ActivityMessageNotification')} + ${activityNotification('ActivityMentionNotification')} + ${activityNotification('ActivityReplyNotification')} + ${activityNotification('ActivityReplySubscribedNotification')} + ${activityNotification('ActivityLikeNotification')} + ${activityNotification('ActivityReplyLikeNotification')} + ${threadNotification('ThreadCommentMentionNotification')} + ${threadNotification('ThreadCommentReplyNotification')} + ${threadNotification('ThreadCommentSubscribedNotification')} + ${threadNotification('ThreadCommentLikeNotification')} + ${threadNotification('ThreadLikeNotification')} + } } }` + }) + }) + ).json() + )['data']['Page']['notifications']; +}; |