diff options
Diffstat (limited to 'src/lib')
| -rw-r--r-- | src/lib/AniList/wrapped.ts | 44 |
1 files changed, 30 insertions, 14 deletions
diff --git a/src/lib/AniList/wrapped.ts b/src/lib/AniList/wrapped.ts index 3f3e0bf8..abcbe5c7 100644 --- a/src/lib/AniList/wrapped.ts +++ b/src/lib/AniList/wrapped.ts @@ -115,18 +115,26 @@ const profileActivities = async ( }; export const wrapped = async ( - anilistAuthorisation: AniListAuthorisation, + anilistAuthorisation: AniListAuthorisation | undefined, identity: UserIdentity, - year = new Date().getFullYear() + year = new Date().getFullYear(), + skipActivities = false ): Promise<Wrapped> => { + const headers: { [key: string]: string } = { + 'Content-Type': 'application/json', + Accept: 'application/json' + }; + + if (anilistAuthorisation) { + headers[ + 'Authorization' + ] = `${anilistAuthorisation.tokenType} ${anilistAuthorisation.accessToken}`; + } + const wrappedResponse = await ( await fetch('https://graphql.anilist.co', { method: 'POST', - headers: { - Authorization: `${anilistAuthorisation.tokenType} ${anilistAuthorisation.accessToken}`, - 'Content-Type': 'application/json', - Accept: 'application/json' - }, + headers, body: JSON.stringify({ query: `{ User(name: "${identity.name}") { @@ -148,17 +156,25 @@ export const wrapped = async ( }) }) ).json(); - const { statusCount, messageCount } = await profileActivities( - anilistAuthorisation, - identity, - new Date(year, 11, 31).getTime() - ); + let statusCountActivities = 0; + let messageCountActivities = 0; + + if (!skipActivities && anilistAuthorisation) { + const { statusCount, messageCount } = await profileActivities( + anilistAuthorisation, + identity, + new Date(year, 11, 31).getTime() + ); + + statusCountActivities = statusCount; + messageCountActivities = messageCount; + } return { statistics: wrappedResponse['data']['User']['statistics'], activities: { - statusCount, - messageCount + statusCount: statusCountActivities, + messageCount: messageCountActivities }, avatar: wrappedResponse['data']['User']['avatar'] }; |