aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFuwn <[email protected]>2023-09-07 16:37:30 -0700
committerFuwn <[email protected]>2023-09-07 16:37:30 -0700
commit973676e1777ce9c713a5cefe5edf17008f41c17f (patch)
tree3ae96a36b71ea7279609a6f2f76cd0ac9aa8bd29
parentfix(activity): fix anilist provided date (diff)
downloaddue.moe-973676e1777ce9c713a5cefe5edf17008f41c17f.tar.xz
due.moe-973676e1777ce9c713a5cefe5edf17008f41c17f.zip
feat(routes): profile page
-rw-r--r--src/lib/AniList/activity.ts2
-rw-r--r--src/lib/AniList/user.ts46
-rw-r--r--src/routes/@[user]/+page.server.ts5
-rw-r--r--src/routes/@[user]/+page.svelte47
4 files changed, 99 insertions, 1 deletions
diff --git a/src/lib/AniList/activity.ts b/src/lib/AniList/activity.ts
index 9d30d275..0d79bf72 100644
--- a/src/lib/AniList/activity.ts
+++ b/src/lib/AniList/activity.ts
@@ -17,7 +17,7 @@ export const lastActivityDate = async (userIdentity: UserIdentity): Promise<Date
})
).json()
)['data']['User']['stats']['activityHistory'];
- let date = new Date(
+ const date = new Date(
Number(activityHistory[activityHistory.length - 1]['date']) * 1000 +
new Date().getTimezoneOffset()
);
diff --git a/src/lib/AniList/user.ts b/src/lib/AniList/user.ts
new file mode 100644
index 00000000..dd9995fd
--- /dev/null
+++ b/src/lib/AniList/user.ts
@@ -0,0 +1,46 @@
+export interface User {
+ name: string;
+ id: number;
+ statistics: {
+ anime: {
+ count: number;
+ meanScore: number;
+ minutesWatched: number;
+ episodesWatched: number;
+ };
+ manga: {
+ count: number;
+ meanScore: number;
+ chaptersRead: number;
+ volumesRead: number;
+ };
+ };
+}
+
+export const user = async (username: string): Promise<User> => {
+ const userData = (
+ await (
+ await fetch('https://graphql.anilist.co', {
+ method: 'POST',
+ headers: {
+ 'Content-Type': 'application/json',
+ Accept: 'application/json'
+ },
+ body: JSON.stringify({
+ query: `{ User(name: "${username}") {
+ name id statistics {
+ anime {
+ count meanScore minutesWatched episodesWatched
+ }
+ manga {
+ count meanScore chaptersRead volumesRead
+ }
+ }
+ } }`
+ })
+ })
+ ).json()
+ )['data']['User'];
+
+ return userData;
+};
diff --git a/src/routes/@[user]/+page.server.ts b/src/routes/@[user]/+page.server.ts
new file mode 100644
index 00000000..76d2d889
--- /dev/null
+++ b/src/routes/@[user]/+page.server.ts
@@ -0,0 +1,5 @@
+export const load = ({ params }) => {
+ return {
+ username: params.user
+ };
+};
diff --git a/src/routes/@[user]/+page.svelte b/src/routes/@[user]/+page.svelte
new file mode 100644
index 00000000..758b52e7
--- /dev/null
+++ b/src/routes/@[user]/+page.svelte
@@ -0,0 +1,47 @@
+<script lang="ts">
+ import { user } from '$lib/AniList/user';
+
+ export let data;
+
+ // 8.5827814569536423841e0
+</script>
+
+{#await user(data.username)}
+ Loading ...
+{:then profile}
+ {#if profile === null}
+ Could not load user profile for <a
+ href={`https://anilist.co/user/${data.username}`}
+ target="_blank">@{data.username}</a
+ >.
+
+ <p />
+
+ Does this user exist?
+ {:else}
+ <a href={`https://anilist.co/user/${profile.name}`} target="_blank" title={String(profile.id)}
+ >@{profile.name}</a
+ >
+
+ <p />
+
+ This user has watched {(profile.statistics.anime.minutesWatched / 60 / 24).toFixed(1)} days of anime
+ and read
+ {((profile.statistics.manga.chaptersRead * 8.58) / 60 / 24).toFixed(1)} days of manga.
+ {/if}
+{:catch}
+ Could not load user profile for <a
+ href={`https://anilist.co/user/${data.username}`}
+ target="_blank">@{data.username}</a
+ >.
+
+ <p />
+
+ Does this user exist?
+{/await}
+
+<p />
+
+<hr />
+
+This page is under construction!