diff options
| author | Fuwn <[email protected]> | 2026-03-01 16:20:51 -0800 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2026-03-01 16:21:02 -0800 |
| commit | eae5d24d9e79e59a19d4721caaeaa0ca650ecb33 (patch) | |
| tree | 1b685bb248e051dfa26d2bfdebe6689402dd93c5 /src/lib/Utility | |
| parent | chore(tooling): remove legacy eslint and prettier (diff) | |
| download | due.moe-eae5d24d9e79e59a19d4721caaeaa0ca650ecb33.tar.xz due.moe-eae5d24d9e79e59a19d4721caaeaa0ca650ecb33.zip | |
chore(biome): drop formatter style overrides
Diffstat (limited to 'src/lib/Utility')
| -rw-r--r-- | src/lib/Utility/device.ts | 26 | ||||
| -rw-r--r-- | src/lib/Utility/fingerprint.ts | 24 | ||||
| -rw-r--r-- | src/lib/Utility/html.ts | 141 | ||||
| -rw-r--r-- | src/lib/Utility/image.ts | 74 | ||||
| -rw-r--r-- | src/lib/Utility/notifications.ts | 99 | ||||
| -rw-r--r-- | src/lib/Utility/oauth.ts | 76 | ||||
| -rw-r--r-- | src/lib/Utility/parameters.ts | 46 | ||||
| -rw-r--r-- | src/lib/Utility/persistentStore.ts | 26 | ||||
| -rw-r--r-- | src/lib/Utility/privilegedUser.ts | 2 | ||||
| -rw-r--r-- | src/lib/Utility/proxy.ts | 20 | ||||
| -rw-r--r-- | src/lib/Utility/root.ts | 8 | ||||
| -rw-r--r-- | src/lib/Utility/string.ts | 2 | ||||
| -rw-r--r-- | src/lib/Utility/time.ts | 10 |
13 files changed, 285 insertions, 269 deletions
diff --git a/src/lib/Utility/device.ts b/src/lib/Utility/device.ts index fa3aeda9..179c57ac 100644 --- a/src/lib/Utility/device.ts +++ b/src/lib/Utility/device.ts @@ -1,17 +1,17 @@ export const mobile = () => { - let check = false; + let check = false; - ((a) => { - if ( - /(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows ce|xda|xiino/i.test( - a - ) || - /1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw-(n|u)|c55\/|capi|ccwa|cdm-|cell|chtm|cldc|cmd-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc-s|devi|dica|dmob|do(c|p)o|ds(12|-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(-|_)|g1 u|g560|gene|gf-5|g-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd-(m|p|t)|hei-|hi(pt|ta)|hp( i|ip)|hs-c|ht(c(-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i-(20|go|ma)|i230|iac( |-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|-[a-w])|libw|lynx|m1-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|-([1-8]|c))|phil|pire|pl(ay|uc)|pn-2|po(ck|rt|se)|prox|psio|pt-g|qa-a|qc(07|12|21|32|60|-[2-7]|i-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h-|oo|p-)|sdk\/|se(c(-|0|1)|47|mc|nd|ri)|sgh-|shar|sie(-|m)|sk-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h-|v-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl-|tdg-|tel(i|m)|tim-|t-mo|to(pl|sh)|ts(70|m-|m3|m5)|tx-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas-|your|zeto|zte-/i.test( - a.substr(0, 4) - ) - ) - check = true; - })(navigator.userAgent || navigator.vendor); + ((a) => { + if ( + /(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows ce|xda|xiino/i.test( + a, + ) || + /1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw-(n|u)|c55\/|capi|ccwa|cdm-|cell|chtm|cldc|cmd-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc-s|devi|dica|dmob|do(c|p)o|ds(12|-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(-|_)|g1 u|g560|gene|gf-5|g-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd-(m|p|t)|hei-|hi(pt|ta)|hp( i|ip)|hs-c|ht(c(-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i-(20|go|ma)|i230|iac( |-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|-[a-w])|libw|lynx|m1-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|-([1-8]|c))|phil|pire|pl(ay|uc)|pn-2|po(ck|rt|se)|prox|psio|pt-g|qa-a|qc(07|12|21|32|60|-[2-7]|i-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h-|oo|p-)|sdk\/|se(c(-|0|1)|47|mc|nd|ri)|sgh-|shar|sie(-|m)|sk-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h-|v-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl-|tdg-|tel(i|m)|tim-|t-mo|to(pl|sh)|ts(70|m-|m3|m5)|tx-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas-|your|zeto|zte-/i.test( + a.substr(0, 4), + ) + ) + check = true; + })(navigator.userAgent || navigator.vendor); - return check; + return check; }; diff --git a/src/lib/Utility/fingerprint.ts b/src/lib/Utility/fingerprint.ts index 2c7211b4..73a9a978 100644 --- a/src/lib/Utility/fingerprint.ts +++ b/src/lib/Utility/fingerprint.ts @@ -1,14 +1,18 @@ export const getFingerprint = () => - btoa( - `${(() => { - const gl = new OffscreenCanvas(0, 0).getContext('webgl'); + btoa( + `${(() => { + const gl = new OffscreenCanvas(0, 0).getContext("webgl"); - if (!gl) return 'none'; + if (!gl) return "none"; - const debugInfo = gl.getExtension('WEBGL_debug_renderer_info'); + const debugInfo = gl.getExtension("WEBGL_debug_renderer_info"); - return debugInfo ? gl.getParameter(debugInfo.UNMASKED_RENDERER_WEBGL) : 'unknown'; - })()}-${ - navigator === null || navigator === void 0 ? void 0 : navigator.hardwareConcurrency - }-${new Date().getTimezoneOffset()}` - ); + return debugInfo + ? gl.getParameter(debugInfo.UNMASKED_RENDERER_WEBGL) + : "unknown"; + })()}-${ + navigator === null || navigator === void 0 + ? void 0 + : navigator.hardwareConcurrency + }-${new Date().getTimezoneOffset()}`, + ); diff --git a/src/lib/Utility/html.ts b/src/lib/Utility/html.ts index 7e0f04c6..10d52971 100644 --- a/src/lib/Utility/html.ts +++ b/src/lib/Utility/html.ts @@ -1,97 +1,98 @@ -import settings from '$stores/settings'; -import { get } from 'svelte/store'; +import settings from "$stores/settings"; +import { get } from "svelte/store"; -export const nbsp = (str: string) => str.replace(/ /g, ' '); +export const nbsp = (str: string) => str.replace(/ /g, " "); export const createHeightObserver = (details = true) => { - const observedElements = new Set<HTMLElement>(); - const resizeObservers = new Map<HTMLElement, ResizeObserver>(); - const detailObservers = new Map<HTMLElement, MutationObserver>(); + const observedElements = new Set<HTMLElement>(); + const resizeObservers = new Map<HTMLElement, ResizeObserver>(); + const detailObservers = new Map<HTMLElement, MutationObserver>(); - const applyHeightLimit = (target: HTMLElement) => { - if (!get(settings).displayLimitListHeight) { - target.style.height = 'auto'; + const applyHeightLimit = (target: HTMLElement) => { + if (!get(settings).displayLimitListHeight) { + target.style.height = "auto"; - return; - } + return; + } - target.style.height = 'auto'; + target.style.height = "auto"; - const elementBound = target.getBoundingClientRect(); - const height = window.innerHeight - elementBound.top - 2.5 * 16; + const elementBound = target.getBoundingClientRect(); + const height = window.innerHeight - elementBound.top - 2.5 * 16; - if (elementBound.height > height) target.style.height = `${height}px`; - }; + if (elementBound.height > height) target.style.height = `${height}px`; + }; - const observeElement = (element: HTMLElement) => { - if (element.dataset.observed) return; + const observeElement = (element: HTMLElement) => { + if (element.dataset.observed) return; - const resizeObserver = new ResizeObserver((entries) => { - entries.forEach((entry) => { - const target = entry.target as HTMLElement; + const resizeObserver = new ResizeObserver((entries) => { + entries.forEach((entry) => { + const target = entry.target as HTMLElement; - applyHeightLimit(target); - }); - }); + applyHeightLimit(target); + }); + }); - resizeObserver.observe(element); - resizeObservers.set(element, resizeObserver); + resizeObserver.observe(element); + resizeObservers.set(element, resizeObserver); - if (details) { - const detailsObserver = new MutationObserver((mutations) => { - mutations.forEach((mutation) => { - const target = mutation.target as HTMLDetailsElement; + if (details) { + const detailsObserver = new MutationObserver((mutations) => { + mutations.forEach((mutation) => { + const target = mutation.target as HTMLDetailsElement; - if (target.tagName === 'DETAILS' && !target.open) target.style.height = 'auto'; - }); - }); + if (target.tagName === "DETAILS" && !target.open) + target.style.height = "auto"; + }); + }); - detailsObserver.observe(element, { attributes: true }); - detailObservers.set(element, detailsObserver); - } + detailsObserver.observe(element, { attributes: true }); + detailObservers.set(element, detailsObserver); + } - element.dataset.observed = 'true'; + element.dataset.observed = "true"; - observedElements.add(element); - applyHeightLimit(element); - }; + observedElements.add(element); + applyHeightLimit(element); + }; - document.querySelectorAll<HTMLElement>('.list').forEach(observeElement); + document.querySelectorAll<HTMLElement>(".list").forEach(observeElement); - const mutationObserver = new MutationObserver((mutations) => { - mutations.forEach((mutation) => { - mutation.addedNodes.forEach((node) => { - if (!(node instanceof HTMLElement)) return; + const mutationObserver = new MutationObserver((mutations) => { + mutations.forEach((mutation) => { + mutation.addedNodes.forEach((node) => { + if (!(node instanceof HTMLElement)) return; - if (node.matches('.list')) observeElement(node); + if (node.matches(".list")) observeElement(node); - node.querySelectorAll<HTMLElement>('.list').forEach(observeElement); - }); - }); - }); + node.querySelectorAll<HTMLElement>(".list").forEach(observeElement); + }); + }); + }); - mutationObserver.observe(document.body, { childList: true, subtree: true }); + mutationObserver.observe(document.body, { childList: true, subtree: true }); - const unsubscribeSettings = settings.subscribe(() => { - observedElements.forEach((element) => { - applyHeightLimit(element); - }); - }); + const unsubscribeSettings = settings.subscribe(() => { + observedElements.forEach((element) => { + applyHeightLimit(element); + }); + }); - return () => { - unsubscribeSettings(); - mutationObserver.disconnect(); - resizeObservers.forEach((observer) => { - observer.disconnect(); - }); - detailObservers.forEach((observer) => { - observer.disconnect(); - }); + return () => { + unsubscribeSettings(); + mutationObserver.disconnect(); + resizeObservers.forEach((observer) => { + observer.disconnect(); + }); + detailObservers.forEach((observer) => { + observer.disconnect(); + }); - observedElements.forEach((element) => { - element.style.height = 'auto'; + observedElements.forEach((element) => { + element.style.height = "auto"; - delete element.dataset.observed; - }); - }; + delete element.dataset.observed; + }); + }; }; diff --git a/src/lib/Utility/image.ts b/src/lib/Utility/image.ts index b8ed0663..2d08e62f 100644 --- a/src/lib/Utility/image.ts +++ b/src/lib/Utility/image.ts @@ -1,46 +1,50 @@ -import { env } from '$env/dynamic/public'; +import { env } from "$env/dynamic/public"; export const cdn = (urlString: string | undefined) => - !urlString || - !['http', 'https'].some((protocol) => urlString.startsWith(protocol)) || - env.PUBLIC_ANILIST_REDIRECT_URI?.includes('localhost') || - [ - 'api.telegram.org', - 'telegra.ph', - 't.me', - 'discord.com', - 'cdn.discordapp.com', - 'media.discordapp.net', - 'images-ext-1.discordapp.net', - 'images-ext-2.discordapp.net', - 'media.trace.moe', - 'files.catbox.moe' - ].includes(new URL(urlString).hostname) - ? urlString - : `https://cdn.due.moe?url=${encodeURIComponent(urlString)}`; + !urlString || + !["http", "https"].some((protocol) => urlString.startsWith(protocol)) || + env.PUBLIC_ANILIST_REDIRECT_URI?.includes("localhost") || + [ + "api.telegram.org", + "telegra.ph", + "t.me", + "discord.com", + "cdn.discordapp.com", + "media.discordapp.net", + "images-ext-1.discordapp.net", + "images-ext-2.discordapp.net", + "media.trace.moe", + "files.catbox.moe", + ].includes(new URL(urlString).hostname) + ? urlString + : `https://cdn.due.moe?url=${encodeURIComponent(urlString)}`; export const thumbnail = (url: string | undefined) => { - const width = 144; - const height = 200; + const width = 144; + const height = 200; - if (url && url.includes('catbox.moe') && !url.includes('gif')) - return url.replace('catbox.moe/', 'catbox.moe/thumbs/t_'); + if (url && url.includes("catbox.moe") && !url.includes("gif")) + return url.replace("catbox.moe/", "catbox.moe/thumbs/t_"); - if (url && url.includes('imgur') && !url.includes('gif')) - return (!url.includes('i.imgur.com') ? url.replace('imgur.com', 'i.imgur.com') : url).replace( - /(\.\w+)$/, - `_d.webp?maxwidth=${width}&shape=thumb&fidelity=high` - ); + if (url && url.includes("imgur") && !url.includes("gif")) + return ( + !url.includes("i.imgur.com") + ? url.replace("imgur.com", "i.imgur.com") + : url + ).replace( + /(\.\w+)$/, + `_d.webp?maxwidth=${width}&shape=thumb&fidelity=high`, + ); - if (url && url.includes('discordapp')) { - const match = url.match(/attachments\/(\d+)\/(\d+)\/(.+)/); + if (url && url.includes("discordapp")) { + const match = url.match(/attachments\/(\d+)\/(\d+)\/(.+)/); - if (match) { - const [, server, id, file] = match; + if (match) { + const [, server, id, file] = match; - return `https://media.discordapp.net/attachments/${server}/${id}/${file}?width=${width}&height=${height}`; - } - } + return `https://media.discordapp.net/attachments/${server}/${id}/${file}?width=${width}&height=${height}`; + } + } - return url; + return url; }; diff --git a/src/lib/Utility/notifications.ts b/src/lib/Utility/notifications.ts index 92f1f1f9..8ed44629 100644 --- a/src/lib/Utility/notifications.ts +++ b/src/lib/Utility/notifications.ts @@ -1,57 +1,64 @@ -import { env } from '$env/dynamic/public'; +import { env } from "$env/dynamic/public"; import { - isNotificationQueued, - notifications, - updateLastNotificationID -} from '$lib/Data/AniList/notifications'; -import { database } from '$lib/Database/IDB/user'; -import { getFingerprint } from './fingerprint'; -import root from './root'; + isNotificationQueued, + notifications, + updateLastNotificationID, +} from "$lib/Data/AniList/notifications"; +import { database } from "$lib/Database/IDB/user"; +import { getFingerprint } from "./fingerprint"; +import root from "./root"; export const requestNotifications = async () => { - if ('Notification' in window && navigator.serviceWorker) { - const registration = await navigator.serviceWorker.getRegistration(); - - if (registration) { - try { - const pushSubscription = await registration.pushManager.subscribe({ - userVisibleOnly: true, - applicationServerKey: env.PUBLIC_VAPID_PUBLIC_KEY - }); - - await fetch(root(`/api/notifications/subscribe?p=${getFingerprint()}`), { - method: 'POST', - headers: { - 'Content-Type': 'application/json' - }, - body: JSON.stringify(pushSubscription) - }); - } catch { - await fetch(`/api/notifications/unsubscribe?p=${getFingerprint()}`, { - method: 'POST' - }); - await updateLocalNotifications(); - setInterval(async () => await updateLocalNotifications(), 1000 * 60); - } - } - } + if ("Notification" in window && navigator.serviceWorker) { + const registration = await navigator.serviceWorker.getRegistration(); + + if (registration) { + try { + const pushSubscription = await registration.pushManager.subscribe({ + userVisibleOnly: true, + applicationServerKey: env.PUBLIC_VAPID_PUBLIC_KEY, + }); + + await fetch( + root(`/api/notifications/subscribe?p=${getFingerprint()}`), + { + method: "POST", + headers: { + "Content-Type": "application/json", + }, + body: JSON.stringify(pushSubscription), + }, + ); + } catch { + await fetch(`/api/notifications/unsubscribe?p=${getFingerprint()}`, { + method: "POST", + }); + await updateLocalNotifications(); + setInterval(async () => await updateLocalNotifications(), 1000 * 60); + } + } + } }; const updateLocalNotifications = async () => { - const user = (await database.users.toArray()).at(0); + const user = (await database.users.toArray()).at(0); - if (!user) return; + if (!user) return; - const recentNotifications = await notifications(user.user.accessToken); + const recentNotifications = await notifications(user.user.accessToken); - if ((await window.Notification.requestPermission()) === 'granted') - if (recentNotifications && isNotificationQueued(recentNotifications, user.lastNotificationID)) { - await updateLastNotificationID(user.id, recentNotifications); + if ((await window.Notification.requestPermission()) === "granted") + if ( + recentNotifications && + isNotificationQueued(recentNotifications, user.lastNotificationID) + ) { + await updateLastNotificationID(user.id, recentNotifications); - new Notification('due.moe', { - body: `${recentNotifications[0].user.name}${recentNotifications[0].context}`, - icon: recentNotifications[0].user.avatar.large || '/favicon-196x196.png', - tag: 'notification-1' - }); - } + new Notification("due.moe", { + body: `${recentNotifications[0].user.name}${recentNotifications[0].context}`, + icon: + recentNotifications[0].user.avatar.large || "/favicon-196x196.png", + tag: "notification-1", + }); + } }; diff --git a/src/lib/Utility/oauth.ts b/src/lib/Utility/oauth.ts index c42739c3..07e8f114 100644 --- a/src/lib/Utility/oauth.ts +++ b/src/lib/Utility/oauth.ts @@ -1,51 +1,51 @@ -import { redirect, type Cookies } from '@sveltejs/kit'; +import { redirect, type Cookies } from "@sveltejs/kit"; export interface ClientOptions { - id: string; - secret: string; - redirectURI: string; + id: string; + secret: string; + redirectURI: string; } export interface CallbackOptions { - url: URL; - cookies: Cookies; - cookie: string; - authorise: string; - redirect?: string; - client: ClientOptions; - verifier?: string; + url: URL; + cookies: Cookies; + cookie: string; + authorise: string; + redirect?: string; + client: ClientOptions; + verifier?: string; } export const callback = async (options: CallbackOptions) => { - const { url, cookies, cookie, authorise, client } = options; - const formData = new FormData(); + const { url, cookies, cookie, authorise, client } = options; + const formData = new FormData(); - formData.append('grant_type', 'authorization_code'); - formData.append('client_id', client.id); - formData.append('client_secret', client.secret); - formData.append('redirect_uri', client.redirectURI); - formData.append('code', url.searchParams.get('code') || 'null'); + formData.append("grant_type", "authorization_code"); + formData.append("client_id", client.id); + formData.append("client_secret", client.secret); + formData.append("redirect_uri", client.redirectURI); + formData.append("code", url.searchParams.get("code") || "null"); - if (options.verifier) formData.append('code_verifier', options.verifier); + if (options.verifier) formData.append("code_verifier", options.verifier); - cookies.set( - cookie, - JSON.stringify( - await ( - await fetch(authorise, { - method: 'POST', - body: formData - }) - ).json() - ), - { - path: '/', - maxAge: 31536000 / 2, - httpOnly: false, - sameSite: 'lax', - secure: false - } - ); + cookies.set( + cookie, + JSON.stringify( + await ( + await fetch(authorise, { + method: "POST", + body: formData, + }) + ).json(), + ), + { + path: "/", + maxAge: 31536000 / 2, + httpOnly: false, + sameSite: "lax", + secure: false, + }, + ); - redirect(303, options.redirect ?? '/'); + redirect(303, options.redirect ?? "/"); }; diff --git a/src/lib/Utility/parameters.ts b/src/lib/Utility/parameters.ts index 07154754..17e97f1e 100644 --- a/src/lib/Utility/parameters.ts +++ b/src/lib/Utility/parameters.ts @@ -1,31 +1,31 @@ -import { browser } from '$app/environment'; -import { page } from '$app/stores'; -import { get } from 'svelte/store'; +import { browser } from "$app/environment"; +import { page } from "$app/stores"; +import { get } from "svelte/store"; export const clearAllParameters = (saved: string[] = []) => { - if (browser) { - if (get(page).url.searchParams.size === 0) return; + if (browser) { + if (get(page).url.searchParams.size === 0) return; - const parameters = new URLSearchParams(); + const parameters = new URLSearchParams(); - saved.forEach((key) => { - if (get(page).url.searchParams.has(key)) { - parameters.set(key, get(page).url.searchParams.get(key) || ''); - } - }); - history.replaceState(null, '', `${get(page).url.pathname}?${parameters}`); - } + saved.forEach((key) => { + if (get(page).url.searchParams.has(key)) { + parameters.set(key, get(page).url.searchParams.get(key) || ""); + } + }); + history.replaceState(null, "", `${get(page).url.pathname}?${parameters}`); + } }; export const parseOrDefault = <T = string | number>( - urlParameters: URLSearchParams | null, - parameter: string, - fallback: T + urlParameters: URLSearchParams | null, + parameter: string, + fallback: T, ): T => - typeof fallback === 'number' - ? ((browser && urlParameters?.size !== 0 - ? parseInt(urlParameters?.get(parameter) || '', 10) || fallback - : fallback) as T) - : ((browser && urlParameters?.size !== 0 - ? urlParameters?.get(parameter) || fallback - : fallback) as T); + typeof fallback === "number" + ? ((browser && urlParameters?.size !== 0 + ? parseInt(urlParameters?.get(parameter) || "", 10) || fallback + : fallback) as T) + : ((browser && urlParameters?.size !== 0 + ? urlParameters?.get(parameter) || fallback + : fallback) as T); diff --git a/src/lib/Utility/persistentStore.ts b/src/lib/Utility/persistentStore.ts index b08c825c..7df3049f 100644 --- a/src/lib/Utility/persistentStore.ts +++ b/src/lib/Utility/persistentStore.ts @@ -1,19 +1,19 @@ -import { writable, type Writable } from 'svelte/store'; -import { browser } from '$app/environment'; +import { writable, type Writable } from "svelte/store"; +import { browser } from "$app/environment"; export const persistentStore = <T>(key: string, initial: T): Writable<T> => { - const store = writable<T>(initial); + const store = writable<T>(initial); - if (browser) - import('localforage').then((localforage) => { - localforage.default.getItem<T>(key).then((value) => { - if (value !== null) store.set(value); - }); + if (browser) + import("localforage").then((localforage) => { + localforage.default.getItem<T>(key).then((value) => { + if (value !== null) store.set(value); + }); - store.subscribe((value) => { - localforage.default.setItem(key, value); - }); - }); + store.subscribe((value) => { + localforage.default.setItem(key, value); + }); + }); - return store; + return store; }; diff --git a/src/lib/Utility/privilegedUser.ts b/src/lib/Utility/privilegedUser.ts index 769032b9..b94e57bc 100644 --- a/src/lib/Utility/privilegedUser.ts +++ b/src/lib/Utility/privilegedUser.ts @@ -1,4 +1,4 @@ -import authorisedJson from '$lib/Data/Static/authorised.json'; +import authorisedJson from "$lib/Data/Static/authorised.json"; const privilegedUser = (id: number) => authorisedJson.includes(id); diff --git a/src/lib/Utility/proxy.ts b/src/lib/Utility/proxy.ts index 4c7cbb90..c6577ac0 100644 --- a/src/lib/Utility/proxy.ts +++ b/src/lib/Utility/proxy.ts @@ -1,16 +1,16 @@ -import { env } from '$env/dynamic/public'; +import { env } from "$env/dynamic/public"; export const proxy = (url: string, disable = false) => { - const randomKey = Math.floor(Math.random() * 90) + 10; + const randomKey = Math.floor(Math.random() * 90) + 10; - return env.PUBLIC_ANILIST_REDIRECT_URI?.includes('localhost') && !disable - ? url - : `https://proxy.due.moe/?d2=${btoa( - url - .split('') - .map((char) => char.charCodeAt(0) + randomKey) - .join(':') - )}${randomKey}&dh`; + return env.PUBLIC_ANILIST_REDIRECT_URI?.includes("localhost") && !disable + ? url + : `https://proxy.due.moe/?d2=${btoa( + url + .split("") + .map((char) => char.charCodeAt(0) + randomKey) + .join(":"), + )}${randomKey}&dh`; }; export default proxy; diff --git a/src/lib/Utility/root.ts b/src/lib/Utility/root.ts index f2a17d04..bf8bb11f 100644 --- a/src/lib/Utility/root.ts +++ b/src/lib/Utility/root.ts @@ -1,8 +1,8 @@ -import { env } from '$env/dynamic/public'; +import { env } from "$env/dynamic/public"; export const root = (path: string, enable = false) => - env.PUBLIC_ANILIST_REDIRECT_URI?.includes('localhost') || enable - ? `http://localhost:5173${path}` - : `https://due.moe${path}`; + env.PUBLIC_ANILIST_REDIRECT_URI?.includes("localhost") || enable + ? `http://localhost:5173${path}` + : `https://due.moe${path}`; export default root; diff --git a/src/lib/Utility/string.ts b/src/lib/Utility/string.ts index 7ecd2023..8cfc4ee5 100644 --- a/src/lib/Utility/string.ts +++ b/src/lib/Utility/string.ts @@ -1,2 +1,2 @@ export const abbreviate = (title: string, maxLength: number) => - title.length > maxLength ? `${title.slice(0, maxLength)}...` : title; + title.length > maxLength ? `${title.slice(0, maxLength)}...` : title; diff --git a/src/lib/Utility/time.ts b/src/lib/Utility/time.ts index da864e26..a390c3d5 100644 --- a/src/lib/Utility/time.ts +++ b/src/lib/Utility/time.ts @@ -1,14 +1,14 @@ -export const databaseTimeToDate = (time: string) => new Date(time + 'Z'); +export const databaseTimeToDate = (time: string) => new Date(time + "Z"); export const dateToDatabaseTime = (date: Date) => - date.toISOString().replace('T', ' ').replace(/\..+/, ''); + date.toISOString().replace("T", " ").replace(/\..+/, ""); export const dateToInputTime = (date: Date) => { - const offset = date.getTimezoneOffset(); + const offset = date.getTimezoneOffset(); - date.setMinutes(date.getMinutes() - offset); + date.setMinutes(date.getMinutes() - offset); - return date.toISOString().slice(0, 16); + return date.toISOString().slice(0, 16); }; export const inputTimeToDatabaseTime = (date: Date) => dateToDatabaseTime(date); |