chore: npm run format + lint

This commit is contained in:
2025-12-30 11:23:55 -05:00
parent 55bee20e5d
commit d71b60bd7e
7 changed files with 134 additions and 116 deletions
+1 -1
View File
@@ -78,4 +78,4 @@ export const roles = {
1: 'Moderator',
255: 'Administrator',
403: 'Banned'
}
};
@@ -1,6 +1,6 @@
export interface Pagination {
page: number;
pageSize: number;
totalCount: number;
totalPages: number;
page: number;
pageSize: number;
totalCount: number;
totalPages: number;
}
+23 -8
View File
@@ -6,12 +6,22 @@ const REFRESH_TOKEN_KEY = 'refreshToken';
export function getToken() {
if (!browser) return null;
return document.cookie.split('; ').find(c => c.startsWith(`${TOKEN_KEY}=`))?.split('=')[1] || null;
return (
document.cookie
.split('; ')
.find((c) => c.startsWith(`${TOKEN_KEY}=`))
?.split('=')[1] || null
);
}
export function getRefreshToken() {
if (!browser) return null;
return document.cookie.split('; ').find(c => c.startsWith(`${REFRESH_TOKEN_KEY}=`))?.split('=')[1] || null;
return (
document.cookie
.split('; ')
.find((c) => c.startsWith(`${REFRESH_TOKEN_KEY}=`))
?.split('=')[1] || null
);
}
export function setTokens(token: string, refreshToken: string) {
@@ -67,19 +77,24 @@ export function startTokenRefreshInterval() {
}
export function getServerToken(cookies: Cookies) {
return cookies.get('token');
return cookies.get('token');
}
export function getServerRefreshToken(cookies: Cookies) {
return cookies.get('refreshToken');
return cookies.get('refreshToken');
}
export function setServerTokens(cookies: Cookies, token: string, refreshToken: string) {
cookies.set('token', token, { path: '/', httpOnly: true, sameSite: 'strict', secure: true });
cookies.set('refreshToken', refreshToken, { path: '/', httpOnly: true, sameSite: 'strict', secure: true });
cookies.set('token', token, { path: '/', httpOnly: true, sameSite: 'strict', secure: true });
cookies.set('refreshToken', refreshToken, {
path: '/',
httpOnly: true,
sameSite: 'strict',
secure: true
});
}
export function clearServerTokens(cookies: Cookies) {
cookies.delete('token', { path: '/' });
cookies.delete('refreshToken', { path: '/' });
cookies.delete('token', { path: '/' });
cookies.delete('refreshToken', { path: '/' });
}
+82 -82
View File
@@ -1,87 +1,87 @@
export async function encryptAES(content: string, password: string): Promise<string> {
const enc = new TextEncoder();
const keyMaterial = await window.crypto.subtle.importKey(
'raw',
enc.encode(password),
{ name: 'PBKDF2' },
false,
['deriveBits', 'deriveKey']
);
const salt = window.crypto.getRandomValues(new Uint8Array(16));
const key = await window.crypto.subtle.deriveKey(
{
name: 'PBKDF2',
salt: salt,
iterations: 100000,
hash: 'SHA-256'
},
keyMaterial,
{ name: 'AES-GCM', length: 256 },
false,
['encrypt']
);
const iv = window.crypto.getRandomValues(new Uint8Array(12));
const encryptedContent = await window.crypto.subtle.encrypt(
{
name: 'AES-GCM',
iv: iv
},
key,
enc.encode(content)
);
const combined = new Uint8Array(salt.byteLength + iv.byteLength + encryptedContent.byteLength);
combined.set(salt, 0);
combined.set(iv, salt.byteLength);
combined.set(new Uint8Array(encryptedContent), salt.byteLength + iv.byteLength);
const result = {
version: 1,
kdf: 'PBKDF2',
iterations: 100000,
hash: 'SHA-256',
algorithm: 'AES-GCM',
data: btoa(String.fromCharCode(...combined))
};
return JSON.stringify(result);
const enc = new TextEncoder();
const keyMaterial = await window.crypto.subtle.importKey(
'raw',
enc.encode(password),
{ name: 'PBKDF2' },
false,
['deriveBits', 'deriveKey']
);
const salt = window.crypto.getRandomValues(new Uint8Array(16));
const key = await window.crypto.subtle.deriveKey(
{
name: 'PBKDF2',
salt: salt,
iterations: 100000,
hash: 'SHA-256'
},
keyMaterial,
{ name: 'AES-GCM', length: 256 },
false,
['encrypt']
);
const iv = window.crypto.getRandomValues(new Uint8Array(12));
const encryptedContent = await window.crypto.subtle.encrypt(
{
name: 'AES-GCM',
iv: iv
},
key,
enc.encode(content)
);
const combined = new Uint8Array(salt.byteLength + iv.byteLength + encryptedContent.byteLength);
combined.set(salt, 0);
combined.set(iv, salt.byteLength);
combined.set(new Uint8Array(encryptedContent), salt.byteLength + iv.byteLength);
const result = {
version: 1,
kdf: 'PBKDF2',
iterations: 100000,
hash: 'SHA-256',
algorithm: 'AES-GCM',
data: btoa(String.fromCharCode(...combined))
};
return JSON.stringify(result);
}
export async function decryptAES(result: string, password: string): Promise<string | null> {
try {
const enc = new TextEncoder();
const parsed = JSON.parse(result);
const combined = Uint8Array.from(atob(parsed.data), c => c.charCodeAt(0));
const salt = combined.slice(0, 16);
const iv = combined.slice(16, 28);
const data = combined.slice(28);
const keyMaterial = await window.crypto.subtle.importKey(
'raw',
enc.encode(password),
{ name: 'PBKDF2' },
false,
['deriveBits', 'deriveKey']
);
const key = await window.crypto.subtle.deriveKey(
{
name: 'PBKDF2',
salt: salt,
iterations: parsed.iterations,
hash: parsed.hash
},
keyMaterial,
{ name: 'AES-GCM', length: 256 },
false,
['decrypt']
);
const decryptedContent = await window.crypto.subtle.decrypt(
{
name: 'AES-GCM',
iv: iv
},
key,
data
);
const dec = new TextDecoder();
return dec.decode(decryptedContent);
} catch {
return null;
}
try {
const enc = new TextEncoder();
const parsed = JSON.parse(result);
const combined = Uint8Array.from(atob(parsed.data), (c) => c.charCodeAt(0));
const salt = combined.slice(0, 16);
const iv = combined.slice(16, 28);
const data = combined.slice(28);
const keyMaterial = await window.crypto.subtle.importKey(
'raw',
enc.encode(password),
{ name: 'PBKDF2' },
false,
['deriveBits', 'deriveKey']
);
const key = await window.crypto.subtle.deriveKey(
{
name: 'PBKDF2',
salt: salt,
iterations: parsed.iterations,
hash: parsed.hash
},
keyMaterial,
{ name: 'AES-GCM', length: 256 },
false,
['decrypt']
);
const decryptedContent = await window.crypto.subtle.decrypt(
{
name: 'AES-GCM',
iv: iv
},
key,
data
);
const dec = new TextDecoder();
return dec.decode(decryptedContent);
} catch {
return null;
}
}
+10 -6
View File
@@ -38,10 +38,12 @@
{ value: 315360000000, label: 'Expire in 10 Years' }
];
const visibilityOptions = data.options.visibilities.map((visibility: { value: number; displayName: string }) => ({
value: visibility.value,
label: visibility.displayName
}));
const visibilityOptions = data.options.visibilities.map(
(visibility: { value: number; displayName: string }) => ({
value: visibility.value,
label: visibility.displayName
})
);
async function handleSubmit(event: Event) {
event.preventDefault();
@@ -91,7 +93,7 @@
<main
class="flex min-h-screen w-full flex-col items-center justify-center bg-neutral-950 text-white"
>
<div class="w-[95%] max-w-5xl rounded border-2 border-neutral-800 bg-neutral-900 p-6">
<div class="w-[95%] max-w-7xl rounded border-2 border-neutral-800 bg-neutral-900 p-6">
<h1 class="mb-6 text-center text-4xl font-bold">Create a Paste</h1>
<form class="mt-4" on:submit|preventDefault={handleSubmit}>
<input
@@ -109,7 +111,9 @@
spellcheck="false"
autocomplete="off"
bind:value={content}
maxlength={data.options.maxContentSize ? Math.floor(data.options.maxContentSize / 4) : undefined}
maxlength={data.options.maxContentSize
? Math.floor(data.options.maxContentSize / 4)
: undefined}
></textarea>
<Dropdown
options={syntaxOptions}
-1
View File
@@ -1,7 +1,6 @@
@import 'tailwindcss';
@import 'highlight.js/styles/github-dark.css';
* {
box-sizing: border-box;
}
@@ -3,14 +3,14 @@ import { getServerToken } from '$lib/utils/auth';
import type { User } from '$lib/types/user';
export const load: PageServerLoad = async ({ params, fetch, cookies }) => {
const { username } = params;
const token = getServerToken(cookies);
const res = await fetch(`/api/user/${username}`, {
headers: {
Authorization: token ? `Bearer ${token}` : ''
}
});
const { username } = params;
const token = getServerToken(cookies);
const res = await fetch(`/api/user/${username}`, {
headers: {
Authorization: token ? `Bearer ${token}` : ''
}
});
const user = await res.json() as User;
return { user };
}
const user = (await res.json()) as User;
return { user };
};