aboutsummaryrefslogtreecommitdiff
path: root/src/routes/api
diff options
context:
space:
mode:
Diffstat (limited to 'src/routes/api')
-rw-r--r--src/routes/api/animeschedule/oauth/callback/+server.ts30
-rw-r--r--src/routes/api/authentication/log-out/+server.ts22
-rw-r--r--src/routes/api/badges/+server.ts281
-rw-r--r--src/routes/api/birthdays/primary/+server.ts74
-rw-r--r--src/routes/api/birthdays/secondary/+server.ts51
-rw-r--r--src/routes/api/configuration/+server.ts111
-rw-r--r--src/routes/api/events/+server.ts12
-rw-r--r--src/routes/api/events/group/+server.ts4
-rw-r--r--src/routes/api/events/groups/+server.ts2
-rw-r--r--src/routes/api/health/+server.ts2
-rw-r--r--src/routes/api/myanimelist/oauth/callback/+server.ts32
-rw-r--r--src/routes/api/notifications/subscribe/+server.ts36
-rw-r--r--src/routes/api/notifications/unsubscribe/+server.ts36
-rw-r--r--src/routes/api/oauth/callback/+server.ts28
-rw-r--r--src/routes/api/oauth/refresh/+server.ts46
-rw-r--r--src/routes/api/preferences/+server.ts156
-rw-r--r--src/routes/api/preferences/pin/+server.ts50
-rw-r--r--src/routes/api/subsplease/+server.ts30
-rw-r--r--src/routes/api/updates/all-novels/+server.ts34
-rw-r--r--src/routes/api/updates/manga/+server.ts28
-rw-r--r--src/routes/api/updates/novels/+server.ts28
21 files changed, 563 insertions, 530 deletions
diff --git a/src/routes/api/animeschedule/oauth/callback/+server.ts b/src/routes/api/animeschedule/oauth/callback/+server.ts
index 2b96ab81..294abc05 100644
--- a/src/routes/api/animeschedule/oauth/callback/+server.ts
+++ b/src/routes/api/animeschedule/oauth/callback/+server.ts
@@ -1,17 +1,17 @@
-import { callback } from '$lib/Utility/oauth.js';
-import { env } from '$env/dynamic/private';
-import { env as env2 } from '$env/dynamic/public';
+import { callback } from "$lib/Utility/oauth.js";
+import { env } from "$env/dynamic/private";
+import { env as env2 } from "$env/dynamic/public";
export const GET = async ({ url, cookies }) =>
- callback({
- url,
- cookies,
- cookie: 'animeschedule',
- authorise: 'https://animeschedule.net/api/v3/oauth2/token',
- redirect: '/settings',
- client: {
- id: env2.PUBLIC_ANIMESCHEDULE_CLIENT_ID,
- secret: env.ANIMESCHEDULE_CLIENT_SECRET,
- redirectURI: env2.PUBLIC_ANIMESCHEDULE_REDIRECT_URI
- }
- });
+ callback({
+ url,
+ cookies,
+ cookie: "animeschedule",
+ authorise: "https://animeschedule.net/api/v3/oauth2/token",
+ redirect: "/settings",
+ client: {
+ id: env2.PUBLIC_ANIMESCHEDULE_CLIENT_ID,
+ secret: env.ANIMESCHEDULE_CLIENT_SECRET,
+ redirectURI: env2.PUBLIC_ANIMESCHEDULE_REDIRECT_URI,
+ },
+ });
diff --git a/src/routes/api/authentication/log-out/+server.ts b/src/routes/api/authentication/log-out/+server.ts
index 26b5dd2c..c04fa5c5 100644
--- a/src/routes/api/authentication/log-out/+server.ts
+++ b/src/routes/api/authentication/log-out/+server.ts
@@ -1,15 +1,15 @@
-import root from '$lib/Utility/root.js';
-import { redirect } from '@sveltejs/kit';
+import root from "$lib/Utility/root.js";
+import { redirect } from "@sveltejs/kit";
export const GET = ({ cookies }) => {
- cookies.delete('user', { path: '/' });
- cookies.set('logout', '1', {
- path: '/',
- maxAge: 60 * 60 * 24 * 7,
- httpOnly: false,
- sameSite: 'lax',
- secure: false
- });
+ cookies.delete("user", { path: "/" });
+ cookies.set("logout", "1", {
+ path: "/",
+ maxAge: 60 * 60 * 24 * 7,
+ httpOnly: false,
+ sameSite: "lax",
+ secure: false,
+ });
- redirect(303, root('/'));
+ redirect(303, root("/"));
};
diff --git a/src/routes/api/badges/+server.ts b/src/routes/api/badges/+server.ts
index e1916517..3c389cf6 100644
--- a/src/routes/api/badges/+server.ts
+++ b/src/routes/api/badges/+server.ts
@@ -1,149 +1,164 @@
-import { userIdentity } from '$lib/Data/AniList/identity';
+import { userIdentity } from "$lib/Data/AniList/identity";
import {
- removeAllUserBadges,
- removeUserBadge,
- updateUserBadge,
- getUserBadges,
- addUserBadge,
- type Badge,
- migrateCategory,
- setShadowHidden,
- setShadowHiddenBadge,
- incrementClickCount
-} from '$lib/Database/SB/User/badges';
-import privilegedUser from '$lib/Utility/privilegedUser';
-
-const unauthorised = new Response('Unauthorised', { status: 401 });
+ removeAllUserBadges,
+ removeUserBadge,
+ updateUserBadge,
+ getUserBadges,
+ addUserBadge,
+ type Badge,
+ migrateCategory,
+ setShadowHidden,
+ setShadowHiddenBadge,
+ incrementClickCount,
+} from "$lib/Database/SB/User/badges";
+import privilegedUser from "$lib/Utility/privilegedUser";
+
+const unauthorised = new Response("Unauthorised", { status: 401 });
const badges = async (id: number) =>
- Response.json(await getUserBadges(id), {
- headers: {
- 'Access-Control-Allow-Origin': 'https://due.moe'
- }
- });
+ Response.json(await getUserBadges(id), {
+ headers: {
+ "Access-Control-Allow-Origin": "https://due.moe",
+ },
+ });
export const GET = async ({ url }) => {
- return await badges(Number(url.searchParams.get('id') || 0));
+ return await badges(Number(url.searchParams.get("id") || 0));
};
export const DELETE = async ({ url, cookies }) => {
- const userCookie = cookies.get('user');
+ const userCookie = cookies.get("user");
- if (!userCookie) return unauthorised;
+ if (!userCookie) return unauthorised;
- 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']
- });
+ 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"],
+ });
- if ((url.searchParams.get('prune') || 0) === 'true') {
- await removeAllUserBadges(identity.id);
- } else {
- await removeUserBadge(identity.id, Number(url.searchParams.get('id')));
- }
+ if ((url.searchParams.get("prune") || 0) === "true") {
+ await removeAllUserBadges(identity.id);
+ } else {
+ await removeUserBadge(identity.id, Number(url.searchParams.get("id")));
+ }
- return await badges(identity.id);
+ return await badges(identity.id);
};
export const PUT = async ({ cookies, url, request }) => {
- if (url.searchParams.get('incrementClickCount') || undefined) {
- await incrementClickCount(Number(url.searchParams.get('incrementClickCount')));
-
- return new Response('Incremented', { status: 200 });
- }
-
- const userCookie = cookies.get('user');
-
- if (!userCookie) return unauthorised;
-
- 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']
- });
- const authorised = privilegedUser(identity.id);
-
- if (url.searchParams.get('shadowHide'))
- setShadowHidden(Number(url.searchParams.get('shadowHide')), authorised);
-
- if (url.searchParams.get('import') || undefined) {
- await Promise.all(
- (await request.json()).map(async (badge: Badge) => await addUserBadge(identity.id, badge))
- );
-
- return await badges(identity.id);
- } else if (url.searchParams.get('migrate') || undefined) {
- await migrateCategory(
- identity.id,
- url.searchParams.get('original') || '',
- url.searchParams.get('new') || ''
- );
-
- return await badges(identity.id);
- }
-
- if (url.searchParams.get('hide') || undefined) {
- const allBadges = await getUserBadges(identity.id);
-
- await Promise.all(
- allBadges
- .filter((badge) => badge.category === (url.searchParams.get('category') || ''))
- .map(async (badge) => {
- await updateUserBadge(identity.id, badge.id as number, {
- ...badge,
- hidden:
- allBadges
- .filter((badge) => badge.category === (url.searchParams.get('category') || ''))
- .filter((badge) => badge.hidden).length >
- allBadges.filter(
- (badge) => badge.category === (url.searchParams.get('category') || '')
- ).length /
- 2
- ? false
- : true
- });
- })
- );
-
- return await badges(identity.id);
- }
-
- if (url.searchParams.get('shadowHideBadge') || undefined) {
- if (!authorised) return unauthorised;
-
- await setShadowHiddenBadge(
- Number(url.searchParams.get('shadowHideBadge')),
- url.searchParams.get('status') === 'true' ? false : true
- );
-
- return await badges(Number(url.searchParams.get('id')));
- }
-
- const badge = {
- post: url.searchParams.get('post') || undefined,
- image: url.searchParams.get('image') || undefined,
- description: url.searchParams.get('description') || null,
- time: url.searchParams.get('time') || undefined,
- category: url.searchParams.get('category') || null,
- hidden: url.searchParams.get('hidden') || false,
- source: url.searchParams.get('source') || null,
- designer: url.searchParams.get('designer') || null
- };
-
- if (
- (await getUserBadges(identity.id)).find(
- (badge) => Number(badge.id) === Number(url.searchParams.get('update'))
- )
- ) {
- await updateUserBadge(identity.id, Number(url.searchParams.get('update')), badge as Badge);
- } else {
- await addUserBadge(identity.id, badge as Badge);
- }
-
- return await badges(identity.id);
+ if (url.searchParams.get("incrementClickCount") || undefined) {
+ await incrementClickCount(
+ Number(url.searchParams.get("incrementClickCount")),
+ );
+
+ return new Response("Incremented", { status: 200 });
+ }
+
+ const userCookie = cookies.get("user");
+
+ if (!userCookie) return unauthorised;
+
+ 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"],
+ });
+ const authorised = privilegedUser(identity.id);
+
+ if (url.searchParams.get("shadowHide"))
+ setShadowHidden(Number(url.searchParams.get("shadowHide")), authorised);
+
+ if (url.searchParams.get("import") || undefined) {
+ await Promise.all(
+ (await request.json()).map(
+ async (badge: Badge) => await addUserBadge(identity.id, badge),
+ ),
+ );
+
+ return await badges(identity.id);
+ } else if (url.searchParams.get("migrate") || undefined) {
+ await migrateCategory(
+ identity.id,
+ url.searchParams.get("original") || "",
+ url.searchParams.get("new") || "",
+ );
+
+ return await badges(identity.id);
+ }
+
+ if (url.searchParams.get("hide") || undefined) {
+ const allBadges = await getUserBadges(identity.id);
+
+ await Promise.all(
+ allBadges
+ .filter(
+ (badge) =>
+ badge.category === (url.searchParams.get("category") || ""),
+ )
+ .map(async (badge) => {
+ await updateUserBadge(identity.id, badge.id as number, {
+ ...badge,
+ hidden:
+ allBadges
+ .filter(
+ (badge) =>
+ badge.category === (url.searchParams.get("category") || ""),
+ )
+ .filter((badge) => badge.hidden).length >
+ allBadges.filter(
+ (badge) =>
+ badge.category === (url.searchParams.get("category") || ""),
+ ).length /
+ 2
+ ? false
+ : true,
+ });
+ }),
+ );
+
+ return await badges(identity.id);
+ }
+
+ if (url.searchParams.get("shadowHideBadge") || undefined) {
+ if (!authorised) return unauthorised;
+
+ await setShadowHiddenBadge(
+ Number(url.searchParams.get("shadowHideBadge")),
+ url.searchParams.get("status") === "true" ? false : true,
+ );
+
+ return await badges(Number(url.searchParams.get("id")));
+ }
+
+ const badge = {
+ post: url.searchParams.get("post") || undefined,
+ image: url.searchParams.get("image") || undefined,
+ description: url.searchParams.get("description") || null,
+ time: url.searchParams.get("time") || undefined,
+ category: url.searchParams.get("category") || null,
+ hidden: url.searchParams.get("hidden") || false,
+ source: url.searchParams.get("source") || null,
+ designer: url.searchParams.get("designer") || null,
+ };
+
+ if (
+ (await getUserBadges(identity.id)).find(
+ (badge) => Number(badge.id) === Number(url.searchParams.get("update")),
+ )
+ ) {
+ await updateUserBadge(
+ identity.id,
+ Number(url.searchParams.get("update")),
+ badge as Badge,
+ );
+ } else {
+ await addUserBadge(identity.id, badge as Badge);
+ }
+
+ return await badges(identity.id);
};
diff --git a/src/routes/api/birthdays/primary/+server.ts b/src/routes/api/birthdays/primary/+server.ts
index 774d47e1..888baa60 100644
--- a/src/routes/api/birthdays/primary/+server.ts
+++ b/src/routes/api/birthdays/primary/+server.ts
@@ -1,40 +1,40 @@
-import { JSDOM } from 'jsdom';
+import { JSDOM } from "jsdom";
export const GET = async ({ url }: { url: URL }) => {
- const document = new JSDOM(
- await (
- await fetch(
- `https://www.anisearch.com/character/birthdays?month=${url.searchParams.get('month')}`
- )
- ).text()
- ).window.document;
- const section = document.querySelector(`#day-${url.searchParams.get('day')}`);
-
- if (!section) return Response.json([]);
-
- const ul = section.querySelector('ul.covers.simple');
-
- if (!ul) return Response.json([]);
-
- return Response.json(
- Array.from(ul.querySelectorAll('li')).map((li) => {
- const anchor = li.querySelector('a');
- const title = li.querySelector('.title');
-
- if (!anchor || !title) return { image: '', title: '' };
-
- const image = li.getElementsByClassName('item-cover')[0];
-
- return {
- image: image ? image.getAttribute('src') : '',
- name: title.textContent?.trim()
- };
- }),
- {
- headers: {
- 'Cache-Control': 'max-age=10800, s-maxage=10800',
- 'Access-Control-Allow-Origin': 'https://due.moe'
- }
- }
- );
+ const document = new JSDOM(
+ await (
+ await fetch(
+ `https://www.anisearch.com/character/birthdays?month=${url.searchParams.get("month")}`,
+ )
+ ).text(),
+ ).window.document;
+ const section = document.querySelector(`#day-${url.searchParams.get("day")}`);
+
+ if (!section) return Response.json([]);
+
+ const ul = section.querySelector("ul.covers.simple");
+
+ if (!ul) return Response.json([]);
+
+ return Response.json(
+ Array.from(ul.querySelectorAll("li")).map((li) => {
+ const anchor = li.querySelector("a");
+ const title = li.querySelector(".title");
+
+ if (!anchor || !title) return { image: "", title: "" };
+
+ const image = li.getElementsByClassName("item-cover")[0];
+
+ return {
+ image: image ? image.getAttribute("src") : "",
+ name: title.textContent?.trim(),
+ };
+ }),
+ {
+ headers: {
+ "Cache-Control": "max-age=10800, s-maxage=10800",
+ "Access-Control-Allow-Origin": "https://due.moe",
+ },
+ },
+ );
};
diff --git a/src/routes/api/birthdays/secondary/+server.ts b/src/routes/api/birthdays/secondary/+server.ts
index 5036622f..b471a32b 100644
--- a/src/routes/api/birthdays/secondary/+server.ts
+++ b/src/routes/api/birthdays/secondary/+server.ts
@@ -1,28 +1,29 @@
-import { env } from '$env/dynamic/private';
+import { env } from "$env/dynamic/private";
export const GET = async ({ url }: { url: URL }) => {
- return Response.json(
- await (
- await fetch(
- `https://www.animecharactersdatabase.com/api_series_characters.php?month=${url.searchParams.get(
- 'month'
- )}&day=${url.searchParams.get('day')}`,
- {
- headers: {
- Accept: 'application/json',
- 'Content-Type': 'application/json',
- 'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64; rv:120.0) Gecko/20100101 Firefox/120.0',
- 'Cache-Control': 'max-age=10, s-maxage=10',
- Cookie: `USTATS=${env.ACDB_COOKIE}`
- }
- }
- )
- ).json(),
- {
- headers: {
- 'Cache-Control': 'max-age=10800, s-maxage=10800',
- 'Access-Control-Allow-Origin': 'https://due.moe'
- }
- }
- );
+ return Response.json(
+ await (
+ await fetch(
+ `https://www.animecharactersdatabase.com/api_series_characters.php?month=${url.searchParams.get(
+ "month",
+ )}&day=${url.searchParams.get("day")}`,
+ {
+ headers: {
+ Accept: "application/json",
+ "Content-Type": "application/json",
+ "User-Agent":
+ "Mozilla/5.0 (X11; Linux x86_64; rv:120.0) Gecko/20100101 Firefox/120.0",
+ "Cache-Control": "max-age=10, s-maxage=10",
+ Cookie: `USTATS=${env.ACDB_COOKIE}`,
+ },
+ },
+ )
+ ).json(),
+ {
+ headers: {
+ "Cache-Control": "max-age=10800, s-maxage=10800",
+ "Access-Control-Allow-Origin": "https://due.moe",
+ },
+ },
+ );
};
diff --git a/src/routes/api/configuration/+server.ts b/src/routes/api/configuration/+server.ts
index 41a70f7b..10b6b09f 100644
--- a/src/routes/api/configuration/+server.ts
+++ b/src/routes/api/configuration/+server.ts
@@ -1,70 +1,73 @@
-import { userIdentity } from '$lib/Data/AniList/identity';
+import { userIdentity } from "$lib/Data/AniList/identity";
import {
- deleteUserConfiguration,
- getUserConfiguration,
- setUserConfiguration
-} from '$lib/Database/SB/User/configuration';
+ deleteUserConfiguration,
+ getUserConfiguration,
+ setUserConfiguration,
+} from "$lib/Database/SB/User/configuration";
-const unauthorised = new Response('Unauthorised', { status: 401 });
+const unauthorised = new Response("Unauthorised", { status: 401 });
export const GET = async ({ url }) =>
- Response.json(await getUserConfiguration(Number(url.searchParams.get('id') || 0)), {
- headers: {
- 'Access-Control-Allow-Origin': 'https://due.moe'
- }
- });
+ Response.json(
+ await getUserConfiguration(Number(url.searchParams.get("id") || 0)),
+ {
+ headers: {
+ "Access-Control-Allow-Origin": "https://due.moe",
+ },
+ },
+ );
export const PUT = async ({ cookies, request }) => {
- const userCookie = cookies.get('user');
+ const userCookie = cookies.get("user");
- if (!userCookie) return unauthorised;
+ if (!userCookie) return unauthorised;
- const user = JSON.parse(userCookie);
+ const user = JSON.parse(userCookie);
- return Response.json(
- await setUserConfiguration(
- (
- await userIdentity({
- tokenType: user['token_type'],
- expiresIn: user['expires_in'],
- accessToken: user['access_token'],
- refreshToken: user['refresh_token']
- })
- ).id,
- {
- configuration: await request.json()
- }
- ),
- {
- headers: {
- 'Access-Control-Allow-Origin': 'https://due.moe'
- }
- }
- );
+ return Response.json(
+ await setUserConfiguration(
+ (
+ await userIdentity({
+ tokenType: user["token_type"],
+ expiresIn: user["expires_in"],
+ accessToken: user["access_token"],
+ refreshToken: user["refresh_token"],
+ })
+ ).id,
+ {
+ configuration: await request.json(),
+ },
+ ),
+ {
+ headers: {
+ "Access-Control-Allow-Origin": "https://due.moe",
+ },
+ },
+ );
};
export const DELETE = async ({ cookies }) => {
- const userCookie = cookies.get('user');
+ const userCookie = cookies.get("user");
- if (!userCookie) return unauthorised;
+ if (!userCookie) return unauthorised;
- const user = JSON.parse(userCookie);
+ const user = JSON.parse(userCookie);
- return Response.json(
- await deleteUserConfiguration(
- (
- await userIdentity({
- tokenType: user['token_type'],
- expiresIn: user['expires_in'],
- accessToken: user['access_token'],
- refreshToken: user['refresh_token']
- })
- ).id
- ),
- {
- headers: {
- 'Access-Control-Allow-Origin': 'https://due.moe'
- }
- }
- );
+ return Response.json(
+ await deleteUserConfiguration(
+ (
+ await userIdentity({
+ tokenType: user["token_type"],
+ expiresIn: user["expires_in"],
+ accessToken: user["access_token"],
+ refreshToken: user["refresh_token"],
+ })
+ ).id,
+ ),
+ {
+ headers: {
+ "Access-Control-Allow-Origin": "https://due.moe",
+ },
+ },
+ );
};
diff --git a/src/routes/api/events/+server.ts b/src/routes/api/events/+server.ts
index 22280394..f7fee7b8 100644
--- a/src/routes/api/events/+server.ts
+++ b/src/routes/api/events/+server.ts
@@ -1,8 +1,8 @@
-import { getEvents, getGroupEvents } from '$lib/Database/SB/events';
+import { getEvents, getGroupEvents } from "$lib/Database/SB/events";
export const GET = async ({ url }) =>
- Response.json(
- url.searchParams.get('group')
- ? await getGroupEvents(url.searchParams.get('group') || '')
- : await getEvents()
- );
+ Response.json(
+ url.searchParams.get("group")
+ ? await getGroupEvents(url.searchParams.get("group") || "")
+ : await getEvents(),
+ );
diff --git a/src/routes/api/events/group/+server.ts b/src/routes/api/events/group/+server.ts
index 9bd4c33a..b95db775 100644
--- a/src/routes/api/events/group/+server.ts
+++ b/src/routes/api/events/group/+server.ts
@@ -1,4 +1,4 @@
-import { getGroup } from '$lib/Database/SB/groups';
+import { getGroup } from "$lib/Database/SB/groups";
export const GET = async ({ url }) =>
- Response.json(await getGroup(url.searchParams.get('slug') || ''));
+ Response.json(await getGroup(url.searchParams.get("slug") || ""));
diff --git a/src/routes/api/events/groups/+server.ts b/src/routes/api/events/groups/+server.ts
index db50d0ad..d74b872c 100644
--- a/src/routes/api/events/groups/+server.ts
+++ b/src/routes/api/events/groups/+server.ts
@@ -1,3 +1,3 @@
-import { getGroups } from '$lib/Database/SB/groups';
+import { getGroups } from "$lib/Database/SB/groups";
export const GET = async () => Response.json(await getGroups());
diff --git a/src/routes/api/health/+server.ts b/src/routes/api/health/+server.ts
index 66a62024..9161b5c7 100644
--- a/src/routes/api/health/+server.ts
+++ b/src/routes/api/health/+server.ts
@@ -1 +1 @@
-export const GET = () => new Response('OK', { status: 200 });
+export const GET = () => new Response("OK", { status: 200 });
diff --git a/src/routes/api/myanimelist/oauth/callback/+server.ts b/src/routes/api/myanimelist/oauth/callback/+server.ts
index 0bb78a64..57a5fbe4 100644
--- a/src/routes/api/myanimelist/oauth/callback/+server.ts
+++ b/src/routes/api/myanimelist/oauth/callback/+server.ts
@@ -1,18 +1,18 @@
-import { callback } from '$lib/Utility/oauth.js';
-import { env } from '$env/dynamic/private';
-import { env as env2 } from '$env/dynamic/public';
+import { callback } from "$lib/Utility/oauth.js";
+import { env } from "$env/dynamic/private";
+import { env as env2 } from "$env/dynamic/public";
export const GET = async ({ url, cookies }) =>
- callback({
- url,
- cookies,
- cookie: 'myanimelist',
- authorise: 'https://myanimelist.net/v1/oauth2/token',
- redirect: '/settings',
- verifier: env.CODE_VERIFIER,
- client: {
- id: env2.PUBLIC_MYANIMELIST_CLIENT_ID,
- secret: env.MYANIMELIST_CLIENT_SECRET,
- redirectURI: env2.PUBLIC_MYANIMLIST_REDIRECT_URI
- }
- });
+ callback({
+ url,
+ cookies,
+ cookie: "myanimelist",
+ authorise: "https://myanimelist.net/v1/oauth2/token",
+ redirect: "/settings",
+ verifier: env.CODE_VERIFIER,
+ client: {
+ id: env2.PUBLIC_MYANIMELIST_CLIENT_ID,
+ secret: env.MYANIMELIST_CLIENT_SECRET,
+ redirectURI: env2.PUBLIC_MYANIMLIST_REDIRECT_URI,
+ },
+ });
diff --git a/src/routes/api/notifications/subscribe/+server.ts b/src/routes/api/notifications/subscribe/+server.ts
index d410dc9d..5a1cacc4 100644
--- a/src/routes/api/notifications/subscribe/+server.ts
+++ b/src/routes/api/notifications/subscribe/+server.ts
@@ -1,27 +1,27 @@
-import { userIdentity } from '$lib/Data/AniList/identity';
-import { setUserSubscription } from '$lib/Database/SB/User/notifications';
+import { userIdentity } from "$lib/Data/AniList/identity";
+import { setUserSubscription } from "$lib/Database/SB/User/notifications";
-const unauthorised = new Response('Unauthorised', { status: 401 });
+const unauthorised = new Response("Unauthorised", { status: 401 });
export const POST = async ({ cookies, request, url }) => {
- const userCookie = cookies.get('user');
- const fingerprint = url.searchParams.get('p');
+ const userCookie = cookies.get("user");
+ const fingerprint = url.searchParams.get("p");
- if (!userCookie || !fingerprint) return unauthorised;
+ if (!userCookie || !fingerprint) return unauthorised;
- const user = JSON.parse(userCookie);
- const userId = (
- await userIdentity({
- tokenType: user['token_type'],
- expiresIn: user['expires_in'],
- accessToken: user['access_token'],
- refreshToken: user['refresh_token']
- })
- ).id;
+ const user = JSON.parse(userCookie);
+ const userId = (
+ await userIdentity({
+ tokenType: user["token_type"],
+ expiresIn: user["expires_in"],
+ accessToken: user["access_token"],
+ refreshToken: user["refresh_token"],
+ })
+ ).id;
- if (!userId) return unauthorised;
+ if (!userId) return unauthorised;
- await setUserSubscription(userId, await request.json(), fingerprint);
+ await setUserSubscription(userId, await request.json(), fingerprint);
- return new Response(null, { status: 200 });
+ return new Response(null, { status: 200 });
};
diff --git a/src/routes/api/notifications/unsubscribe/+server.ts b/src/routes/api/notifications/unsubscribe/+server.ts
index ded228f3..2db8b5c3 100644
--- a/src/routes/api/notifications/unsubscribe/+server.ts
+++ b/src/routes/api/notifications/unsubscribe/+server.ts
@@ -1,27 +1,27 @@
-import { userIdentity } from '$lib/Data/AniList/identity';
-import { deleteUserSubscription } from '$lib/Database/SB/User/notifications';
+import { userIdentity } from "$lib/Data/AniList/identity";
+import { deleteUserSubscription } from "$lib/Database/SB/User/notifications";
-const unauthorised = new Response('Unauthorised', { status: 401 });
+const unauthorised = new Response("Unauthorised", { status: 401 });
export const POST = async ({ cookies, url }) => {
- const userCookie = cookies.get('user');
- const fingerprint = url.searchParams.get('p');
+ const userCookie = cookies.get("user");
+ const fingerprint = url.searchParams.get("p");
- if (!userCookie || !fingerprint) return unauthorised;
+ if (!userCookie || !fingerprint) return unauthorised;
- const user = JSON.parse(userCookie);
- const userId = (
- await userIdentity({
- tokenType: user['token_type'],
- expiresIn: user['expires_in'],
- accessToken: user['access_token'],
- refreshToken: user['refresh_token']
- })
- ).id;
+ const user = JSON.parse(userCookie);
+ const userId = (
+ await userIdentity({
+ tokenType: user["token_type"],
+ expiresIn: user["expires_in"],
+ accessToken: user["access_token"],
+ refreshToken: user["refresh_token"],
+ })
+ ).id;
- if (!userId) return unauthorised;
+ if (!userId) return unauthorised;
- await deleteUserSubscription(userId, fingerprint);
+ await deleteUserSubscription(userId, fingerprint);
- return new Response(null, { status: 200 });
+ return new Response(null, { status: 200 });
};
diff --git a/src/routes/api/oauth/callback/+server.ts b/src/routes/api/oauth/callback/+server.ts
index 986520f9..c5faa859 100644
--- a/src/routes/api/oauth/callback/+server.ts
+++ b/src/routes/api/oauth/callback/+server.ts
@@ -1,16 +1,16 @@
-import { callback } from '$lib/Utility/oauth.js';
-import { env } from '$env/dynamic/private';
-import { env as env2 } from '$env/dynamic/public';
+import { callback } from "$lib/Utility/oauth.js";
+import { env } from "$env/dynamic/private";
+import { env as env2 } from "$env/dynamic/public";
export const GET = async ({ url, cookies }) =>
- callback({
- url,
- cookies,
- cookie: 'user',
- authorise: 'https://anilist.co/api/v2/oauth/token',
- client: {
- id: env2.PUBLIC_ANILIST_CLIENT_ID,
- secret: env.ANILIST_CLIENT_SECRET,
- redirectURI: env2.PUBLIC_ANILIST_REDIRECT_URI
- }
- });
+ callback({
+ url,
+ cookies,
+ cookie: "user",
+ authorise: "https://anilist.co/api/v2/oauth/token",
+ client: {
+ id: env2.PUBLIC_ANILIST_CLIENT_ID,
+ secret: env.ANILIST_CLIENT_SECRET,
+ redirectURI: env2.PUBLIC_ANILIST_REDIRECT_URI,
+ },
+ });
diff --git a/src/routes/api/oauth/refresh/+server.ts b/src/routes/api/oauth/refresh/+server.ts
index 13f4400c..13e7ab09 100644
--- a/src/routes/api/oauth/refresh/+server.ts
+++ b/src/routes/api/oauth/refresh/+server.ts
@@ -1,30 +1,30 @@
-import { env } from '$env/dynamic/private';
-import { env as env2 } from '$env/dynamic/public';
-import { redirect } from '@sveltejs/kit';
+import { env } from "$env/dynamic/private";
+import { env as env2 } from "$env/dynamic/public";
+import { redirect } from "@sveltejs/kit";
export const GET = async ({ url, cookies }) => {
- const formData = new FormData();
+ const formData = new FormData();
- formData.append('grant_type', 'refresh_token');
- formData.append('client_id', env2.PUBLIC_ANILIST_CLIENT_ID as string);
- formData.append('client_secret', env.ANILIST_CLIENT_SECRET as string);
- formData.append('refresh_token', url.searchParams.get('token') || '');
+ formData.append("grant_type", "refresh_token");
+ formData.append("client_id", env2.PUBLIC_ANILIST_CLIENT_ID as string);
+ formData.append("client_secret", env.ANILIST_CLIENT_SECRET as string);
+ formData.append("refresh_token", url.searchParams.get("token") || "");
- const newUser = await (
- await fetch('https://anilist.co/api/v2/oauth/token', {
- method: 'POST',
- body: formData
- })
- ).json();
+ const newUser = await (
+ await fetch("https://anilist.co/api/v2/oauth/token", {
+ method: "POST",
+ body: formData,
+ })
+ ).json();
- cookies.set('user', JSON.stringify(newUser), {
- path: '/',
- maxAge: 60 * 60 * 24 * 7,
- httpOnly: false,
- sameSite: 'lax',
- secure: false
- });
+ cookies.set("user", JSON.stringify(newUser), {
+ path: "/",
+ maxAge: 60 * 60 * 24 * 7,
+ httpOnly: false,
+ sameSite: "lax",
+ secure: false,
+ });
- if (url.searchParams.get('redirect')) redirect(303, '/');
- else return Response.json(newUser);
+ if (url.searchParams.get("redirect")) redirect(303, "/");
+ else return Response.json(newUser);
};
diff --git a/src/routes/api/preferences/+server.ts b/src/routes/api/preferences/+server.ts
index 0fb91f45..c46a3abf 100644
--- a/src/routes/api/preferences/+server.ts
+++ b/src/routes/api/preferences/+server.ts
@@ -1,89 +1,103 @@
-import { userIdentity } from '$lib/Data/AniList/identity';
+import { userIdentity } from "$lib/Data/AniList/identity";
import {
- getUserPreferences,
- toggleHideMissingBadges,
- setCSS,
- setBiography,
- toggleHideAWCBadges,
- togglePinnedBadgeWallCategory,
- setPinnedBadgeWallCategories
-} from '$lib/Database/SB/User/preferences';
+ getUserPreferences,
+ toggleHideMissingBadges,
+ setCSS,
+ setBiography,
+ toggleHideAWCBadges,
+ togglePinnedBadgeWallCategory,
+ setPinnedBadgeWallCategories,
+} from "$lib/Database/SB/User/preferences";
-const unauthorised = new Response('Unauthorised', { status: 401 });
+const unauthorised = new Response("Unauthorised", { status: 401 });
export const GET = async ({ url }) => {
- const preferences = await getUserPreferences(Number(url.searchParams.get('id') || 0));
+ const preferences = await getUserPreferences(
+ Number(url.searchParams.get("id") || 0),
+ );
- return Response.json(preferences ? preferences : {}, {
- headers: {
- 'Access-Control-Allow-Origin': 'https://due.moe'
- }
- });
+ return Response.json(preferences ? preferences : {}, {
+ headers: {
+ "Access-Control-Allow-Origin": "https://due.moe",
+ },
+ });
};
export const PUT = async ({ url, cookies, request }) => {
- const userCookie = cookies.get('user');
+ const userCookie = cookies.get("user");
- if (!userCookie) return unauthorised;
+ if (!userCookie) return unauthorised;
- const user = JSON.parse(userCookie);
- const userId = (
- await userIdentity({
- tokenType: user['token_type'],
- expiresIn: user['expires_in'],
- accessToken: user['access_token'],
- refreshToken: user['refresh_token']
- })
- ).id;
+ const user = JSON.parse(userCookie);
+ const userId = (
+ await userIdentity({
+ tokenType: user["token_type"],
+ expiresIn: user["expires_in"],
+ accessToken: user["access_token"],
+ refreshToken: user["refresh_token"],
+ })
+ ).id;
- if (url.searchParams.get('toggleHideMissingBadges') !== null)
- return Response.json(await toggleHideMissingBadges(userId), {
- headers: {
- 'Access-Control-Allow-Origin': 'https://due.moe'
- }
- });
+ if (url.searchParams.get("toggleHideMissingBadges") !== null)
+ return Response.json(await toggleHideMissingBadges(userId), {
+ headers: {
+ "Access-Control-Allow-Origin": "https://due.moe",
+ },
+ });
- if (url.searchParams.get('toggleHideAWCBadges') !== null)
- return Response.json(await toggleHideAWCBadges(userId), {
- headers: {
- 'Access-Control-Allow-Origin': 'https://due.moe'
- }
- });
+ if (url.searchParams.get("toggleHideAWCBadges") !== null)
+ return Response.json(await toggleHideAWCBadges(userId), {
+ headers: {
+ "Access-Control-Allow-Origin": "https://due.moe",
+ },
+ });
- if (url.searchParams.get('badgeWallCSS') !== null)
- return Response.json(await setCSS(userId, await request.text()), {
- headers: {
- 'Access-Control-Allow-Origin': 'https://due.moe'
- }
- });
+ if (url.searchParams.get("badgeWallCSS") !== null)
+ return Response.json(await setCSS(userId, await request.text()), {
+ headers: {
+ "Access-Control-Allow-Origin": "https://due.moe",
+ },
+ });
- if (url.searchParams.get('toggleCategory') !== null)
- return Response.json(
- await togglePinnedBadgeWallCategory(userId, url.searchParams.get('toggleCategory') || ''),
- {
- headers: {
- 'Access-Control-Allow-Origin': 'https://due.moe'
- }
- }
- );
+ if (url.searchParams.get("toggleCategory") !== null)
+ return Response.json(
+ await togglePinnedBadgeWallCategory(
+ userId,
+ url.searchParams.get("toggleCategory") || "",
+ ),
+ {
+ headers: {
+ "Access-Control-Allow-Origin": "https://due.moe",
+ },
+ },
+ );
- if (url.searchParams.get('setCategories') !== null)
- return Response.json(await setPinnedBadgeWallCategories(userId, await request.json()), {
- headers: {
- 'Access-Control-Allow-Origin': 'https://due.moe'
- }
- });
+ if (url.searchParams.get("setCategories") !== null)
+ return Response.json(
+ await setPinnedBadgeWallCategories(userId, await request.json()),
+ {
+ headers: {
+ "Access-Control-Allow-Origin": "https://due.moe",
+ },
+ },
+ );
- if (url.searchParams.get('biography') !== null)
- return Response.json(await setBiography(userId, (await request.text()).slice(0, 3000)), {
- headers: {
- 'Access-Control-Allow-Origin': 'https://due.moe'
- }
- });
+ if (url.searchParams.get("biography") !== null)
+ return Response.json(
+ await setBiography(userId, (await request.text()).slice(0, 3000)),
+ {
+ headers: {
+ "Access-Control-Allow-Origin": "https://due.moe",
+ },
+ },
+ );
- return Response.json(await getUserPreferences(Number(url.searchParams.get('id') || 0)), {
- headers: {
- 'Access-Control-Allow-Origin': 'https://due.moe'
- }
- });
+ return Response.json(
+ await getUserPreferences(Number(url.searchParams.get("id") || 0)),
+ {
+ headers: {
+ "Access-Control-Allow-Origin": "https://due.moe",
+ },
+ },
+ );
};
diff --git a/src/routes/api/preferences/pin/+server.ts b/src/routes/api/preferences/pin/+server.ts
index 28398cf0..15465113 100644
--- a/src/routes/api/preferences/pin/+server.ts
+++ b/src/routes/api/preferences/pin/+server.ts
@@ -1,32 +1,32 @@
-import { userIdentity } from '$lib/Data/AniList/identity';
-import { toggleHololiveStreamPinning } from '$lib/Database/SB/User/preferences';
+import { userIdentity } from "$lib/Data/AniList/identity";
+import { toggleHololiveStreamPinning } from "$lib/Database/SB/User/preferences";
-const unauthorised = new Response('Unauthorised', { status: 401 });
+const unauthorised = new Response("Unauthorised", { status: 401 });
export const PUT = async ({ cookies, url }) => {
- const userCookie = cookies.get('user');
+ const userCookie = cookies.get("user");
- if (!userCookie) return unauthorised;
+ if (!userCookie) return unauthorised;
- const user = JSON.parse(userCookie);
+ const user = JSON.parse(userCookie);
- return Response.json(
- await toggleHololiveStreamPinning(
- (
- await userIdentity({
- tokenType: user['token_type'],
- expiresIn: user['expires_in'],
- accessToken: user['access_token'],
- refreshToken: user['refresh_token']
- })
- ).id,
- url.searchParams.get('stream') || ''
- ),
- {
- headers: {
- method: 'PUT',
- 'Access-Control-Allow-Origin': 'https://due.moe'
- }
- }
- );
+ return Response.json(
+ await toggleHololiveStreamPinning(
+ (
+ await userIdentity({
+ tokenType: user["token_type"],
+ expiresIn: user["expires_in"],
+ accessToken: user["access_token"],
+ refreshToken: user["refresh_token"],
+ })
+ ).id,
+ url.searchParams.get("stream") || "",
+ ),
+ {
+ headers: {
+ method: "PUT",
+ "Access-Control-Allow-Origin": "https://due.moe",
+ },
+ },
+ );
};
diff --git a/src/routes/api/subsplease/+server.ts b/src/routes/api/subsplease/+server.ts
index 93e734c2..93b91609 100644
--- a/src/routes/api/subsplease/+server.ts
+++ b/src/routes/api/subsplease/+server.ts
@@ -1,16 +1,16 @@
export const GET = async ({ url }) =>
- Response.json(
- await (
- await fetch(
- `https://subsplease.org/api/?f=schedule&tz=${
- url.searchParams.get('tz') || 'America/Los_Angeles'
- }`
- )
- ).json(),
- {
- headers: {
- 'Cache-Control': 'max-age=86400, s-maxage=86400',
- 'Access-Control-Allow-Origin': 'https://due.moe'
- }
- }
- );
+ Response.json(
+ await (
+ await fetch(
+ `https://subsplease.org/api/?f=schedule&tz=${
+ url.searchParams.get("tz") || "America/Los_Angeles"
+ }`,
+ )
+ ).json(),
+ {
+ headers: {
+ "Cache-Control": "max-age=86400, s-maxage=86400",
+ "Access-Control-Allow-Origin": "https://due.moe",
+ },
+ },
+ );
diff --git a/src/routes/api/updates/all-novels/+server.ts b/src/routes/api/updates/all-novels/+server.ts
index 5dd2aaad..f90656bf 100644
--- a/src/routes/api/updates/all-novels/+server.ts
+++ b/src/routes/api/updates/all-novels/+server.ts
@@ -1,20 +1,20 @@
export const GET = async ({ setHeaders }) => {
- setHeaders({
- 'Cache-Control': 'public, max-age=600, s-maxage=600'
- });
+ setHeaders({
+ "Cache-Control": "public, max-age=600, s-maxage=600",
+ });
- return Response.json(
- await (
- await fetch('https://www.wlnupdates.com/api', {
- method: 'POST',
- headers: {
- 'Content-Type': 'application/json',
- 'Access-Control-Allow-Origin': 'https://due.moe'
- },
- body: JSON.stringify({
- mode: 'get-releases'
- })
- })
- ).json()
- );
+ return Response.json(
+ await (
+ await fetch("https://www.wlnupdates.com/api", {
+ method: "POST",
+ headers: {
+ "Content-Type": "application/json",
+ "Access-Control-Allow-Origin": "https://due.moe",
+ },
+ body: JSON.stringify({
+ mode: "get-releases",
+ }),
+ })
+ ).json(),
+ );
};
diff --git a/src/routes/api/updates/manga/+server.ts b/src/routes/api/updates/manga/+server.ts
index af078c05..c794d7b3 100644
--- a/src/routes/api/updates/manga/+server.ts
+++ b/src/routes/api/updates/manga/+server.ts
@@ -1,18 +1,18 @@
-import Parser from 'rss-parser';
+import Parser from "rss-parser";
export const GET = async ({ setHeaders }) => {
- setHeaders({
- 'Cache-Control': 'public, max-age=600, s-maxage=600'
- });
+ setHeaders({
+ "Cache-Control": "public, max-age=600, s-maxage=600",
+ });
- return Response.json(
- await new Parser().parseString(
- await (await fetch('https://www.mangaupdates.com/rss.php')).text()
- ),
- {
- headers: {
- 'Access-Control-Allow-Origin': 'https://due.moe'
- }
- }
- );
+ return Response.json(
+ await new Parser().parseString(
+ await (await fetch("https://www.mangaupdates.com/rss.php")).text(),
+ ),
+ {
+ headers: {
+ "Access-Control-Allow-Origin": "https://due.moe",
+ },
+ },
+ );
};
diff --git a/src/routes/api/updates/novels/+server.ts b/src/routes/api/updates/novels/+server.ts
index 7ca6ca43..7258b966 100644
--- a/src/routes/api/updates/novels/+server.ts
+++ b/src/routes/api/updates/novels/+server.ts
@@ -1,18 +1,18 @@
-import Parser from 'rss-parser';
+import Parser from "rss-parser";
export const GET = async ({ setHeaders }) => {
- setHeaders({
- 'Cache-Control': 'public, max-age=600, s-maxage=600'
- });
+ setHeaders({
+ "Cache-Control": "public, max-age=600, s-maxage=600",
+ });
- return Response.json(
- await new Parser().parseString(
- await (await fetch('https://api.syosetu.com/allnovel.Atom')).text()
- ),
- {
- headers: {
- 'Access-Control-Allow-Origin': 'https://due.moe'
- }
- }
- );
+ return Response.json(
+ await new Parser().parseString(
+ await (await fetch("https://api.syosetu.com/allnovel.Atom")).text(),
+ ),
+ {
+ headers: {
+ "Access-Control-Allow-Origin": "https://due.moe",
+ },
+ },
+ );
};