mirror of
https://github.com/whoswhip/Sharpbin.git
synced 2026-12-05 18:48:41 +00:00
refactor: migrate to props and runes
this was done using sv migrate and a bit of ai to fully migrate
This commit is contained in:
@@ -4,28 +4,41 @@
|
||||
label: string;
|
||||
}
|
||||
|
||||
export let options: Option[] = [];
|
||||
export let value: string | number = '';
|
||||
export let placeholder = 'Select...';
|
||||
export let searchable = false;
|
||||
export let displayValue: (val: string | number) => string = (val) => {
|
||||
return options.find((o) => o.value === val)?.label ?? String(val);
|
||||
};
|
||||
export let variant: string = '';
|
||||
interface Props {
|
||||
options?: Option[];
|
||||
value?: string | number;
|
||||
placeholder?: string;
|
||||
searchable?: boolean;
|
||||
displayValue?: (val: string | number) => string;
|
||||
variant?: string;
|
||||
}
|
||||
|
||||
let isOpen = false;
|
||||
let searchQuery = '';
|
||||
let dropdownElement: HTMLDivElement;
|
||||
let dropdownListElement: HTMLDivElement;
|
||||
let dropdownMaxHeight = '12rem';
|
||||
let {
|
||||
options = [],
|
||||
value = $bindable(''),
|
||||
placeholder = 'Select...',
|
||||
searchable = false,
|
||||
displayValue = (val) => {
|
||||
return options.find((o) => o.value === val)?.label ?? String(val);
|
||||
},
|
||||
variant = ''
|
||||
}: Props = $props();
|
||||
|
||||
$: filteredOptions = searchable
|
||||
? options.filter(
|
||||
(opt) =>
|
||||
opt.label.toLowerCase().includes(searchQuery.toLowerCase()) ||
|
||||
String(opt.value).toLowerCase().includes(searchQuery.toLowerCase())
|
||||
)
|
||||
: options;
|
||||
let isOpen = $state(false);
|
||||
let searchQuery = $state('');
|
||||
let dropdownElement = $state<HTMLDivElement | undefined>(undefined);
|
||||
let dropdownListElement = $state<HTMLDivElement | undefined>(undefined);
|
||||
let dropdownMaxHeight = $state('12rem');
|
||||
|
||||
let filteredOptions = $derived(
|
||||
searchable
|
||||
? options.filter(
|
||||
(opt) =>
|
||||
opt.label.toLowerCase().includes(searchQuery.toLowerCase()) ||
|
||||
String(opt.value).toLowerCase().includes(searchQuery.toLowerCase())
|
||||
)
|
||||
: options
|
||||
);
|
||||
|
||||
function handleSelect(selectedValue: string | number) {
|
||||
value = selectedValue;
|
||||
@@ -64,12 +77,12 @@
|
||||
}
|
||||
</script>
|
||||
|
||||
<svelte:window on:click={handleClickOutside} />
|
||||
<svelte:window onclick={handleClickOutside} />
|
||||
|
||||
<div bind:this={dropdownElement} class="relative mb-2 w-full" class:dropdown-sm={variant === 'sm'}>
|
||||
<button
|
||||
type="button"
|
||||
on:click={toggleDropdown}
|
||||
onclick={toggleDropdown}
|
||||
class="w-full rounded border border-neutral-700 bg-neutral-800 p-2 text-left transition-colors hover:bg-neutral-700"
|
||||
class:dropdown-sm-btn={variant === 'sm'}
|
||||
>
|
||||
@@ -91,7 +104,7 @@
|
||||
class="w-full border-b border-neutral-700 bg-neutral-800 p-2 outline-none"
|
||||
class:dropdown-sm-input={variant === 'sm'}
|
||||
bind:value={searchQuery}
|
||||
on:keydown={handleKeyDown}
|
||||
onkeydown={handleKeyDown}
|
||||
/>
|
||||
</div>
|
||||
{/if}
|
||||
@@ -102,7 +115,7 @@
|
||||
{#each filteredOptions as option (option.value)}
|
||||
<button
|
||||
type="button"
|
||||
on:click={() => handleSelect(option.value)}
|
||||
onclick={() => handleSelect(option.value)}
|
||||
class="w-full border-b border-neutral-700 px-3 py-2 text-left last:border-b-0 hover:bg-neutral-600"
|
||||
class:bg-neutral-700={value === option.value}
|
||||
class:dropdown-sm-option={variant === 'sm'}
|
||||
|
||||
@@ -5,46 +5,68 @@
|
||||
import { tick } from 'svelte';
|
||||
import { extractError } from '$lib/utils/misc';
|
||||
|
||||
export let show = false;
|
||||
export let mode:
|
||||
| 'decrypt'
|
||||
| 'encrypt'
|
||||
| 'confirm'
|
||||
| 'prompt'
|
||||
| 'multiselect'
|
||||
| 'totp'
|
||||
| 'totpSetup'
|
||||
| 'report' = 'decrypt';
|
||||
export let title = '';
|
||||
export let message = '';
|
||||
export let error = '';
|
||||
export let placeholder = '';
|
||||
export let inputType = 'text';
|
||||
export let inputMaxLength: number | null = null;
|
||||
export let items: { label: string; value: unknown }[] = [];
|
||||
export let initialValue: unknown = null;
|
||||
export let totpActive: boolean | null = null;
|
||||
export let reportTarget: 'user' | 'paste' | null = null;
|
||||
export let reportTargetId: string | number | null = null;
|
||||
export let reportSiteKey: string | null = null;
|
||||
export let onConfirm: (value: unknown) => void;
|
||||
export let onCancel: () => void;
|
||||
export let confirmButtonText = '';
|
||||
interface Props {
|
||||
show?: boolean;
|
||||
mode?:
|
||||
| 'decrypt'
|
||||
| 'encrypt'
|
||||
| 'confirm'
|
||||
| 'prompt'
|
||||
| 'multiselect'
|
||||
| 'totp'
|
||||
| 'totpSetup'
|
||||
| 'report';
|
||||
title?: string;
|
||||
message?: string;
|
||||
error?: string;
|
||||
placeholder?: string;
|
||||
inputType?: string;
|
||||
inputMaxLength?: number | null;
|
||||
items?: { label: string; value: unknown }[];
|
||||
initialValue?: unknown;
|
||||
totpActive?: boolean | null;
|
||||
reportTarget?: 'user' | 'paste' | null;
|
||||
reportTargetId?: string | number | null;
|
||||
reportSiteKey?: string | null;
|
||||
onConfirm: (value: unknown) => void;
|
||||
onCancel: () => void;
|
||||
confirmButtonText?: string;
|
||||
}
|
||||
|
||||
let inputValue: string | unknown[] | boolean = '';
|
||||
let totpSecret = '';
|
||||
let totpQr = '';
|
||||
let totpEnabled = false;
|
||||
let totpInitialized = false;
|
||||
let totpLoading = false;
|
||||
let totpError = '';
|
||||
let displayError = '';
|
||||
let reportTypes: string[] = [];
|
||||
let reportType = '';
|
||||
let reportInitialized = false;
|
||||
let reportLoading = false;
|
||||
let multiselectInitialized = false;
|
||||
let turnstileEl: HTMLDivElement | null = null;
|
||||
let {
|
||||
show = false,
|
||||
mode = 'decrypt',
|
||||
title = '',
|
||||
message = '',
|
||||
error = $bindable(''),
|
||||
placeholder = '',
|
||||
inputType = 'text',
|
||||
inputMaxLength = null,
|
||||
items = [],
|
||||
initialValue = null,
|
||||
totpActive = null,
|
||||
reportTarget = null,
|
||||
reportTargetId = null,
|
||||
reportSiteKey = null,
|
||||
onConfirm,
|
||||
onCancel,
|
||||
confirmButtonText = ''
|
||||
}: Props = $props();
|
||||
|
||||
let inputValue: string | unknown[] | boolean = $state('');
|
||||
let totpSecret = $state('');
|
||||
let totpQr = $state('');
|
||||
let totpEnabled = $state(false);
|
||||
let totpInitialized = $state(false);
|
||||
let totpLoading = $state(false);
|
||||
let totpError = $state('');
|
||||
let displayError = $derived(error || totpError);
|
||||
let reportTypes: string[] = $state([]);
|
||||
let reportType = $state('');
|
||||
let reportInitialized = $state(false);
|
||||
let reportLoading = $state(false);
|
||||
let multiselectInitialized = $state(false);
|
||||
let turnstileEl: HTMLDivElement | null = $state(null);
|
||||
let turnstileWidgetId: string | null = null;
|
||||
|
||||
const titleMap = {
|
||||
@@ -63,34 +85,12 @@
|
||||
encrypt: 'Encrypt',
|
||||
confirm: 'Confirm',
|
||||
multiselect: 'Confirm',
|
||||
totpSetup: totpEnabled ? 'Disable' : 'Enable',
|
||||
totpSetup: 'Enable',
|
||||
totp: 'Verify',
|
||||
report: 'Submit Report',
|
||||
prompt: 'Submit'
|
||||
};
|
||||
|
||||
$: displayError = error || totpError;
|
||||
|
||||
$: if (!show) resetModal();
|
||||
|
||||
$: if (show && mode === 'totpSetup' && !totpInitialized) {
|
||||
totpInitialized = true;
|
||||
if (totpActive !== null) {
|
||||
totpEnabled = totpActive;
|
||||
}
|
||||
initializeTotp();
|
||||
}
|
||||
|
||||
$: if (show && mode === 'report' && !reportInitialized) {
|
||||
reportInitialized = true;
|
||||
initializeReport();
|
||||
}
|
||||
|
||||
$: if (show && mode === 'multiselect' && !multiselectInitialized) {
|
||||
multiselectInitialized = true;
|
||||
inputValue = Array.isArray(initialValue) ? JSON.parse(JSON.stringify(initialValue)) : [];
|
||||
}
|
||||
|
||||
function resetModal() {
|
||||
inputValue =
|
||||
initialValue !== null
|
||||
@@ -212,7 +212,8 @@
|
||||
return null;
|
||||
}
|
||||
|
||||
async function handleSubmit() {
|
||||
async function handleSubmit(event: Event) {
|
||||
event.preventDefault();
|
||||
if (mode === 'report') {
|
||||
await submitReport();
|
||||
return;
|
||||
@@ -394,17 +395,44 @@
|
||||
}
|
||||
}
|
||||
|
||||
$: displayTitle = title || titleMap[mode];
|
||||
|
||||
$: confirmLabel = confirmButtonText || confirmLabelMap[mode];
|
||||
$: shouldShowInput =
|
||||
mode !== 'confirm' && mode !== 'multiselect' && mode !== 'totpSetup' && mode !== 'report';
|
||||
$effect(() => {
|
||||
if (!show) resetModal();
|
||||
});
|
||||
$effect(() => {
|
||||
if (show && mode === 'totpSetup' && !totpInitialized) {
|
||||
totpInitialized = true;
|
||||
if (totpActive !== null) {
|
||||
totpEnabled = totpActive;
|
||||
}
|
||||
initializeTotp();
|
||||
}
|
||||
});
|
||||
$effect(() => {
|
||||
if (show && mode === 'report' && !reportInitialized) {
|
||||
reportInitialized = true;
|
||||
initializeReport();
|
||||
}
|
||||
});
|
||||
$effect(() => {
|
||||
if (show && mode === 'multiselect' && !multiselectInitialized) {
|
||||
multiselectInitialized = true;
|
||||
inputValue = Array.isArray(initialValue) ? JSON.parse(JSON.stringify(initialValue)) : [];
|
||||
}
|
||||
});
|
||||
let displayTitle = $derived(title || titleMap[mode]);
|
||||
let confirmLabel = $derived(
|
||||
confirmButtonText ||
|
||||
(mode === 'totpSetup' ? (totpEnabled ? 'Disable' : 'Enable') : confirmLabelMap[mode])
|
||||
);
|
||||
let shouldShowInput = $derived(
|
||||
mode !== 'confirm' && mode !== 'multiselect' && mode !== 'totpSetup' && mode !== 'report'
|
||||
);
|
||||
</script>
|
||||
|
||||
{#if show}
|
||||
<div class="fixed inset-0 z-50 flex items-center justify-center bg-black/20 backdrop-blur-xs">
|
||||
<form
|
||||
on:submit|preventDefault={handleSubmit}
|
||||
onsubmit={handleSubmit}
|
||||
class="w-full max-w-md rounded border border-neutral-800 bg-neutral-900 p-6"
|
||||
>
|
||||
<h2 class="mb-4 text-xl font-semibold text-white">
|
||||
@@ -448,7 +476,7 @@
|
||||
>
|
||||
<button
|
||||
type="button"
|
||||
on:click={copySecret}
|
||||
onclick={copySecret}
|
||||
class="rounded bg-neutral-700 px-3 py-1 text-sm font-medium text-white transition-colors hover:bg-neutral-800"
|
||||
>
|
||||
Copy
|
||||
@@ -463,7 +491,7 @@
|
||||
maxlength="6"
|
||||
inputmode="numeric"
|
||||
pattern="[0-9]*"
|
||||
on:input={onCodeInput}
|
||||
oninput={onCodeInput}
|
||||
class="w-full rounded border border-neutral-700 bg-neutral-800 p-2 text-white outline-none"
|
||||
/>
|
||||
{/if}
|
||||
@@ -543,7 +571,7 @@
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
on:click={onCancel}
|
||||
onclick={onCancel}
|
||||
class="cursor-pointer rounded border border-neutral-700 px-4 py-2 text-white hover:bg-neutral-950"
|
||||
>
|
||||
Cancel
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
import Modal from '$lib/components/Modal.svelte';
|
||||
import { cancelModal, confirmModal, modal } from '$lib/stores/modal';
|
||||
|
||||
$: state = $modal;
|
||||
let state = $derived($modal);
|
||||
</script>
|
||||
|
||||
<Modal
|
||||
|
||||
@@ -15,9 +15,13 @@
|
||||
window.location.href = '/';
|
||||
}
|
||||
|
||||
export let data: PageData;
|
||||
interface Props {
|
||||
data: PageData;
|
||||
}
|
||||
|
||||
let menuOpen = false;
|
||||
let { data }: Props = $props();
|
||||
|
||||
let menuOpen = $state(false);
|
||||
|
||||
let currentPath = page.url.pathname;
|
||||
let returnParam =
|
||||
@@ -73,7 +77,7 @@
|
||||
>Profile</a
|
||||
>
|
||||
<button
|
||||
on:click={logout}
|
||||
onclick={logout}
|
||||
class="cursor-pointer rounded bg-neutral-700 px-3 py-1 text-white transition-colors hover:bg-neutral-600"
|
||||
>Logout</button
|
||||
>
|
||||
@@ -104,7 +108,7 @@
|
||||
</a>
|
||||
<button
|
||||
class="ml-auto flex h-10 w-10 items-center justify-center rounded border border-neutral-700 bg-neutral-800 p-2 hover:bg-neutral-700 focus:outline-none"
|
||||
on:click={() => (menuOpen = !menuOpen)}
|
||||
onclick={() => (menuOpen = !menuOpen)}
|
||||
aria-label="Toggle Menu"
|
||||
aria-expanded={menuOpen}
|
||||
>
|
||||
@@ -126,23 +130,23 @@
|
||||
<a
|
||||
href={resolve('/recent')}
|
||||
class="block w-full rounded bg-neutral-800 px-3 py-2 text-center text-neutral-100 transition-colors hover:bg-neutral-700"
|
||||
on:click={() => (menuOpen = false)}>Recent Pastes</a
|
||||
onclick={() => (menuOpen = false)}>Recent Pastes</a
|
||||
>
|
||||
{#if $user}
|
||||
{#if hasRole($user.roles, 2) || hasRole($user.roles, 4)}
|
||||
<a
|
||||
href={resolve('/reports')}
|
||||
class="mt-1 block w-full rounded bg-neutral-800 px-3 py-2 text-center text-neutral-100 transition-colors hover:bg-neutral-700"
|
||||
on:click={() => (menuOpen = false)}>Reports</a
|
||||
onclick={() => (menuOpen = false)}>Reports</a
|
||||
>
|
||||
{/if}
|
||||
<a
|
||||
href={resolve(`/user/${$user.username}`)}
|
||||
class="mt-1 block w-full rounded bg-neutral-800 px-3 py-2 text-center text-neutral-100 transition-colors hover:bg-neutral-700"
|
||||
on:click={() => (menuOpen = false)}>Profile</a
|
||||
onclick={() => (menuOpen = false)}>Profile</a
|
||||
>
|
||||
<button
|
||||
on:click={() => {
|
||||
onclick={() => {
|
||||
logout();
|
||||
menuOpen = false;
|
||||
}}
|
||||
@@ -153,7 +157,7 @@
|
||||
<a
|
||||
href={resolve(`/login${returnParam}`)}
|
||||
class="mt-1 block w-full rounded bg-neutral-800 px-3 py-2 text-center text-neutral-100 transition-colors hover:bg-neutral-700"
|
||||
on:click={() => (menuOpen = false)}>Login</a
|
||||
onclick={() => (menuOpen = false)}>Login</a
|
||||
>
|
||||
<!-- eslint-disable svelte/no-navigation-without-resolve -->
|
||||
<a
|
||||
@@ -162,7 +166,7 @@
|
||||
.options?.registration_enabled
|
||||
? ''
|
||||
: 'cursor-not-allowed bg-neutral-900 text-neutral-500'}"
|
||||
on:click={() => (menuOpen = false)}>Register</a
|
||||
onclick={() => (menuOpen = false)}>Register</a
|
||||
>
|
||||
<!-- eslint-enable svelte/no-navigation-without-resolve -->
|
||||
{/if}
|
||||
|
||||
@@ -17,12 +17,16 @@
|
||||
import { syntaxes } from '$lib/consts';
|
||||
import type { Paste } from '$lib/types/paste';
|
||||
|
||||
export let paste: Paste;
|
||||
export let now: Date;
|
||||
export let showUser: boolean = true;
|
||||
export let compact: boolean = false;
|
||||
interface Props {
|
||||
paste: Paste;
|
||||
now: Date;
|
||||
showUser?: boolean;
|
||||
compact?: boolean;
|
||||
}
|
||||
|
||||
const syntax = syntaxes[paste.syntax] ?? syntaxes['plaintext'];
|
||||
let { paste, now, showUser = true, compact = false }: Props = $props();
|
||||
|
||||
let syntax = $derived(syntaxes[paste.syntax] ?? syntaxes['plaintext']);
|
||||
</script>
|
||||
|
||||
{#if compact}
|
||||
|
||||
@@ -10,11 +10,15 @@
|
||||
import User from '@lucide/svelte/icons/user';
|
||||
import type { PasteEmbedProps } from './pasteEmbed';
|
||||
|
||||
export let title: PasteEmbedProps['title'];
|
||||
export let uploader: PasteEmbedProps['uploader'];
|
||||
export let metadata: PasteEmbedProps['metadata'];
|
||||
export let previewLines: PasteEmbedProps['previewLines'];
|
||||
export let isEncrypted: PasteEmbedProps['isEncrypted'];
|
||||
interface Props {
|
||||
title: PasteEmbedProps['title'];
|
||||
uploader: PasteEmbedProps['uploader'];
|
||||
metadata: PasteEmbedProps['metadata'];
|
||||
previewLines: PasteEmbedProps['previewLines'];
|
||||
isEncrypted: PasteEmbedProps['isEncrypted'];
|
||||
}
|
||||
|
||||
let { title, uploader, metadata, previewLines, isEncrypted }: Props = $props();
|
||||
|
||||
const metadataIcons = {
|
||||
size: FileBox,
|
||||
|
||||
@@ -69,7 +69,8 @@ function parseBooleanClaim(value: unknown) {
|
||||
}
|
||||
|
||||
function parseNumberClaim(value: unknown): number | null {
|
||||
const numeric = typeof value === 'number' ? value : typeof value === 'string' ? parseInt(value, 10) : NaN;
|
||||
const numeric =
|
||||
typeof value === 'number' ? value : typeof value === 'string' ? parseInt(value, 10) : NaN;
|
||||
return Number.isFinite(numeric) ? numeric : null;
|
||||
}
|
||||
|
||||
|
||||
@@ -11,7 +11,12 @@
|
||||
import { page } from '$app/state';
|
||||
import type { LayoutData } from './$types';
|
||||
|
||||
export let data: LayoutData;
|
||||
interface Props {
|
||||
data: LayoutData;
|
||||
children?: import('svelte').Snippet;
|
||||
}
|
||||
|
||||
let { data, children }: Props = $props();
|
||||
|
||||
async function syncUserFromToken() {
|
||||
const token = getToken();
|
||||
@@ -103,7 +108,7 @@
|
||||
</svelte:head>
|
||||
|
||||
<Navbar {data} />
|
||||
<slot />
|
||||
{@render children?.()}
|
||||
<Footer />
|
||||
|
||||
<ModalHost />
|
||||
|
||||
@@ -18,37 +18,47 @@
|
||||
import { SvelteURLSearchParams } from 'svelte/reactivity';
|
||||
import { FileUp, X, Eye, EyeClosed, Dices } from '@lucide/svelte';
|
||||
|
||||
export let data: PageData;
|
||||
interface Props {
|
||||
data: PageData;
|
||||
}
|
||||
|
||||
let textArea: HTMLTextAreaElement;
|
||||
let markdownConatiner: HTMLDivElement;
|
||||
let { data }: Props = $props();
|
||||
|
||||
let error = '';
|
||||
let title = '';
|
||||
let content = '';
|
||||
let selectedSyntax = data.options?.syntaxes?.[0];
|
||||
let expiresIn: number = 0;
|
||||
let selectedVisibility = data.options?.visibilities?.[0]?.value;
|
||||
let password = '';
|
||||
let passwordVisible = false;
|
||||
let anonymousUpload = false;
|
||||
let isDragging = false;
|
||||
let dragError = '';
|
||||
let previewMode = false;
|
||||
let renderedMarkdown = '';
|
||||
let textArea = $state<HTMLTextAreaElement | undefined>(undefined);
|
||||
let markdownConatiner = $state<HTMLDivElement | undefined>(undefined);
|
||||
|
||||
$: currentByteSize =
|
||||
const getInitialSyntax = () => data.options?.syntaxes?.[0] ?? 'plaintext';
|
||||
const getInitialVisibility = () => data.options?.visibilities?.[0]?.value ?? 0;
|
||||
|
||||
let error = $state('');
|
||||
let title = $state('');
|
||||
let content = $state('');
|
||||
let selectedSyntax = $state(getInitialSyntax());
|
||||
let expiresIn: number = $state(0);
|
||||
let selectedVisibility = $state(getInitialVisibility());
|
||||
let password = $state('');
|
||||
let passwordVisible = $state(false);
|
||||
let anonymousUpload = $state(false);
|
||||
let isDragging = $state(false);
|
||||
let dragError = $state('');
|
||||
let previewMode = $state(false);
|
||||
let renderedMarkdown = $state('');
|
||||
|
||||
let currentByteSize = $derived(
|
||||
selectedVisibility === 2
|
||||
? estimateEncryptedSize(content)
|
||||
: new TextEncoder().encode(content).length;
|
||||
: new TextEncoder().encode(content).length
|
||||
);
|
||||
|
||||
$: if (selectedSyntax !== 'markdown') {
|
||||
previewMode = false;
|
||||
}
|
||||
$effect(() => {
|
||||
if (selectedSyntax !== 'markdown') {
|
||||
previewMode = false;
|
||||
}
|
||||
});
|
||||
|
||||
const MAX_HEIGHT = () => Math.floor((window.innerHeight - 120) * 0.6);
|
||||
|
||||
let previewHeight = 'auto';
|
||||
let previewHeight = $state('auto');
|
||||
async function togglePreview(toPreview: boolean) {
|
||||
if (toPreview && !previewMode) {
|
||||
previewHeight = textArea?.style.height || 'auto';
|
||||
@@ -59,11 +69,11 @@
|
||||
}
|
||||
|
||||
function resize(markdown: boolean = false) {
|
||||
if ((!markdown && !textArea) || (markdown && !markdownConatiner)) return;
|
||||
const element = markdown ? markdownConatiner : textArea;
|
||||
if (!element) return;
|
||||
|
||||
let h: number;
|
||||
let max: number;
|
||||
let element = markdown ? markdownConatiner : textArea;
|
||||
|
||||
element.style.height = 'auto';
|
||||
h = element.scrollHeight;
|
||||
@@ -106,17 +116,21 @@
|
||||
};
|
||||
});
|
||||
|
||||
const syntaxOptions =
|
||||
data.options?.syntaxes?.map((lang: string) => ({
|
||||
value: lang,
|
||||
label: syntaxes[lang]?.name ?? lang.charAt(0).toUpperCase() + lang.slice(1)
|
||||
})) ?? [];
|
||||
let syntaxOptions = $derived.by(
|
||||
() =>
|
||||
data.options?.syntaxes?.map((lang: string) => ({
|
||||
value: lang,
|
||||
label: syntaxes[lang]?.name ?? lang.charAt(0).toUpperCase() + lang.slice(1)
|
||||
})) ?? []
|
||||
);
|
||||
|
||||
const visibilityOptions =
|
||||
data.options?.visibilities?.map((visibility: { value: number; displayName: string }) => ({
|
||||
value: visibility.value,
|
||||
label: visibility.displayName
|
||||
})) ?? [];
|
||||
let visibilityOptions = $derived.by(
|
||||
() =>
|
||||
data.options?.visibilities?.map((visibility: { value: number; displayName: string }) => ({
|
||||
value: visibility.value,
|
||||
label: visibility.displayName
|
||||
})) ?? []
|
||||
);
|
||||
|
||||
async function handleSubmit(event: Event) {
|
||||
event.preventDefault();
|
||||
@@ -244,7 +258,7 @@
|
||||
>
|
||||
<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}>
|
||||
<form class="mt-4" onsubmit={handleSubmit}>
|
||||
<input
|
||||
type="text"
|
||||
placeholder="Title (optional)"
|
||||
@@ -274,10 +288,10 @@
|
||||
minlength="1"
|
||||
bind:this={textArea}
|
||||
bind:value={content}
|
||||
on:input={() => resize()}
|
||||
on:change={() => resize()}
|
||||
on:focus={() => resize()}
|
||||
on:beforeinput={(e) => {
|
||||
oninput={() => resize()}
|
||||
onchange={() => resize()}
|
||||
onfocus={() => resize()}
|
||||
onbeforeinput={(e) => {
|
||||
if (!data.options?.maxPasteSize) return;
|
||||
|
||||
const futureSize =
|
||||
@@ -292,19 +306,19 @@
|
||||
e.preventDefault();
|
||||
}
|
||||
}}
|
||||
on:dragenter={(e) => {
|
||||
ondragenter={(e) => {
|
||||
e.preventDefault();
|
||||
isDragging = true;
|
||||
}}
|
||||
on:dragover={(e) => {
|
||||
ondragover={(e) => {
|
||||
e.preventDefault();
|
||||
isDragging = true;
|
||||
}}
|
||||
on:dragleave={(e) => {
|
||||
ondragleave={(e) => {
|
||||
e.preventDefault();
|
||||
isDragging = false;
|
||||
}}
|
||||
on:drop={(e) => {
|
||||
ondrop={(e) => {
|
||||
requestAnimationFrame(() => resize());
|
||||
e.preventDefault();
|
||||
isDragging = false;
|
||||
@@ -376,7 +390,7 @@
|
||||
class="h-full w-1/2 rounded-l transition-colors {previewMode
|
||||
? 'hover:bg-neutral-700'
|
||||
: 'bg-neutral-700 text-white'}"
|
||||
on:click={() => togglePreview(false)}
|
||||
onclick={() => togglePreview(false)}
|
||||
>
|
||||
Code
|
||||
</button>
|
||||
@@ -385,7 +399,7 @@
|
||||
class="h-full w-1/2 rounded-r transition-colors {!previewMode
|
||||
? 'hover:bg-neutral-700'
|
||||
: 'bg-neutral-700 text-white'}"
|
||||
on:click={() => togglePreview(true)}
|
||||
onclick={() => togglePreview(true)}
|
||||
>
|
||||
Preview
|
||||
</button>
|
||||
@@ -449,7 +463,7 @@
|
||||
<button
|
||||
type="button"
|
||||
class="mr-1 ml-1 flex w-12.5 items-center justify-center border border-neutral-700 bg-neutral-800 p-2 text-neutral-400 hover:bg-neutral-700 active:bg-neutral-600"
|
||||
on:click={() => {
|
||||
onclick={() => {
|
||||
const chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
|
||||
const bytes = new Uint8Array(16);
|
||||
crypto.getRandomValues(bytes);
|
||||
@@ -462,7 +476,7 @@
|
||||
<button
|
||||
type="button"
|
||||
class="flex w-12.5 items-center justify-center rounded-r border border-neutral-700 bg-neutral-800 p-2 text-neutral-400 hover:bg-neutral-700 active:bg-neutral-600"
|
||||
on:click={() => (passwordVisible = !passwordVisible)}
|
||||
onclick={() => (passwordVisible = !passwordVisible)}
|
||||
>
|
||||
{#if passwordVisible}
|
||||
<EyeClosed class="h-5 w-5" />
|
||||
|
||||
@@ -49,33 +49,41 @@
|
||||
import { openModal } from '$lib/stores/modal';
|
||||
import type { Paste } from '$lib/types/paste';
|
||||
import HighlightWorker from '$lib/workers/highlight.worker?worker';
|
||||
export let data: PageData;
|
||||
interface Props {
|
||||
data: PageData;
|
||||
}
|
||||
|
||||
let reportSiteKey: string | null = null;
|
||||
let editing = false;
|
||||
let editContent: string | null = null;
|
||||
let editMetadata: Paste | null = data.paste ? { ...data.paste } : null;
|
||||
let editError = '';
|
||||
let editLoading = false;
|
||||
let isBinary = false;
|
||||
let pasteContent = '';
|
||||
let decryptedContent: string | null = null;
|
||||
let { data = $bindable() }: Props = $props();
|
||||
|
||||
let reportSiteKey = $derived(
|
||||
(data as unknown as { authOptions?: { cf_turnstile_site_key?: string | null } }).authOptions
|
||||
?.cf_turnstile_site_key ?? null
|
||||
);
|
||||
let editing = $state(false);
|
||||
let editContent: string | null = $state(null);
|
||||
let editMetadata: Paste | null = $state(data.paste ? { ...data.paste } : null);
|
||||
let editError = $state('');
|
||||
let editLoading = $state(false);
|
||||
let isBinary = $state(false);
|
||||
let pasteContent = $state('');
|
||||
let decryptedContent: string | null = $state(null);
|
||||
let decryptError = '';
|
||||
let decryptStatus = '';
|
||||
let contentRendered = false;
|
||||
let downloadedPaste = false;
|
||||
let copiedPaste = false;
|
||||
let decryptStatus = $state('');
|
||||
let contentRendered = $state(false);
|
||||
let downloadedPaste = $state(false);
|
||||
let copiedPaste = $state(false);
|
||||
let highlightWorker: Worker | null = null;
|
||||
let highlightRequestId = 0;
|
||||
let ignoreExternalMediaWarning = false;
|
||||
|
||||
let scrollY = 0;
|
||||
let scrollY = $state(0);
|
||||
|
||||
let now = new Date();
|
||||
$: isExpired =
|
||||
let now = $state(new Date());
|
||||
let isExpired = $derived(
|
||||
data?.paste?.expiresAt && data.paste.expiresAt !== 0
|
||||
? new Date(data.paste.expiresAt).getTime() <= now.getTime()
|
||||
: false;
|
||||
: false
|
||||
);
|
||||
|
||||
let interval: ReturnType<typeof setInterval> | null = null;
|
||||
|
||||
@@ -490,12 +498,12 @@
|
||||
}
|
||||
});
|
||||
|
||||
$: if (data?.paste && (data.paste.visibility !== 2 || decryptedContent !== null)) renderPaste();
|
||||
$: reportSiteKey =
|
||||
(data as unknown as { authOptions?: { cf_turnstile_site_key?: string | null } }).authOptions
|
||||
?.cf_turnstile_site_key ?? null;
|
||||
$: pasteImageUrl =
|
||||
data?.paste && data?.url ? `${new URL(data.url).origin}/${data.paste.id}.jpg` : null;
|
||||
$effect(() => {
|
||||
if (data?.paste && (data.paste.visibility !== 2 || decryptedContent !== null)) renderPaste();
|
||||
});
|
||||
let pasteImageUrl = $derived(
|
||||
data?.paste && data?.url ? `${new URL(data.url).origin}/${data.paste.id}.jpg` : null
|
||||
);
|
||||
</script>
|
||||
|
||||
<svelte:window bind:scrollY />
|
||||
@@ -750,7 +758,7 @@
|
||||
<button
|
||||
type="button"
|
||||
class="flex cursor-pointer items-center rounded-md bg-neutral-700 px-2 py-0.5 text-sm hover:bg-neutral-600"
|
||||
on:click={() => {
|
||||
onclick={() => {
|
||||
navigator.clipboard.writeText(decryptedContent ?? data.content);
|
||||
copiedPaste = true;
|
||||
setTimeout(() => (copiedPaste = false), 1000);
|
||||
@@ -778,7 +786,7 @@
|
||||
<button
|
||||
type="button"
|
||||
class="flex cursor-pointer items-center rounded-md bg-neutral-700 px-2 py-0.5 text-sm hover:bg-neutral-600"
|
||||
on:click={() => {
|
||||
onclick={() => {
|
||||
const blob = new Blob([decryptedContent ?? data.content], {
|
||||
type: 'text/plain'
|
||||
});
|
||||
@@ -839,7 +847,7 @@
|
||||
<button
|
||||
type="button"
|
||||
class="flex cursor-pointer items-center rounded-md bg-neutral-700 px-2 py-0.5 text-sm hover:bg-amber-600/50"
|
||||
on:click={() => {
|
||||
onclick={() => {
|
||||
promptUser('report');
|
||||
}}
|
||||
>
|
||||
@@ -853,7 +861,7 @@
|
||||
<button
|
||||
type="button"
|
||||
class="flex cursor-pointer items-center rounded-md bg-neutral-700 px-2 py-0.5 text-sm hover:bg-neutral-600"
|
||||
on:click={() => {
|
||||
onclick={() => {
|
||||
editContent = decryptedContent ?? data.content;
|
||||
editError = '';
|
||||
editing = true;
|
||||
@@ -866,7 +874,7 @@
|
||||
<button
|
||||
type="button"
|
||||
class="flex cursor-pointer items-center rounded-md bg-neutral-700 px-2 py-0.5 text-sm hover:bg-red-900"
|
||||
on:click={() => {
|
||||
onclick={() => {
|
||||
promptUser('confirm').then(async (value) => {
|
||||
if (value) {
|
||||
const token = getToken();
|
||||
@@ -895,7 +903,7 @@
|
||||
<button
|
||||
type="button"
|
||||
class="flex cursor-pointer items-center rounded-md bg-neutral-700 px-2 py-0.5 text-sm hover:bg-neutral-600"
|
||||
on:click={async () => {
|
||||
onclick={async () => {
|
||||
if (editContent !== null || editMetadata !== null) {
|
||||
await updatePaste(editContent, editMetadata);
|
||||
}
|
||||
@@ -908,7 +916,7 @@
|
||||
<button
|
||||
type="button"
|
||||
class="flex cursor-pointer items-center rounded-md bg-neutral-700 px-2 py-0.5 text-sm hover:bg-neutral-600"
|
||||
on:click={() => {
|
||||
onclick={() => {
|
||||
editing = false;
|
||||
editError = '';
|
||||
}}
|
||||
@@ -922,7 +930,7 @@
|
||||
<button
|
||||
transition:fade={{ duration: 200 }}
|
||||
class="flex cursor-pointer items-center rounded-md bg-neutral-700 px-2 py-0.5 text-sm hover:bg-neutral-600"
|
||||
on:click={() => window.scrollTo({ top: 0, behavior: 'smooth' })}
|
||||
onclick={() => window.scrollTo({ top: 0, behavior: 'smooth' })}
|
||||
aria-label="Scroll to top"
|
||||
>
|
||||
<ArrowUp class="mr-1 h-5 w-5 text-neutral-400" />
|
||||
@@ -963,7 +971,7 @@
|
||||
? 'csv-container scrollbar overflow-x-auto overflow-y-auto scrollbar-thumb-neutral-600 scrollbar-track-neutral-800'
|
||||
: 'codeblock-with-lines overflow-x-auto overflow-y-auto'}
|
||||
class:hidden={!contentRendered}
|
||||
on:click={handleMarkdownClick}
|
||||
onclick={handleMarkdownClick}
|
||||
role="presentation"
|
||||
>
|
||||
<!-- eslint-disable-next-line svelte/no-at-html-tags -->
|
||||
|
||||
@@ -5,12 +5,16 @@
|
||||
import { onMount } from 'svelte';
|
||||
import type { PageData } from './$types';
|
||||
|
||||
let username = '';
|
||||
let password = '';
|
||||
let error = '';
|
||||
let totpEnabled = false;
|
||||
let totpCode = '';
|
||||
export let data: PageData;
|
||||
let username = $state('');
|
||||
let password = $state('');
|
||||
let error = $state('');
|
||||
let totpEnabled = $state(false);
|
||||
let totpCode = $state('');
|
||||
interface Props {
|
||||
data: PageData;
|
||||
}
|
||||
|
||||
let { data }: Props = $props();
|
||||
|
||||
onMount(() => {
|
||||
const render = () => {
|
||||
@@ -35,7 +39,8 @@
|
||||
};
|
||||
});
|
||||
|
||||
async function login() {
|
||||
async function login(event: Event) {
|
||||
event.preventDefault();
|
||||
const body: { username: string; password: string; token?: string; totpcode?: string } = {
|
||||
username,
|
||||
password
|
||||
@@ -96,7 +101,7 @@
|
||||
>
|
||||
<div class="w-full max-w-md rounded border-2 border-neutral-800 bg-neutral-900 p-6">
|
||||
<h1 class="mb-6 text-center text-3xl font-bold">Login</h1>
|
||||
<form on:submit|preventDefault={login} class="space-y-4">
|
||||
<form onsubmit={login} class="space-y-4">
|
||||
<input
|
||||
type="text"
|
||||
placeholder="Username"
|
||||
@@ -122,7 +127,7 @@
|
||||
inputmode="numeric"
|
||||
pattern="[0-9]*"
|
||||
required
|
||||
on:input={(e) => {
|
||||
oninput={(e) => {
|
||||
if (e.target instanceof HTMLInputElement) {
|
||||
e.target.value = e.target.value.replace(/\D/g, '').slice(0, 6);
|
||||
totpCode = e.target.value;
|
||||
|
||||
@@ -3,9 +3,13 @@
|
||||
import { onMount } from 'svelte';
|
||||
import Paste from '$lib/components/Paste.svelte';
|
||||
|
||||
export let data: PageData;
|
||||
interface Props {
|
||||
data: PageData;
|
||||
}
|
||||
|
||||
let now = new Date();
|
||||
let { data }: Props = $props();
|
||||
|
||||
let now = $state(new Date());
|
||||
|
||||
onMount(() => {
|
||||
const interval = setInterval(() => {
|
||||
|
||||
@@ -8,27 +8,31 @@
|
||||
import { onMount } from 'svelte';
|
||||
import type { PageData } from './$types';
|
||||
|
||||
let username = '';
|
||||
let password = '';
|
||||
let confirmPassword = '';
|
||||
let email = '';
|
||||
let displayName = '';
|
||||
let error = '';
|
||||
let username = $state('');
|
||||
let password = $state('');
|
||||
let confirmPassword = $state('');
|
||||
let email = $state('');
|
||||
let displayName = $state('');
|
||||
let error = $state('');
|
||||
|
||||
let passwordFocused = false;
|
||||
let showPassword = false;
|
||||
let passwordFocused = $state(false);
|
||||
let showPassword = $state(false);
|
||||
|
||||
let passwordChecks = {
|
||||
let passwordChecks = $state({
|
||||
minLength: false,
|
||||
maxLength: false,
|
||||
upper: false,
|
||||
lower: false,
|
||||
number: false
|
||||
};
|
||||
let passwordValid = false;
|
||||
let loading = false;
|
||||
});
|
||||
let passwordValid = $state(false);
|
||||
let loading = $state(false);
|
||||
|
||||
export let data: PageData;
|
||||
interface Props {
|
||||
data: PageData;
|
||||
}
|
||||
|
||||
let { data }: Props = $props();
|
||||
|
||||
onMount(() => {
|
||||
const render = () => {
|
||||
@@ -71,9 +75,12 @@
|
||||
passwordChecks.number;
|
||||
}
|
||||
|
||||
$: validatePassword(password);
|
||||
$effect(() => {
|
||||
validatePassword(password);
|
||||
});
|
||||
|
||||
async function register() {
|
||||
async function register(event: Event) {
|
||||
event.preventDefault();
|
||||
if (!passwordValid || password !== confirmPassword) return;
|
||||
loading = true;
|
||||
error = '';
|
||||
@@ -143,7 +150,7 @@
|
||||
Registration is currently disabled.
|
||||
</div>
|
||||
{/if}
|
||||
<form on:submit|preventDefault={register} class="space-y-4">
|
||||
<form onsubmit={register} class="space-y-4">
|
||||
<input
|
||||
type="text"
|
||||
placeholder="Username"
|
||||
@@ -179,15 +186,15 @@
|
||||
placeholder="Password"
|
||||
bind:value={password}
|
||||
required
|
||||
on:focus={() => (passwordFocused = true)}
|
||||
on:blur={() => (passwordFocused = false)}
|
||||
onfocus={() => (passwordFocused = true)}
|
||||
onblur={() => (passwordFocused = false)}
|
||||
autocomplete="new-password"
|
||||
disabled={loading || !data.options?.registration_enabled}
|
||||
class="focus:bg-neutral-750 w-[calc(100%-40px)] rounded-l border border-neutral-700 bg-neutral-800 p-2 placeholder-neutral-500 transition-colors duration-200 focus:border-neutral-600"
|
||||
/>
|
||||
<button
|
||||
type="button"
|
||||
on:click={() => (showPassword = !showPassword)}
|
||||
onclick={() => (showPassword = !showPassword)}
|
||||
disabled={loading || !data.options?.registration_enabled}
|
||||
class="ml-2 flex w-10 items-center rounded-r border border-neutral-700 bg-neutral-800 p-2 transition-colors duration-200 hover:bg-neutral-700 focus:outline-none"
|
||||
>
|
||||
|
||||
@@ -5,15 +5,20 @@
|
||||
import { tooltip } from '$lib/utils/misc';
|
||||
import { getToken } from '$lib/utils/auth';
|
||||
|
||||
export let data: PageData;
|
||||
interface Props {
|
||||
data: PageData;
|
||||
}
|
||||
|
||||
const report = data.report;
|
||||
let saving = false;
|
||||
let saveError = '';
|
||||
const statusOptions = data.options?.statuses ?? [];
|
||||
const typeOptions = data.options?.types ?? [];
|
||||
let statusValue = reportStatusLabels[report.status] ?? '';
|
||||
let typeValue = reportTypeLabels[report.type] ?? '';
|
||||
let { data }: Props = $props();
|
||||
const initialReport = () => ({ ...data.report });
|
||||
|
||||
let report = $state(initialReport());
|
||||
let saving = $state(false);
|
||||
let saveError = $state('');
|
||||
let statusOptions = $derived(data.options?.statuses ?? []);
|
||||
let typeOptions = $derived(data.options?.types ?? []);
|
||||
let statusValue = $state(reportStatusLabels[report.status] ?? '');
|
||||
let typeValue = $state(reportTypeLabels[report.type] ?? '');
|
||||
|
||||
async function updateReport() {
|
||||
saveError = '';
|
||||
@@ -143,7 +148,7 @@
|
||||
<div class="flex items-center gap-3">
|
||||
<button
|
||||
class="rounded bg-neutral-700 px-4 py-2 text-sm font-medium transition-colors hover:bg-neutral-600 disabled:opacity-60"
|
||||
on:click={updateReport}
|
||||
onclick={updateReport}
|
||||
disabled={saving}
|
||||
>
|
||||
{saving ? 'Saving...' : 'Update Report'}
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
<script lang="ts">
|
||||
import { createBubbler, stopPropagation } from 'svelte/legacy';
|
||||
|
||||
const bubble = createBubbler();
|
||||
import type { PageData } from './$types';
|
||||
import { resolve } from '$app/paths';
|
||||
import { goto } from '$app/navigation';
|
||||
@@ -6,14 +9,30 @@
|
||||
import { tooltip } from '$lib/utils/misc';
|
||||
import { SvelteURLSearchParams } from 'svelte/reactivity';
|
||||
|
||||
export let data: PageData;
|
||||
interface Props {
|
||||
data: PageData;
|
||||
}
|
||||
|
||||
let target = data.filters.target;
|
||||
let status = data.filters.status;
|
||||
let type = data.filters.type ?? '';
|
||||
let pasteId = data.filters.pasteId;
|
||||
let userUuid = data.filters.userUuid;
|
||||
let mixedTarget = target === 'all' ? pasteId || userUuid : '';
|
||||
let { data }: Props = $props();
|
||||
const initialFilters = (() => {
|
||||
const filters = data.filters;
|
||||
return {
|
||||
target: (filters.target as 'all' | 'pastes' | 'users') ?? 'all',
|
||||
status: filters.status ?? '',
|
||||
type: filters.type ?? '',
|
||||
pasteId: filters.pasteId ?? '',
|
||||
userUuid: filters.userUuid ?? ''
|
||||
};
|
||||
})();
|
||||
|
||||
let target = $state(initialFilters.target);
|
||||
let status = $state(initialFilters.status);
|
||||
let type = $state(initialFilters.type);
|
||||
let pasteId = $state(initialFilters.pasteId);
|
||||
let userUuid = $state(initialFilters.userUuid);
|
||||
let mixedTarget = $state(
|
||||
initialFilters.target === 'all' ? initialFilters.pasteId || initialFilters.userUuid : ''
|
||||
);
|
||||
let inputTimer: ReturnType<typeof setTimeout> | null = null;
|
||||
|
||||
const targets = [
|
||||
@@ -22,8 +41,8 @@
|
||||
{ value: 'users', label: 'Users' }
|
||||
];
|
||||
|
||||
const statuses = data.options?.statuses ?? [];
|
||||
const types = data.options?.types ?? [];
|
||||
let statuses = $derived(data.options?.statuses ?? []);
|
||||
let types = $derived(data.options?.types ?? []);
|
||||
const uuidRegex = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
||||
|
||||
function applyFilters(page = 1) {
|
||||
@@ -108,7 +127,7 @@
|
||||
id="report-target"
|
||||
class="rounded border border-neutral-700 bg-neutral-800 p-2"
|
||||
bind:value={target}
|
||||
on:change={(e) => {
|
||||
onchange={(e) => {
|
||||
if (e.currentTarget instanceof HTMLSelectElement) {
|
||||
handleTargetChange(e.currentTarget.value);
|
||||
}
|
||||
@@ -125,7 +144,7 @@
|
||||
id="report-status"
|
||||
class="rounded border border-neutral-700 bg-neutral-800 p-2"
|
||||
bind:value={status}
|
||||
on:change={() => applyFilters(1)}
|
||||
onchange={() => applyFilters(1)}
|
||||
>
|
||||
<option value="">Any</option>
|
||||
{#each statuses as s (s)}
|
||||
@@ -139,7 +158,7 @@
|
||||
id="report-type"
|
||||
class="rounded border border-neutral-700 bg-neutral-800 p-2"
|
||||
bind:value={type}
|
||||
on:change={() => applyFilters(1)}
|
||||
onchange={() => applyFilters(1)}
|
||||
>
|
||||
<option value="">Any</option>
|
||||
{#each types as t (t)}
|
||||
@@ -165,7 +184,7 @@
|
||||
? 'User UUID'
|
||||
: 'Paste ID or User UUID'}
|
||||
value={target === 'pastes' ? pasteId : target === 'users' ? userUuid : mixedTarget}
|
||||
on:input={(e) => {
|
||||
oninput={(e) => {
|
||||
if (e.currentTarget instanceof HTMLInputElement) {
|
||||
handleTargetInput(e.currentTarget.value);
|
||||
}
|
||||
@@ -181,8 +200,8 @@
|
||||
class="flex cursor-pointer flex-col gap-2 rounded border border-neutral-700 bg-neutral-800 px-5 py-4 transition-colors duration-200 hover:bg-neutral-700 focus:ring-2 focus:ring-neutral-600 focus:outline-none"
|
||||
role="link"
|
||||
tabindex="0"
|
||||
on:click={() => goto(resolve(`/report/${report.reportID}`))}
|
||||
on:keydown={(e) => {
|
||||
onclick={() => goto(resolve(`/report/${report.reportID}`))}
|
||||
onkeydown={(e) => {
|
||||
if (e.key === 'Enter' || e.key === ' ') {
|
||||
e.preventDefault();
|
||||
goto(resolve(`/report/${report.reportID}`));
|
||||
@@ -204,7 +223,7 @@
|
||||
<a
|
||||
href={resolve(`/${report.pasteId}`)}
|
||||
class="text-neutral-300 hover:text-white"
|
||||
on:click|stopPropagation
|
||||
onclick={stopPropagation(bubble('click'))}
|
||||
>
|
||||
{report.pasteTitle !== '' ? report.pasteTitle : report.pasteId}
|
||||
</a>
|
||||
@@ -215,7 +234,7 @@
|
||||
href={resolve(`/user/${report.targetUsername}`)}
|
||||
class="text-neutral-300 hover:text-white"
|
||||
use:tooltip={report.userUUID}
|
||||
on:click|stopPropagation
|
||||
onclick={stopPropagation(bubble('click'))}
|
||||
>
|
||||
{report.targetDisplayName || report.targetUsername}
|
||||
</a>
|
||||
@@ -228,7 +247,7 @@
|
||||
href={resolve(`/user/${report.reporterUsername}`)}
|
||||
class="text-neutral-300 hover:text-white"
|
||||
use:tooltip={report.reporterUUID}
|
||||
on:click|stopPropagation
|
||||
onclick={stopPropagation(bubble('click'))}
|
||||
>
|
||||
{report.reporterDisplayName || report.reporterUsername}
|
||||
</a>
|
||||
@@ -251,7 +270,7 @@
|
||||
<div class="mt-6 flex items-center justify-center gap-4">
|
||||
<button
|
||||
class="rounded bg-neutral-700 px-3 py-1 disabled:opacity-50"
|
||||
on:click={() => applyFilters(data.reports.pagination.page - 1)}
|
||||
onclick={() => applyFilters(data.reports.pagination.page - 1)}
|
||||
disabled={data.reports.pagination.page <= 1}
|
||||
>
|
||||
Prev
|
||||
@@ -261,7 +280,7 @@
|
||||
</span>
|
||||
<button
|
||||
class="rounded bg-neutral-700 px-3 py-1 disabled:opacity-50"
|
||||
on:click={() => applyFilters(data.reports.pagination.page + 1)}
|
||||
onclick={() => applyFilters(data.reports.pagination.page + 1)}
|
||||
disabled={data.reports.pagination.page >= data.reports.pagination.totalPages}
|
||||
>
|
||||
Next
|
||||
|
||||
@@ -3,11 +3,17 @@
|
||||
import { formatBytes, formatNumber, tooltip } from '$lib/utils/misc';
|
||||
import { FileText, Users, Database, TrendingUp } from '@lucide/svelte';
|
||||
|
||||
export let data: PageData;
|
||||
$: stats = data.stats.stats;
|
||||
interface Props {
|
||||
data: PageData;
|
||||
}
|
||||
|
||||
$: dailyData = stats.pastes.daily || [];
|
||||
$: maxCount = Math.max(...dailyData.map((d: { count: number; date: number }) => d.count), 5);
|
||||
let { data }: Props = $props();
|
||||
let stats = $derived(data.stats.stats);
|
||||
|
||||
let dailyData = $derived(stats.pastes.daily || []);
|
||||
let maxCount = $derived(
|
||||
Math.max(...dailyData.map((d: { count: number; date: number }) => d.count), 5)
|
||||
);
|
||||
|
||||
function getOrdinal(n: number) {
|
||||
const s = ['th', 'st', 'nd', 'rd'];
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
<script lang="ts">
|
||||
import { createBubbler, stopPropagation } from 'svelte/legacy';
|
||||
|
||||
const bubble = createBubbler();
|
||||
import { resolve } from '$app/paths';
|
||||
import { goto, afterNavigate } from '$app/navigation';
|
||||
import { page } from '$app/state';
|
||||
@@ -36,41 +39,46 @@
|
||||
import { reportStatusLabels, reportTargetLabels, reportTypeLabels } from '$lib/types/report';
|
||||
import { fade } from 'svelte/transition';
|
||||
|
||||
export let data: PageData;
|
||||
interface Props {
|
||||
data: PageData;
|
||||
}
|
||||
|
||||
let currentPage = data.pastes?.pagination?.page ?? 1;
|
||||
let pagination: Pagination = data.pastes?.pagination ?? {
|
||||
page: 1,
|
||||
pageSize: 50,
|
||||
totalCount: 0,
|
||||
totalPages: 1
|
||||
};
|
||||
let pastes = data.pastes?.pastes ?? [];
|
||||
let loading = false;
|
||||
let isOwner = false;
|
||||
let { data }: Props = $props();
|
||||
const initialPagination: Pagination = (() => {
|
||||
const pagination = data.pastes?.pagination;
|
||||
return {
|
||||
page: pagination?.page ?? 1,
|
||||
pageSize: pagination?.pageSize ?? 50,
|
||||
totalCount: pagination?.totalCount ?? 0,
|
||||
totalPages: pagination?.totalPages ?? 1
|
||||
};
|
||||
})();
|
||||
|
||||
let currentPage = $state(initialPagination.page);
|
||||
let pagination: Pagination = $state(initialPagination);
|
||||
let pastes = $state((() => data.pastes?.pastes ?? [])());
|
||||
let loading = $state(false);
|
||||
let isOwner = $derived(data.user && $user ? data.user?.uuid === $user.uuid : false);
|
||||
let modalError = '';
|
||||
let totpEnabled = false;
|
||||
let now = new Date();
|
||||
let totpEnabled = $derived(Boolean($user?.totpEnabled));
|
||||
let now = $state(new Date());
|
||||
let interval: ReturnType<typeof setInterval> | null = null;
|
||||
let isEditingDisplayName = false;
|
||||
let editDisplayNameValue = '';
|
||||
let isEditingDisplayName = $state(false);
|
||||
let editDisplayNameValue = $state('');
|
||||
|
||||
let apiKeys: { uuid: string; name: string; createdAt: string; lastUsedAt: string | null }[] = [];
|
||||
let apiKeys: { uuid: string; name: string; createdAt: string; lastUsedAt: string | null }[] =
|
||||
$state([]);
|
||||
let successfullyFetchedApiKeys = false;
|
||||
let newApiKeyName = '';
|
||||
let newApiKeyValue = '';
|
||||
let isCreatingApiKey = false;
|
||||
let apiKeyError = '';
|
||||
let copiedApiKey = false;
|
||||
let newApiKeyName = $state('');
|
||||
let newApiKeyValue = $state('');
|
||||
let isCreatingApiKey = $state(false);
|
||||
let apiKeyError = $state('');
|
||||
let copiedApiKey = $state(false);
|
||||
|
||||
$: isOwner = data.user && $user ? data.user?.uuid === $user.uuid : false;
|
||||
$: totpEnabled = Boolean($user?.totpEnabled);
|
||||
$: reportsSubmitted = data.reportsSubmitted;
|
||||
$: reportsTarget = data.reportsTarget;
|
||||
let reportsSubmitted = $derived(data.reportsSubmitted);
|
||||
let reportsTarget = $derived(data.reportsTarget);
|
||||
|
||||
let activeTab: 'pastes' | 'reportsSubmitted' | 'reportsTarget' | 'settings' = isOwner
|
||||
? 'settings'
|
||||
: 'pastes';
|
||||
let activeTab: 'pastes' | 'reportsSubmitted' | 'reportsTarget' | 'settings' = $state('pastes');
|
||||
|
||||
async function updateTab(newPageTab: typeof activeTab) {
|
||||
if (activeTab === newPageTab) return;
|
||||
@@ -93,7 +101,7 @@
|
||||
}
|
||||
}
|
||||
|
||||
$: {
|
||||
$effect(() => {
|
||||
const tab = page.url.searchParams.get('tab');
|
||||
switch (tab) {
|
||||
case 'pastes':
|
||||
@@ -119,7 +127,7 @@
|
||||
activeTab = 'pastes';
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
const roleOptions = [
|
||||
{ label: 'Member', value: 1 },
|
||||
@@ -245,10 +253,11 @@
|
||||
}
|
||||
|
||||
function handleTotpConfirm(value: unknown) {
|
||||
let enabled = totpEnabled;
|
||||
if (value && typeof value === 'object' && 'enabled' in value) {
|
||||
totpEnabled = Boolean((value as { enabled?: boolean }).enabled);
|
||||
enabled = Boolean((value as { enabled?: boolean }).enabled);
|
||||
}
|
||||
user.update((u) => (u ? { ...u, totpEnabled } : u));
|
||||
user.update((u) => (u ? { ...u, totpEnabled: enabled } : u));
|
||||
modalError = '';
|
||||
}
|
||||
|
||||
@@ -425,9 +434,10 @@
|
||||
}
|
||||
});
|
||||
|
||||
$: reportSiteKey =
|
||||
let reportSiteKey = $derived(
|
||||
(data as unknown as { authOptions?: { cf_turnstile_site_key?: string | null } }).authOptions
|
||||
?.cf_turnstile_site_key ?? null;
|
||||
?.cf_turnstile_site_key ?? null
|
||||
);
|
||||
</script>
|
||||
|
||||
<svelte:head>
|
||||
@@ -525,7 +535,7 @@
|
||||
<!-- svelte-ignore a11y_no_static_element_interactions -->
|
||||
<div
|
||||
class="absolute top-0 right-0"
|
||||
on:click={() =>
|
||||
onclick={() =>
|
||||
openModal({
|
||||
mode: 'report',
|
||||
title: 'Report User',
|
||||
@@ -546,7 +556,7 @@
|
||||
'settings'
|
||||
? 'border-neutral-200 text-white'
|
||||
: 'border-transparent text-neutral-400'}"
|
||||
on:click={() => updateTab('settings')}
|
||||
onclick={() => updateTab('settings')}
|
||||
>
|
||||
Settings
|
||||
</button>
|
||||
@@ -556,7 +566,7 @@
|
||||
'pastes'
|
||||
? 'border-neutral-200 text-white'
|
||||
: 'border-transparent text-neutral-400'}"
|
||||
on:click={() => updateTab('pastes')}
|
||||
onclick={() => updateTab('pastes')}
|
||||
>
|
||||
Pastes
|
||||
<span class="ml-2 rounded bg-neutral-800 px-2 py-0.5 text-xs text-neutral-300"
|
||||
@@ -569,7 +579,7 @@
|
||||
'reportsSubmitted'
|
||||
? 'border-neutral-200 text-white'
|
||||
: 'border-transparent text-neutral-400'}"
|
||||
on:click={() => updateTab('reportsSubmitted')}
|
||||
onclick={() => updateTab('reportsSubmitted')}
|
||||
>
|
||||
Submitted Reports
|
||||
<span class="ml-2 rounded bg-neutral-800 px-2 py-0.5 text-xs text-neutral-300"
|
||||
@@ -583,7 +593,7 @@
|
||||
'reportsTarget'
|
||||
? 'border-neutral-200 text-white'
|
||||
: 'border-transparent text-neutral-400'}"
|
||||
on:click={() => updateTab('reportsTarget')}
|
||||
onclick={() => updateTab('reportsTarget')}
|
||||
>
|
||||
Reports Against User
|
||||
<span class="ml-2 rounded bg-neutral-800 px-2 py-0.5 text-xs text-neutral-300"
|
||||
@@ -624,20 +634,20 @@
|
||||
bind:value={editDisplayNameValue}
|
||||
class="w-full border-b border-neutral-600 bg-transparent px-2 py-1 font-mono text-neutral-300 outline-none focus:border-neutral-400"
|
||||
maxlength="26"
|
||||
on:keydown={(e) => {
|
||||
onkeydown={(e) => {
|
||||
if (e.key === 'Enter') saveDisplayName();
|
||||
else if (e.key === 'Escape') cancelEditDisplayName();
|
||||
}}
|
||||
/>
|
||||
<button
|
||||
on:click={saveDisplayName}
|
||||
onclick={saveDisplayName}
|
||||
class="flex items-center gap-1 rounded bg-green-900/50 px-3 py-2 text-xs font-medium text-green-400 transition-colors hover:bg-green-900"
|
||||
>
|
||||
<Check class="h-4 w-4" />
|
||||
Save
|
||||
</button>
|
||||
<button
|
||||
on:click={cancelEditDisplayName}
|
||||
onclick={cancelEditDisplayName}
|
||||
class="flex items-center gap-1 rounded bg-neutral-700 px-3 py-2 text-xs font-medium text-neutral-300 transition-colors hover:bg-neutral-600"
|
||||
>
|
||||
<X class="h-4 w-4" />
|
||||
@@ -649,7 +659,7 @@
|
||||
>{data.user?.displayName || data.user?.username}</span
|
||||
>
|
||||
<button
|
||||
on:click={startEditDisplayName}
|
||||
onclick={startEditDisplayName}
|
||||
class="flex items-center gap-2 rounded bg-neutral-700 px-4 py-2 text-sm font-medium transition-colors hover:bg-neutral-600"
|
||||
>
|
||||
<Pencil class="h-4 w-4" />
|
||||
@@ -683,7 +693,7 @@
|
||||
>
|
||||
</div>
|
||||
<button
|
||||
on:click={openTotpSetup}
|
||||
onclick={openTotpSetup}
|
||||
class="rounded bg-neutral-700 px-3 py-1.5 text-xs font-medium transition-colors hover:bg-neutral-600"
|
||||
>
|
||||
{totpEnabled ? 'Manage' : 'Enable'}
|
||||
@@ -720,7 +730,7 @@
|
||||
>
|
||||
</div>
|
||||
<button
|
||||
on:click={openEditRoles}
|
||||
onclick={openEditRoles}
|
||||
class="flex items-center gap-2 rounded bg-neutral-700 px-4 py-2 text-sm font-medium transition-colors hover:bg-neutral-600"
|
||||
>
|
||||
Edit
|
||||
@@ -764,7 +774,7 @@
|
||||
maxlength="26"
|
||||
/>
|
||||
<button
|
||||
on:click={createApiKey}
|
||||
onclick={createApiKey}
|
||||
disabled={loading || !newApiKeyName}
|
||||
class="flex items-center gap-2 rounded bg-neutral-700 px-4 py-2 text-sm font-medium transition-colors hover:bg-neutral-600 disabled:opacity-50"
|
||||
>
|
||||
@@ -776,7 +786,7 @@
|
||||
Create
|
||||
</button>
|
||||
<button
|
||||
on:click={() => {
|
||||
onclick={() => {
|
||||
isCreatingApiKey = false;
|
||||
newApiKeyName = '';
|
||||
}}
|
||||
@@ -787,7 +797,7 @@
|
||||
</div>
|
||||
{:else}
|
||||
<button
|
||||
on:click={() => (isCreatingApiKey = true)}
|
||||
onclick={() => (isCreatingApiKey = true)}
|
||||
class="flex items-center gap-2 rounded bg-neutral-700 px-4 py-2 text-sm font-medium transition-colors hover:bg-neutral-600"
|
||||
>
|
||||
<Plus class="h-4 w-4" />
|
||||
@@ -801,7 +811,7 @@
|
||||
<div class="mb-2 flex items-center justify-between">
|
||||
<span class="text-sm font-medium text-green-400">API Key Created</span>
|
||||
<button
|
||||
on:click={() => (newApiKeyValue = '')}
|
||||
onclick={() => (newApiKeyValue = '')}
|
||||
class="text-green-400/70 hover:text-green-400"
|
||||
>
|
||||
<X class="h-4 w-4" />
|
||||
@@ -816,7 +826,7 @@
|
||||
>
|
||||
<button
|
||||
class="p-1 text-neutral-400 hover:text-white"
|
||||
on:click={() => {
|
||||
onclick={() => {
|
||||
navigator.clipboard.writeText(newApiKeyValue);
|
||||
copiedApiKey = true;
|
||||
setTimeout(() => (copiedApiKey = false), 1000);
|
||||
@@ -859,7 +869,7 @@
|
||||
</div>
|
||||
</div>
|
||||
<button
|
||||
on:click={() => deleteApiKey(key.uuid)}
|
||||
onclick={() => deleteApiKey(key.uuid)}
|
||||
disabled={loading}
|
||||
class="p-2 text-neutral-500 transition-colors hover:text-red-400"
|
||||
title="Revoke Key"
|
||||
@@ -894,7 +904,7 @@
|
||||
</p>
|
||||
</div>
|
||||
<button
|
||||
on:click={openDeleteAccount}
|
||||
onclick={openDeleteAccount}
|
||||
class="rounded border border-red-500/50 bg-red-500/10 px-4 py-2 text-sm font-medium whitespace-nowrap text-red-400 transition-colors hover:bg-red-500 hover:text-white"
|
||||
>
|
||||
Delete Account
|
||||
@@ -922,7 +932,7 @@
|
||||
<div class="mt-4 flex items-center justify-center gap-4">
|
||||
<button
|
||||
class="rounded bg-neutral-700 px-3 py-1 disabled:opacity-50"
|
||||
on:click={() => fetchPage(currentPage - 1)}
|
||||
onclick={() => fetchPage(currentPage - 1)}
|
||||
disabled={currentPage === 1 || loading}
|
||||
>
|
||||
Prev
|
||||
@@ -932,7 +942,7 @@
|
||||
</span>
|
||||
<button
|
||||
class="rounded bg-neutral-700 px-3 py-1 disabled:opacity-50"
|
||||
on:click={() => fetchPage(currentPage + 1)}
|
||||
onclick={() => fetchPage(currentPage + 1)}
|
||||
disabled={currentPage === pagination.totalPages || loading}
|
||||
>
|
||||
Next
|
||||
@@ -946,8 +956,8 @@
|
||||
class="flex cursor-pointer flex-col gap-2 rounded border border-neutral-700 bg-neutral-800 px-5 py-4 transition-colors duration-200 hover:bg-neutral-700 focus:ring-2 focus:ring-neutral-600 focus:outline-none"
|
||||
role="link"
|
||||
tabindex="0"
|
||||
on:click={() => goto(resolve(`/report/${report.reportID}`))}
|
||||
on:keydown={(e) => {
|
||||
onclick={() => goto(resolve(`/report/${report.reportID}`))}
|
||||
onkeydown={(e) => {
|
||||
if (e.key === 'Enter' || e.key === ' ') {
|
||||
e.preventDefault();
|
||||
goto(resolve(`/report/${report.reportID}`));
|
||||
@@ -969,7 +979,7 @@
|
||||
<a
|
||||
href={resolve(`/${report.pasteId}`)}
|
||||
class="text-neutral-300 hover:text-white"
|
||||
on:click|stopPropagation
|
||||
onclick={stopPropagation(bubble('click'))}
|
||||
>
|
||||
{report.pasteTitle !== '' ? report.pasteTitle : report.pasteId}
|
||||
</a>
|
||||
@@ -980,7 +990,7 @@
|
||||
href={resolve(`/user/${report.targetUsername}`)}
|
||||
class="text-neutral-300 hover:text-white"
|
||||
use:tooltip={report.userUUID}
|
||||
on:click|stopPropagation
|
||||
onclick={stopPropagation(bubble('click'))}
|
||||
>
|
||||
{report.targetDisplayName || report.targetUsername}
|
||||
</a>
|
||||
@@ -1005,8 +1015,8 @@
|
||||
class="flex cursor-pointer flex-col gap-2 rounded border border-neutral-700 bg-neutral-800 px-5 py-4 transition-colors duration-200 hover:bg-neutral-700 focus:ring-2 focus:ring-neutral-600 focus:outline-none"
|
||||
role="link"
|
||||
tabindex="0"
|
||||
on:click={() => goto(resolve(`/report/${report.reportID}`))}
|
||||
on:keydown={(e) => {
|
||||
onclick={() => goto(resolve(`/report/${report.reportID}`))}
|
||||
onkeydown={(e) => {
|
||||
if (e.key === 'Enter' || e.key === ' ') {
|
||||
e.preventDefault();
|
||||
goto(resolve(`/report/${report.reportID}`));
|
||||
@@ -1029,7 +1039,7 @@
|
||||
href={resolve(`/user/${report.reporterUsername}`)}
|
||||
class="text-neutral-300 hover:text-white"
|
||||
use:tooltip={report.reporterUUID}
|
||||
on:click|stopPropagation
|
||||
onclick={stopPropagation(bubble('click'))}
|
||||
>
|
||||
{report.reporterDisplayName || report.reporterUsername}
|
||||
</a>
|
||||
@@ -1040,7 +1050,7 @@
|
||||
<a
|
||||
href={resolve(`/${report.pasteId ?? report.pastePID}`)}
|
||||
class="text-neutral-300 hover:text-white"
|
||||
on:click|stopPropagation
|
||||
onclick={stopPropagation(bubble('click'))}
|
||||
>
|
||||
{report.pasteTitle ? report.pasteTitle : `Paste #${report.pastePID}`}
|
||||
</a>
|
||||
@@ -1051,7 +1061,7 @@
|
||||
href={resolve(`/user/${report.targetUsername}`)}
|
||||
class="text-neutral-300 hover:text-white"
|
||||
use:tooltip={report.userUUID}
|
||||
on:click|stopPropagation
|
||||
onclick={stopPropagation(bubble('click'))}
|
||||
>
|
||||
{report.targetDisplayName || report.targetUsername}
|
||||
</a>
|
||||
|
||||
Reference in New Issue
Block a user