aboutsummaryrefslogtreecommitdiff
path: root/src/routes/api
diff options
context:
space:
mode:
authorFuwn <[email protected]>2023-10-26 15:41:57 -0700
committerFuwn <[email protected]>2023-10-26 15:41:57 -0700
commit9bac3b6b6a9103841a3456436c65af66549a83da (patch)
tree4273c0ebe5567109daf8b7a4d2c92d51694677cf /src/routes/api
parentfix(feeds): html encode title (diff)
parentfeat: move back to bun (diff)
downloaddue.moe-9bac3b6b6a9103841a3456436c65af66549a83da.tar.xz
due.moe-9bac3b6b6a9103841a3456436c65af66549a83da.zip
merge: branch 'badges'
Diffstat (limited to 'src/routes/api')
-rw-r--r--src/routes/api/badges/add/+server.ts26
-rw-r--r--src/routes/api/badges/remove/+server.ts22
2 files changed, 48 insertions, 0 deletions
diff --git a/src/routes/api/badges/add/+server.ts b/src/routes/api/badges/add/+server.ts
new file mode 100644
index 00000000..627176a7
--- /dev/null
+++ b/src/routes/api/badges/add/+server.ts
@@ -0,0 +1,26 @@
+import { userIdentity } from '$lib/AniList/identity.js';
+import { addUserBadge } from '$lib/userBadgesDatabase.js';
+
+export const POST = async ({ cookies, url }) => {
+ const userCookie = cookies.get('user');
+
+ if (!userCookie) {
+ return new Response('Unauthenticated', { status: 401 });
+ }
+
+ const user = JSON.parse(userCookie);
+ const identity = await userIdentity({
+ tokenType: user['token_type'],
+ expiresIn: user['expires_in'],
+ accessToken: user['access_token'],
+ refreshToken: user['refresh_token']
+ });
+
+ addUserBadge(identity.id, {
+ post: url.searchParams.get('post') || undefined,
+ image: url.searchParams.get('image') || undefined,
+ description: url.searchParams.get('description') || undefined
+ });
+
+ return Response.json({});
+};
diff --git a/src/routes/api/badges/remove/+server.ts b/src/routes/api/badges/remove/+server.ts
new file mode 100644
index 00000000..8b05369a
--- /dev/null
+++ b/src/routes/api/badges/remove/+server.ts
@@ -0,0 +1,22 @@
+import { userIdentity } from '$lib/AniList/identity.js';
+import { removeUserBadge } from '$lib/userBadgesDatabase.js';
+
+export const POST = async ({ url, cookies }) => {
+ const userCookie = cookies.get('user');
+
+ if (!userCookie) {
+ return new Response('Unauthenticated', { status: 401 });
+ }
+
+ const user = JSON.parse(userCookie);
+ const identity = await userIdentity({
+ tokenType: user['token_type'],
+ expiresIn: user['expires_in'],
+ accessToken: user['access_token'],
+ refreshToken: user['refresh_token']
+ });
+
+ removeUserBadge(identity.id, Number(url.searchParams.get('id')));
+
+ return Response.json({});
+};