This commit is contained in:
1 parent
9a6ec940f7
commit
fd32419371
114 files changed
+21997
-96
No files matched your search
@@ -0,0 +1,211 @@
|
||||
<script lang="ts">
|
||||
import { onMount } from 'svelte'
|
||||
import { get } from '$lib/api'
|
||||
import EmptyState from '$lib/components/EmptyState.svelte'
|
||||
import SectionTitle from '$lib/components/SectionTitle.svelte'
|
||||
import Badge from '$lib/components/ui/badge.svelte'
|
||||
import Button from '$lib/components/ui/button.svelte'
|
||||
import Card from '$lib/components/ui/card.svelte'
|
||||
|
||||
type Json = Record<string, unknown>
|
||||
type MediaType = 'image' | 'video' | 'audio' | 'funscript'
|
||||
|
||||
// mediaType fixes the card to one media type and hides the type filter entirely - used by the
|
||||
// Images/Videos/Audios/Funscripts tabs, which have no business filtering across types. Every
|
||||
// other page (dashboard, schedules, discover) omits it and gets the full type filter instead.
|
||||
let {
|
||||
mediaType,
|
||||
title = 'Processing history',
|
||||
description = 'Recently processed elements and their results.',
|
||||
pageSize = 10,
|
||||
}: {
|
||||
mediaType?: MediaType
|
||||
title?: string
|
||||
description?: string
|
||||
pageSize?: number
|
||||
} = $props()
|
||||
|
||||
const TYPE_OPTIONS: { value: string; label: string }[] = [
|
||||
{ value: '', label: 'All types' },
|
||||
{ value: 'image', label: 'Images' },
|
||||
{ value: 'video', label: 'Videos' },
|
||||
{ value: 'audio', label: 'Audios' },
|
||||
{ value: 'funscript', label: 'Funscripts' },
|
||||
]
|
||||
const STATUS_OPTIONS: { value: string; label: string }[] = [
|
||||
{ value: '', label: 'All statuses' },
|
||||
{ value: 'queued', label: 'Queued' },
|
||||
{ value: 'processing', label: 'Processing' },
|
||||
{ value: 'done', label: 'Done' },
|
||||
{ value: 'error', label: 'Error' },
|
||||
]
|
||||
|
||||
let typeFilter = $state('')
|
||||
let statusFilter = $state('')
|
||||
let currentPage = $state(1)
|
||||
let entries = $state<Json[]>([])
|
||||
let total = $state(0)
|
||||
let loading = $state(true)
|
||||
let error = $state('')
|
||||
|
||||
// The type filter is only ever shown (and only ever meaningful) when the parent hasn't already
|
||||
// fixed one - once it's fixed, the fixed value always wins over whatever's left in the dropdown
|
||||
// state from a previous type-agnostic usage of this same component instance.
|
||||
const effectiveType = $derived(mediaType ?? typeFilter)
|
||||
|
||||
function firstValue(entry: Json, keys: string[], fallback: string) {
|
||||
for (const key of keys) {
|
||||
const value = entry[key]
|
||||
if (value !== undefined && value !== null && String(value).trim() !== '') {
|
||||
return String(value)
|
||||
}
|
||||
}
|
||||
return fallback
|
||||
}
|
||||
|
||||
function statusTone(status: string): 'neutral' | 'primary' | 'success' | 'warning' | 'danger' {
|
||||
const normalized = status.toLowerCase()
|
||||
if (normalized.includes('error') || normalized.includes('fail')) return 'danger'
|
||||
if (normalized.includes('process') || normalized.includes('running')) return 'primary'
|
||||
if (normalized.includes('queue') || normalized.includes('pending')) return 'warning'
|
||||
if (normalized.includes('done') || normalized.includes('complete') || normalized.includes('success'))
|
||||
return 'success'
|
||||
return 'neutral'
|
||||
}
|
||||
|
||||
async function load({ background = false } = {}) {
|
||||
if (!background) loading = true
|
||||
error = ''
|
||||
try {
|
||||
const params: [string, string][] = [
|
||||
['limit', String(pageSize)],
|
||||
['offset', String((currentPage - 1) * pageSize)],
|
||||
]
|
||||
if (effectiveType) params.push(['mediaType', effectiveType])
|
||||
if (statusFilter) params.push(['status', statusFilter])
|
||||
const query = params.map(([key, value]) => `${key}=${encodeURIComponent(value)}`).join('&')
|
||||
const response = await get<Json>(`/api/history?${query}`)
|
||||
const rawEntries = response.items || response.history || response.rows
|
||||
entries = Array.isArray(rawEntries) ? (rawEntries as Json[]) : []
|
||||
total = Number(response.total ?? entries.length) || 0
|
||||
} catch (reason) {
|
||||
error = reason instanceof Error ? reason.message : 'Unable to load processing history.'
|
||||
entries = []
|
||||
total = 0
|
||||
} finally {
|
||||
if (!background) loading = false
|
||||
}
|
||||
}
|
||||
|
||||
function goToPage(next: number) {
|
||||
const target = Math.max(1, next)
|
||||
if (target === currentPage) return
|
||||
currentPage = target
|
||||
void load()
|
||||
}
|
||||
|
||||
function applyTypeFilter(value: string) {
|
||||
typeFilter = value
|
||||
currentPage = 1
|
||||
void load()
|
||||
}
|
||||
|
||||
function applyStatusFilter(value: string) {
|
||||
statusFilter = value
|
||||
currentPage = 1
|
||||
void load()
|
||||
}
|
||||
|
||||
// Re-fetches whenever the mediaType *prop* changes - the Images/Videos/Audios/Funscripts tabs
|
||||
// all reuse one component instance across tab switches (same position in the parent's template),
|
||||
// so this is what makes switching tabs actually reload that tab's own history instead of still
|
||||
// showing the previous tab's entries. Also covers the initial load on mount.
|
||||
$effect(() => {
|
||||
void mediaType
|
||||
currentPage = 1
|
||||
void load()
|
||||
})
|
||||
|
||||
onMount(() => {
|
||||
const timer = window.setInterval(() => void load({ background: true }), 10_000)
|
||||
return () => window.clearInterval(timer)
|
||||
})
|
||||
</script>
|
||||
|
||||
<Card class="space-y-4">
|
||||
<SectionTitle {title} {description} />
|
||||
<div class="flex flex-wrap items-center gap-3">
|
||||
{#if !mediaType}
|
||||
<select
|
||||
class="field h-8 w-40 text-sm"
|
||||
value={typeFilter}
|
||||
onchange={(event) => applyTypeFilter(event.currentTarget.value)}
|
||||
>
|
||||
{#each TYPE_OPTIONS as option (option.value)}
|
||||
<option value={option.value}>{option.label}</option>
|
||||
{/each}
|
||||
</select>
|
||||
{/if}
|
||||
<select
|
||||
class="field h-8 w-40 text-sm"
|
||||
value={statusFilter}
|
||||
onchange={(event) => applyStatusFilter(event.currentTarget.value)}
|
||||
>
|
||||
{#each STATUS_OPTIONS as option (option.value)}
|
||||
<option value={option.value}>{option.label}</option>
|
||||
{/each}
|
||||
</select>
|
||||
</div>
|
||||
{#if error}
|
||||
<p class="rounded-md border border-danger/30 bg-danger/10 p-3 text-xs text-danger">{error}</p>
|
||||
{/if}
|
||||
{#if loading}
|
||||
<p class="text-sm text-muted-fg">Loading history…</p>
|
||||
{:else if entries.length === 0}
|
||||
<EmptyState title="No processed elements" message="Processed files and their results will appear here." />
|
||||
{:else}
|
||||
<div class="space-y-2">
|
||||
{#each entries as entry, index (String(entry.id || entry.file_path || index))}
|
||||
{@const name = firstValue(entry, ['file_name', 'fileName', 'file', 'type', 'action'], 'Processed element')}
|
||||
{@const path = firstValue(entry, ['file_path', 'filePath', 'path'], '')}
|
||||
{@const entryMediaType = firstValue(entry, ['media_type', 'mediaType', 'type'], '')}
|
||||
{@const status = firstValue(entry, ['status', 'state'], 'recorded')}
|
||||
{@const progress = firstValue(entry, ['progress'], '')}
|
||||
{@const timestamp = firstValue(
|
||||
entry,
|
||||
['finished_at', 'finishedAt', 'created_at', 'createdAt', 'queued_at', 'queuedAt', 'timestamp'],
|
||||
'',
|
||||
)}
|
||||
{@const message = firstValue(entry, ['error', 'error_message', 'message'], '')}
|
||||
<div class="rounded-md border border-border bg-bg p-3">
|
||||
<div class="flex items-start justify-between gap-3">
|
||||
<div class="min-w-0">
|
||||
<p class="truncate text-sm font-medium text-fg">{name}</p>
|
||||
{#if path}<p class="mt-1 truncate text-xs text-muted-fg">{path}</p>{/if}
|
||||
</div>
|
||||
<Badge tone={statusTone(status)}>{status}</Badge>
|
||||
</div>
|
||||
<div class="mt-2 flex flex-wrap gap-x-3 gap-y-1 text-xs text-muted-fg">
|
||||
{#if entryMediaType}<span>{entryMediaType}</span>{/if}
|
||||
{#if progress}<span>{progress}% complete</span>{/if}
|
||||
{#if timestamp}<span>{timestamp}</span>{/if}
|
||||
</div>
|
||||
{#if message}<p class="mt-2 truncate text-xs text-danger">{message}</p>{/if}
|
||||
</div>
|
||||
{/each}
|
||||
</div>
|
||||
<div class="flex items-center justify-between border-t border-border pt-3">
|
||||
<p class="text-xs text-muted-fg">Showing {entries.length} of {total.toLocaleString()}</p>
|
||||
<div class="flex gap-2">
|
||||
<Button variant="secondary" size="sm" disabled={currentPage <= 1} onclick={() => goToPage(currentPage - 1)}
|
||||
>Previous</Button
|
||||
><Button
|
||||
variant="secondary"
|
||||
size="sm"
|
||||
disabled={currentPage * pageSize >= total}
|
||||
onclick={() => goToPage(currentPage + 1)}>Next</Button
|
||||
>
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
</Card>
|
||||
@@ -0,0 +1,212 @@
|
||||
<script lang="ts">
|
||||
import { notify } from '@gabriel20xx/web-ui'
|
||||
import { post } from '$lib/api'
|
||||
import SectionTitle from '$lib/components/SectionTitle.svelte'
|
||||
import Badge from '$lib/components/ui/badge.svelte'
|
||||
import Button from '$lib/components/ui/button.svelte'
|
||||
import Card from '$lib/components/ui/card.svelte'
|
||||
|
||||
type Json = Record<string, unknown>
|
||||
type StatusTone = 'neutral' | 'primary' | 'success' | 'warning' | 'danger'
|
||||
|
||||
let {
|
||||
status = {},
|
||||
stats = {},
|
||||
loading = false,
|
||||
description = 'Current analyzer worker state.',
|
||||
}: { status?: Json; stats?: Json; loading?: boolean; description?: string } = $props()
|
||||
|
||||
// discovering/extracting/cleaning all share one backend scan slot (see scanCancel on the Go
|
||||
// side), so they stop through the same endpoint; generate/analyze/the legacy extract worker
|
||||
// each have their own. "clearing" (database clear) has no entry - that reset runs synchronously
|
||||
// on the request that started it, so there's nothing separate left to cancel.
|
||||
const STOP_ENDPOINTS: Record<string, string> = {
|
||||
discovering: 'scan/stop',
|
||||
extracting: 'scan/stop',
|
||||
cleaning: 'scan/stop',
|
||||
generating: 'generate/stop',
|
||||
analyzing: 'analyze/stop',
|
||||
processing: 'extract/stop',
|
||||
}
|
||||
|
||||
let stopping = $state(false)
|
||||
|
||||
function asRecord(value: unknown): Json {
|
||||
return value && typeof value === 'object' && !Array.isArray(value) ? (value as Json) : {}
|
||||
}
|
||||
|
||||
function firstRecord(...values: unknown[]): Json {
|
||||
for (const value of values) {
|
||||
const record = asRecord(value)
|
||||
if (Object.keys(record).length > 0) return record
|
||||
}
|
||||
return {}
|
||||
}
|
||||
|
||||
function numeric(source: Json, key: string, fallback = 0) {
|
||||
const value = Number(source[key] ?? fallback)
|
||||
return Number.isFinite(value) ? value : fallback
|
||||
}
|
||||
|
||||
function formatTimestamp(value: unknown) {
|
||||
if (value === null || value === undefined) return '—'
|
||||
|
||||
if (value instanceof Date) {
|
||||
return Number.isNaN(value.getTime()) ? '—' : value.toLocaleString()
|
||||
}
|
||||
|
||||
const raw = String(value).trim()
|
||||
if (!raw) return '—'
|
||||
|
||||
const numericValue = Number(raw)
|
||||
const timestamp =
|
||||
Number.isFinite(numericValue) && /^-?\d+(?:\.\d+)?$/.test(raw)
|
||||
? Math.abs(numericValue) < 100_000_000_000
|
||||
? numericValue * 1000
|
||||
: numericValue
|
||||
: Date.parse(raw)
|
||||
|
||||
if (!Number.isFinite(timestamp) || timestamp <= 0) return '—'
|
||||
return new Date(timestamp).toLocaleString()
|
||||
}
|
||||
|
||||
function stateTone(label: string, running: boolean, paused: boolean): StatusTone {
|
||||
if (running) return paused ? 'warning' : 'primary'
|
||||
if (label.includes('error') || label.includes('failed')) return 'danger'
|
||||
if (['idle', 'completed', 'complete', 'done'].includes(label)) return 'success'
|
||||
return 'neutral'
|
||||
}
|
||||
|
||||
const extractionProgress = $derived(asRecord(status.extractionProgress))
|
||||
const queue = $derived(firstRecord(status.queue, extractionProgress, stats, status))
|
||||
const currentJob = $derived(asRecord(status.current))
|
||||
const stateLabel = $derived(
|
||||
String(
|
||||
status.state ||
|
||||
status.status ||
|
||||
(status.running === true ? (status.paused === true ? 'paused' : 'running') : 'idle'),
|
||||
),
|
||||
)
|
||||
const stateKey = $derived(stateLabel.toLowerCase())
|
||||
const running = $derived(
|
||||
status.running === true ||
|
||||
status.extracting === true ||
|
||||
status.processing === true ||
|
||||
['running', 'extracting', 'processing', 'discovering', 'generating', 'analyzing', 'cleaning', 'clearing'].includes(
|
||||
stateKey,
|
||||
),
|
||||
)
|
||||
const paused = $derived(status.paused === true || stateKey.includes('paused'))
|
||||
// `status.queue` (a raw media_worker_jobs count) is misleading here: those rows go straight to
|
||||
// "done" on discovery and never actually sit in "queued"/"processing", so that count is always
|
||||
// 0 regardless of how much metadata/thumbnail/AI-analysis work is really pending. `stats` -
|
||||
// summed from the same per-stage pipeline breakdown the dashboard/discover pages render below
|
||||
// this card - is the real number, so it takes priority; the job-table queue is just a fallback
|
||||
// for callers that only ever pass `status`.
|
||||
const queued = $derived(numeric(stats, 'queued', numeric(queue, 'queued', numeric(status, 'queued'))))
|
||||
const processing = $derived(
|
||||
numeric(stats, 'processing', numeric(queue, 'processing', numeric(status, 'processing'))),
|
||||
)
|
||||
const total = $derived(numeric(status, 'total', numeric(extractionProgress, 'total')))
|
||||
const completed = $derived(
|
||||
numeric(
|
||||
status,
|
||||
'completed',
|
||||
numeric(queue, 'completed', numeric(queue, 'done', numeric(extractionProgress, 'extracted'))),
|
||||
),
|
||||
)
|
||||
const failed = $derived(numeric(status, 'failed', numeric(queue, 'failed')))
|
||||
const progressCompleted = $derived(completed + failed)
|
||||
const progressPercent = $derived(total > 0 ? Math.min(100, (progressCompleted / total) * 100) : 0)
|
||||
const current = $derived(
|
||||
typeof status.current === 'string'
|
||||
? status.current
|
||||
: String(currentJob.fileName || currentJob.file_name || currentJob.filePath || currentJob.file_path || '—'),
|
||||
)
|
||||
const worker = $derived(String(status.worker || status.activeWorker || '—'))
|
||||
const lastUpdate = $derived(
|
||||
formatTimestamp(status.updatedAt || status.updated_at || status.timestamp || status.finishedAt),
|
||||
)
|
||||
const lastError = $derived(String(status.lastError || status.error || ''))
|
||||
const tone = $derived(stateTone(stateKey, running, paused))
|
||||
const stopEndpoint = $derived(STOP_ENDPOINTS[stateKey])
|
||||
const canStop = $derived(running && !!stopEndpoint)
|
||||
|
||||
async function stopAction() {
|
||||
if (!stopEndpoint) return
|
||||
stopping = true
|
||||
try {
|
||||
await post(`/api/${stopEndpoint}`)
|
||||
notify.success('Stop requested.')
|
||||
} catch (reason) {
|
||||
notify.error(reason instanceof Error ? reason.message : 'Unable to stop the running action.')
|
||||
} finally {
|
||||
stopping = false
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<Card class="space-y-4">
|
||||
<SectionTitle title="Live status" {description} />
|
||||
{#if loading}
|
||||
<p class="text-sm text-muted-fg">Loading status…</p>
|
||||
{:else}
|
||||
<div class="space-y-3" aria-live="polite">
|
||||
<div class="flex items-center justify-between gap-3">
|
||||
<span class="text-sm text-muted-fg">State</span>
|
||||
<div class="flex items-center gap-2">
|
||||
<Badge {tone}>{stateLabel}</Badge>
|
||||
{#if canStop}
|
||||
<Button variant="danger" size="sm" disabled={stopping} onclick={() => void stopAction()}>
|
||||
{stopping ? 'Stopping…' : 'Stop'}
|
||||
</Button>
|
||||
{/if}
|
||||
</div>
|
||||
</div>
|
||||
<div class="flex items-center justify-between">
|
||||
<span class="text-sm text-muted-fg">Pending</span>
|
||||
<span class="text-sm text-fg">{queued}</span>
|
||||
</div>
|
||||
<div class="flex items-center justify-between">
|
||||
<span class="text-sm text-muted-fg">Processing</span>
|
||||
<span class="text-sm text-fg">{processing}</span>
|
||||
</div>
|
||||
<div class="flex items-center justify-between">
|
||||
<span class="text-sm text-muted-fg">Worker</span>
|
||||
<span class="text-sm text-fg">{worker}</span>
|
||||
</div>
|
||||
<div class="flex items-center justify-between gap-3">
|
||||
<span class="text-sm text-muted-fg">Current item</span>
|
||||
<span class="max-w-52 truncate text-right text-xs text-muted-fg">{current}</span>
|
||||
</div>
|
||||
{#if total > 0}
|
||||
<div>
|
||||
<div class="mb-1 flex justify-between text-xs text-muted-fg">
|
||||
<span>Progress</span>
|
||||
<span>{progressCompleted} / {total}</span>
|
||||
</div>
|
||||
<div class="h-2 overflow-hidden rounded-full bg-surface-hover">
|
||||
<div class="h-full rounded-full bg-primary transition-[width]" style={`width: ${progressPercent}%`}></div>
|
||||
</div>
|
||||
</div>
|
||||
{:else if running && progressCompleted > 0}
|
||||
<div>
|
||||
<div class="mb-1 flex justify-between text-xs text-muted-fg">
|
||||
<span>Progress</span>
|
||||
<span>{progressCompleted} processed</span>
|
||||
</div>
|
||||
<div class="h-2 overflow-hidden rounded-full bg-surface-hover">
|
||||
<div class="h-full w-1/3 animate-pulse rounded-full bg-primary"></div>
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
<div class="flex items-center justify-between gap-3">
|
||||
<span class="text-sm text-muted-fg">Last update</span>
|
||||
<span class="max-w-52 truncate text-right text-xs text-muted-fg">{lastUpdate}</span>
|
||||
</div>
|
||||
{#if lastError}
|
||||
<p class="rounded-md border border-danger/30 bg-danger/10 p-3 text-xs text-danger">{lastError}</p>
|
||||
{/if}
|
||||
</div>
|
||||
{/if}
|
||||
</Card>
|
||||
@@ -0,0 +1,85 @@
|
||||
<script lang="ts">
|
||||
import SectionTitle from '$lib/components/SectionTitle.svelte'
|
||||
import Card from '$lib/components/ui/card.svelte'
|
||||
|
||||
type Json = Record<string, unknown>
|
||||
|
||||
const mediaTypes = [
|
||||
{ key: 'image', label: 'Images' },
|
||||
{ key: 'video', label: 'Videos' },
|
||||
{ key: 'audio', label: 'Audios' },
|
||||
{ key: 'funscript', label: 'Funscripts' },
|
||||
]
|
||||
// 'convert' is left out - that stage was retired along with the Convert tab, and the
|
||||
// backend's breakdown map still carries it (always zero) only for backward compatibility.
|
||||
// 'discover' is left out too - it's not a per-file processing stage, just the media count
|
||||
// itself, which is already shown via total() in the card header.
|
||||
const processStages = [
|
||||
{ key: 'extract', label: 'Metadata' },
|
||||
{ key: 'generate', label: 'Thumbnails' },
|
||||
{ key: 'analyze', label: 'AI analysis' },
|
||||
]
|
||||
|
||||
let { pipeline = {} }: { pipeline?: Json } = $props()
|
||||
|
||||
// Thumbnails only ever run for images and videos, and AI analysis has no stages at all for
|
||||
// funscript - skip those rows rather than showing counts that can only ever read zero.
|
||||
function stagesFor(mediaTypeKey: string) {
|
||||
return processStages.filter((stage) => {
|
||||
if (stage.key === 'generate') return mediaTypeKey === 'image' || mediaTypeKey === 'video'
|
||||
if (stage.key === 'analyze') return mediaTypeKey !== 'funscript'
|
||||
return true
|
||||
})
|
||||
}
|
||||
|
||||
function count(stage: string, mediaType: string, status: string) {
|
||||
const stageData = pipeline[stage]
|
||||
if (!stageData || typeof stageData !== 'object' || Array.isArray(stageData)) return 0
|
||||
const mediaData = (stageData as Json)[mediaType]
|
||||
if (!mediaData || typeof mediaData !== 'object' || Array.isArray(mediaData)) return 0
|
||||
const value = Number((mediaData as Json)[status] ?? 0)
|
||||
return Number.isFinite(value) ? value : 0
|
||||
}
|
||||
|
||||
// The "discover" stage's "completed" bucket is a straight count of active media rows of that type
|
||||
// (funscripts counted via has_funscript rather than their own media_type) - already exactly the
|
||||
// per-type total, so there's no need for a separate stats prop just to show it in the header.
|
||||
function total(mediaTypeKey: string) {
|
||||
return count('discover', mediaTypeKey, 'completed')
|
||||
}
|
||||
</script>
|
||||
|
||||
<Card class="space-y-4">
|
||||
<SectionTitle
|
||||
title="Pipeline breakdown"
|
||||
description="Pending, completed, and error counts for every media type and processing stage."
|
||||
/>
|
||||
<div class="grid gap-4 md:grid-cols-2">
|
||||
{#each mediaTypes as mediaType (mediaType.key)}
|
||||
<div class="overflow-hidden rounded-md border border-border">
|
||||
<div class="flex items-center justify-between border-b border-border bg-bg px-4 py-3">
|
||||
<h3 class="text-sm font-semibold text-fg">{mediaType.label}</h3>
|
||||
<span class="text-xs text-muted-fg">{total(mediaType.key).toLocaleString()} total</span>
|
||||
</div>
|
||||
<div class="grid grid-cols-[minmax(0,1fr)_4.5rem_4.5rem_4.5rem] items-center gap-x-2 px-4 py-2 text-xs">
|
||||
<span class="text-muted-fg">Process stage</span>
|
||||
<span class="text-right text-warning">Pending</span>
|
||||
<span class="text-right text-success">Done</span>
|
||||
<span class="text-right text-danger">Errors</span>
|
||||
{#each stagesFor(mediaType.key) as stage (stage.key)}
|
||||
<span class="border-t border-border py-2 text-sm text-fg">{stage.label}</span>
|
||||
<span class="border-t border-border py-2 text-right text-sm text-warning"
|
||||
>{count(stage.key, mediaType.key, 'queued')}</span
|
||||
>
|
||||
<span class="border-t border-border py-2 text-right text-sm text-success"
|
||||
>{count(stage.key, mediaType.key, 'completed')}</span
|
||||
>
|
||||
<span class="border-t border-border py-2 text-right text-sm text-danger"
|
||||
>{count(stage.key, mediaType.key, 'errors')}</span
|
||||
>
|
||||
{/each}
|
||||
</div>
|
||||
</div>
|
||||
{/each}
|
||||
</div>
|
||||
</Card>
|
||||
@@ -0,0 +1,292 @@
|
||||
<script lang="ts">
|
||||
import { goto } from '$app/navigation'
|
||||
import { page } from '$app/state'
|
||||
import { onMount } from 'svelte'
|
||||
import AuthPage from '$lib/components/AuthPage.svelte'
|
||||
import ProjectIcon from '$lib/components/ProjectIcon.svelte'
|
||||
import AboutWorkspace from '$lib/features/AboutWorkspace.svelte'
|
||||
import { AboutDialog, AdminDialog, Header, NotificationStack, PageHeader, ProfileDialog } from '@gabriel20xx/web-ui'
|
||||
import type {
|
||||
AuthLoginInput,
|
||||
AuthSetupInput,
|
||||
ManagedUser,
|
||||
ProfileUpdateInput,
|
||||
UserCreateInput,
|
||||
UserId,
|
||||
UserRole,
|
||||
UserUpdateInput,
|
||||
} from '@gabriel20xx/web-ui'
|
||||
import SettingsDialog from '$lib/components/SettingsDialog.svelte'
|
||||
import { getPanelForPath } from '$lib/app-config'
|
||||
import { pageActions } from '$lib/stores/page-actions.svelte'
|
||||
import { del, get, post, put } from '$lib/api'
|
||||
import '$lib/language.svelte'
|
||||
import type { AppConfig, AuthState, AuthUser } from '$lib/types'
|
||||
import type { Snippet } from 'svelte'
|
||||
|
||||
let { app, children }: { app: AppConfig; children: Snippet } = $props()
|
||||
|
||||
let auth = $state<AuthState>({
|
||||
user: null,
|
||||
authRequired: true,
|
||||
setupRequired: true,
|
||||
loading: true,
|
||||
error: null,
|
||||
})
|
||||
let settingsOpen = $state(false)
|
||||
let aboutOpen = $state(false)
|
||||
let profileOpen = $state(false)
|
||||
let adminOpen = $state(false)
|
||||
|
||||
// Header only renders its profile/settings menu when username is truthy - with login not
|
||||
// required and nobody signed in, auth.user is legitimately null (there's no session to read
|
||||
// it from), which silently hid Settings (and with it, the only UI path back to re-enabling
|
||||
// login) behind a button that never appeared. Falls back to a placeholder identity in that
|
||||
// one case so the menu - and Settings - stays reachable.
|
||||
const displayName = $derived(auth.user?.username || auth.user?.email || (auth.authRequired ? '' : 'Admin'))
|
||||
const homePath = $derived(app.nav[0]?.path || '/')
|
||||
const navItems = $derived(
|
||||
app.nav.map((item) => ({
|
||||
href: item.path,
|
||||
label: item.label,
|
||||
icon: item.icon,
|
||||
description: item.description,
|
||||
})),
|
||||
)
|
||||
const activeNavItem = $derived(
|
||||
app.nav.find((item) => item.panel === getPanelForPath(app, page.url.pathname)) || app.nav[0],
|
||||
)
|
||||
const currentRole = $derived<UserRole>(
|
||||
auth.user?.role === 'superadmin' || auth.user?.role === 'admin' ? auth.user.role : 'user',
|
||||
)
|
||||
const currentUserId = $derived<UserId | undefined>(auth.user?.id)
|
||||
const isAdmin = $derived(currentRole === 'admin' || currentRole === 'superadmin')
|
||||
|
||||
function openSettings() {
|
||||
settingsOpen = true
|
||||
}
|
||||
|
||||
function openAbout() {
|
||||
aboutOpen = true
|
||||
}
|
||||
|
||||
function openProfile() {
|
||||
profileOpen = true
|
||||
}
|
||||
|
||||
function openAdmin() {
|
||||
adminOpen = true
|
||||
}
|
||||
|
||||
function closeSettings() {
|
||||
settingsOpen = false
|
||||
if (page.url.pathname === '/settings') void goto(homePath)
|
||||
}
|
||||
|
||||
function closeAbout() {
|
||||
aboutOpen = false
|
||||
if (page.url.pathname === '/about') void goto(homePath)
|
||||
}
|
||||
|
||||
function currentPageToken() {
|
||||
if (typeof window === 'undefined') return '/'
|
||||
return `${window.location.pathname}${window.location.search}` || '/'
|
||||
}
|
||||
|
||||
async function loadAuth() {
|
||||
try {
|
||||
const data = await get<{ user: AuthUser | null; authRequired?: boolean }>(
|
||||
`/auth/me?page=${encodeURIComponent(currentPageToken())}`,
|
||||
)
|
||||
let setupRequired = false
|
||||
try {
|
||||
const bootstrap = await get<{ adminNeeded?: boolean }>('/auth/bootstrap/admin-needed')
|
||||
setupRequired = bootstrap.adminNeeded === true
|
||||
} catch {
|
||||
// The auth status remains usable if the optional bootstrap check is unavailable.
|
||||
}
|
||||
auth = {
|
||||
user: data.user || null,
|
||||
authRequired: data.authRequired !== false,
|
||||
setupRequired,
|
||||
loading: false,
|
||||
error: null,
|
||||
}
|
||||
} catch (error) {
|
||||
auth = {
|
||||
...auth,
|
||||
loading: false,
|
||||
error: error instanceof Error ? error.message : 'Unable to load authentication state.',
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async function login(input: AuthLoginInput) {
|
||||
const data = await post<{ user: AuthUser }>('/auth/login', {
|
||||
identifier: input.identifier,
|
||||
password: input.password,
|
||||
totpToken: input.totpToken,
|
||||
})
|
||||
auth = { ...auth, user: data.user, setupRequired: false, loading: false, error: null }
|
||||
}
|
||||
|
||||
async function setup(input: AuthSetupInput) {
|
||||
const data = await post<{ user: AuthUser }>('/auth/signup', {
|
||||
email: input.email,
|
||||
username: input.username,
|
||||
password: input.password,
|
||||
})
|
||||
auth = { ...auth, user: data.user, setupRequired: false, loading: false, error: null }
|
||||
}
|
||||
|
||||
const requestReset = () => post('/auth/reset/request')
|
||||
|
||||
async function confirmReset(code: string) {
|
||||
await post('/auth/reset/confirm', { code })
|
||||
window.location.reload()
|
||||
}
|
||||
|
||||
async function logout() {
|
||||
try {
|
||||
await post('/auth/logout')
|
||||
auth.user = null
|
||||
} catch (error) {
|
||||
auth.error = error instanceof Error ? error.message : 'Logout failed.'
|
||||
}
|
||||
}
|
||||
|
||||
async function updateProfile(input: ProfileUpdateInput) {
|
||||
const data = await put<{ user: AuthUser }>('/auth/me', input)
|
||||
auth = { ...auth, user: data.user, error: null }
|
||||
}
|
||||
|
||||
async function listUsers(): Promise<ManagedUser[]> {
|
||||
return get<ManagedUser[]>('/api/auth/users')
|
||||
}
|
||||
|
||||
async function createUser(input: UserCreateInput): Promise<void | ManagedUser> {
|
||||
return post<ManagedUser>('/api/auth/users', input)
|
||||
}
|
||||
|
||||
async function updateUser(id: UserId, input: UserUpdateInput): Promise<void | ManagedUser> {
|
||||
return put<ManagedUser>(`/api/auth/users/${encodeURIComponent(String(id))}`, input)
|
||||
}
|
||||
|
||||
async function deleteUser(id: UserId): Promise<void> {
|
||||
await del<{ ok: boolean }>(`/api/auth/users/${encodeURIComponent(String(id))}`)
|
||||
}
|
||||
|
||||
async function updateLoginRequired(loginRequired: boolean) {
|
||||
await put<{ loginRequired: boolean }>('/api/auth/access', { loginRequired })
|
||||
auth = { ...auth, authRequired: loginRequired }
|
||||
}
|
||||
|
||||
onMount(() => {
|
||||
void loadAuth()
|
||||
})
|
||||
|
||||
$effect(() => {
|
||||
if (page.url.pathname === '/settings') settingsOpen = true
|
||||
if (page.url.pathname === '/about') aboutOpen = true
|
||||
})
|
||||
</script>
|
||||
|
||||
{#if auth.loading || auth.error || auth.setupRequired || (auth.authRequired && !auth.user)}
|
||||
<AuthPage
|
||||
{app}
|
||||
setupRequired={auth.setupRequired}
|
||||
loading={auth.loading}
|
||||
error={auth.error || ''}
|
||||
onLogin={login}
|
||||
onSetup={setup}
|
||||
onRequestReset={requestReset}
|
||||
onConfirmReset={confirmReset}
|
||||
/>
|
||||
{:else}
|
||||
<div class="sc-root sc-app-shell min-h-screen bg-bg text-fg mediacollection-shell">
|
||||
<NotificationStack />
|
||||
|
||||
<Header
|
||||
brand={app.name}
|
||||
brandHref={homePath}
|
||||
currentPath={page.url.pathname}
|
||||
faviconHref="/favicon.svg"
|
||||
{navItems}
|
||||
onAbout={openAbout}
|
||||
onAdmin={isAdmin ? openAdmin : undefined}
|
||||
onLogout={logout}
|
||||
onProfile={openProfile}
|
||||
onSettings={openSettings}
|
||||
username={displayName}
|
||||
/>
|
||||
|
||||
<main class="mx-auto w-full max-w-7xl px-4 pt-4 pb-8">
|
||||
<PageHeader
|
||||
title={activeNavItem?.label || app.name}
|
||||
description={activeNavItem?.description || app.description}
|
||||
actions={pageActions.snippet ?? undefined}
|
||||
/>
|
||||
{@render children?.()}
|
||||
</main>
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
<SettingsDialog bind:open={settingsOpen} onClose={closeSettings} />
|
||||
<AdminDialog
|
||||
bind:open={adminOpen}
|
||||
{currentRole}
|
||||
{currentUserId}
|
||||
onListUsers={listUsers}
|
||||
onCreateUser={createUser}
|
||||
onUpdateUser={updateUser}
|
||||
onDeleteUser={deleteUser}
|
||||
loginRequired={auth.authRequired}
|
||||
onLoginRequiredChange={updateLoginRequired}
|
||||
/>
|
||||
<AboutDialog bind:open={aboutOpen} brand={app.name} description={app.description} onClose={closeAbout}>
|
||||
{#snippet icon()}
|
||||
<ProjectIcon icon={app.icon} class="size-8 text-primary" />
|
||||
{/snippet}
|
||||
<AboutWorkspace />
|
||||
</AboutDialog>
|
||||
<ProfileDialog
|
||||
bind:open={profileOpen}
|
||||
currentEmail={auth.user?.email || ''}
|
||||
currentUsername={auth.user?.username || ''}
|
||||
onSave={updateProfile}
|
||||
/>
|
||||
|
||||
<style>
|
||||
/* The shared component library (header, page title box, dialogs, buttons, ...) otherwise
|
||||
renders in its own generic default palette instead of this app's own branding - remap its
|
||||
--sc-* tokens onto this app's own --color-* palette so every shared component follows suit.
|
||||
--sc-secondary is a subtle tinted-surface color for low-emphasis buttons, a different role
|
||||
than this app's own saturated --color-secondary, so it's derived instead of mapped directly. */
|
||||
:global(.mediacollection-shell) {
|
||||
--sc-bg: var(--color-bg);
|
||||
--sc-surface: var(--color-surface);
|
||||
--sc-surface-raised: var(--color-surface);
|
||||
--sc-surface-hover: var(--color-surface-hover);
|
||||
--sc-border: var(--color-border);
|
||||
--sc-border-strong: var(--color-border);
|
||||
--sc-fg: var(--color-fg);
|
||||
--sc-muted-fg: var(--color-muted-fg);
|
||||
--sc-subtle-fg: var(--color-muted-fg);
|
||||
--sc-primary: var(--color-primary);
|
||||
--sc-primary-hover: var(--color-secondary);
|
||||
--sc-primary-fg: var(--color-primary-fg);
|
||||
--sc-secondary: color-mix(in srgb, var(--color-primary) 12%, var(--color-surface));
|
||||
--sc-secondary-hover: color-mix(in srgb, var(--color-primary) 20%, var(--color-surface));
|
||||
--sc-secondary-fg: var(--color-fg);
|
||||
--sc-accent: var(--color-accent);
|
||||
--sc-accent-fg: var(--color-accent-fg);
|
||||
--sc-danger: var(--color-danger);
|
||||
--sc-danger-hover: color-mix(in srgb, var(--color-danger) 90%, black);
|
||||
--sc-danger-fg: var(--color-danger-fg);
|
||||
--sc-success: var(--color-success);
|
||||
--sc-success-fg: var(--color-success-fg);
|
||||
--sc-warning: var(--color-warning);
|
||||
--sc-warning-fg: var(--color-warning-fg);
|
||||
--sc-ring: var(--color-ring);
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,43 @@
|
||||
<script lang="ts">
|
||||
import {
|
||||
AuthPage as SharedAuthPage,
|
||||
type AuthLoginInput,
|
||||
type AuthResetConfirm,
|
||||
type AuthResetRequest,
|
||||
type AuthSetupInput,
|
||||
} from '@gabriel20xx/web-ui'
|
||||
import type { AppConfig } from '$lib/types'
|
||||
|
||||
let {
|
||||
app,
|
||||
error = '',
|
||||
loading = false,
|
||||
onConfirmReset,
|
||||
onLogin,
|
||||
onRequestReset,
|
||||
onSetup,
|
||||
setupRequired,
|
||||
}: {
|
||||
app: AppConfig
|
||||
error?: string
|
||||
loading?: boolean
|
||||
onConfirmReset: AuthResetConfirm
|
||||
onLogin: (input: AuthLoginInput) => void | Promise<void>
|
||||
onRequestReset: AuthResetRequest
|
||||
onSetup: (input: AuthSetupInput) => void | Promise<void>
|
||||
setupRequired: boolean
|
||||
} = $props()
|
||||
</script>
|
||||
|
||||
<SharedAuthPage
|
||||
brand={app.name}
|
||||
tagline={app.eyebrow}
|
||||
{setupRequired}
|
||||
{loading}
|
||||
{error}
|
||||
showTotp
|
||||
{onLogin}
|
||||
{onSetup}
|
||||
{onRequestReset}
|
||||
{onConfirmReset}
|
||||
/>
|
||||
@@ -0,0 +1,14 @@
|
||||
<script lang="ts">
|
||||
import { Inbox } from '@lucide/svelte'
|
||||
let { title, message }: { title: string; message: string } = $props()
|
||||
</script>
|
||||
|
||||
<div
|
||||
class="flex min-h-40 flex-col items-center justify-center gap-3 rounded-lg border border-dashed border-border bg-surface/50 px-5 py-8 text-center"
|
||||
>
|
||||
<Inbox class="size-8 text-muted-fg" />
|
||||
<div>
|
||||
<p class="text-sm font-medium text-fg">{title}</p>
|
||||
<p class="mt-1 max-w-sm text-xs text-muted-fg">{message}</p>
|
||||
</div>
|
||||
</div>
|
||||
@@ -0,0 +1,352 @@
|
||||
<script lang="ts">
|
||||
import { ArrowDown, ArrowRight, ChevronDown, FileCog, Image as ImageIcon, Search, Sparkles } from '@lucide/svelte'
|
||||
import Badge from '$lib/components/ui/badge.svelte'
|
||||
import { cn } from '$lib/utils/cn'
|
||||
|
||||
type StageStatus = { pending: number; processing: number; processed: number; errors: number; active: boolean }
|
||||
type AiStage = { key: string; label: string; model: string; enabled: boolean }
|
||||
type StageErrorItem = { filePath: string; error: string }
|
||||
type StageKey = 'metadata' | 'thumbnails' | 'analyze'
|
||||
|
||||
let {
|
||||
discovered,
|
||||
discoveredLabel,
|
||||
metadataEnabled,
|
||||
metadataStatus,
|
||||
metadataDescription,
|
||||
metadataDetails,
|
||||
onToggleMetadata,
|
||||
thumbnailsSupported,
|
||||
thumbnailsEnabled,
|
||||
thumbnailsStatus,
|
||||
thumbnailsDescription,
|
||||
thumbnailsDetails,
|
||||
onToggleThumbnails,
|
||||
aiStages,
|
||||
modelOptions,
|
||||
hasAiModel,
|
||||
analysisStatus,
|
||||
onToggleStage,
|
||||
onModelChange,
|
||||
onRetryErrors,
|
||||
onShowErrors,
|
||||
disabled = false,
|
||||
}: {
|
||||
discovered: number
|
||||
discoveredLabel: string
|
||||
metadataEnabled: boolean
|
||||
metadataStatus: StageStatus
|
||||
metadataDescription: string
|
||||
metadataDetails: string
|
||||
onToggleMetadata: (enabled: boolean) => void
|
||||
thumbnailsSupported: boolean
|
||||
thumbnailsEnabled: boolean
|
||||
thumbnailsStatus: StageStatus
|
||||
thumbnailsDescription: string
|
||||
thumbnailsDetails: string
|
||||
onToggleThumbnails: (enabled: boolean) => void
|
||||
aiStages: AiStage[]
|
||||
modelOptions: string[]
|
||||
hasAiModel: boolean
|
||||
analysisStatus: StageStatus
|
||||
onToggleStage: (stage: string, enabled: boolean) => void
|
||||
onModelChange: (stage: string, model: string) => void
|
||||
onRetryErrors: (stage: StageKey) => void
|
||||
onShowErrors: (stage: StageKey) => Promise<StageErrorItem[]>
|
||||
disabled?: boolean
|
||||
} = $props()
|
||||
|
||||
// Short, model-agnostic descriptions of what each AI backend actually produces - shown in the
|
||||
// AI analysis stage's expandable details rather than making users guess from the model name.
|
||||
const MODEL_DETAILS: Record<string, string> = {
|
||||
nsfwjs: 'NSFWJS - classifies the frame as safe or not-safe-for-work.',
|
||||
wdtagger: 'WD Tagger - predicts weighted Danbooru-style content tags.',
|
||||
faceapi: 'face-api.js - detects faces and estimates apparent gender.',
|
||||
onnxage: 'ONNX Age - estimates the apparent age of detected faces.',
|
||||
florence2: 'Florence-2 - vision-language model used for captions and descriptions.',
|
||||
laplacian: 'Laplacian variance - measures image sharpness/blur as a quality signal.',
|
||||
whisper: 'Whisper - transcribes spoken audio to text.',
|
||||
clap: 'CLAP - audio-text embedding model used for zero-shot audio tagging.',
|
||||
}
|
||||
|
||||
const showAiAnalysis = $derived(aiStages.length > 0)
|
||||
const aiActive = $derived(hasAiModel && aiStages.some((stage) => stage.enabled))
|
||||
|
||||
let metadataDetailsOpen = $state(false)
|
||||
let thumbnailsDetailsOpen = $state(false)
|
||||
let aiDetailsOpen = $state(false)
|
||||
|
||||
// Keyed by stage so each of the three error panels (metadata/thumbnails/analyze) opens,
|
||||
// loads, and closes independently. Errors are fetched on open rather than eagerly for every
|
||||
// stage up front - most stages never have any, and the count alone (already shown) is enough
|
||||
// until the user actually asks to see what failed.
|
||||
let errorPanels = $state<Record<string, { open: boolean; loading: boolean; items: StageErrorItem[] }>>({})
|
||||
|
||||
async function toggleErrors(stage: StageKey) {
|
||||
const current = errorPanels[stage]
|
||||
if (current?.open) {
|
||||
errorPanels = { ...errorPanels, [stage]: { ...current, open: false } }
|
||||
return
|
||||
}
|
||||
errorPanels = { ...errorPanels, [stage]: { open: true, loading: true, items: current?.items ?? [] } }
|
||||
const items = await onShowErrors(stage)
|
||||
errorPanels = { ...errorPanels, [stage]: { open: true, loading: false, items } }
|
||||
}
|
||||
</script>
|
||||
|
||||
{#snippet connector(active: boolean)}
|
||||
<div class="flex items-center justify-center py-1 lg:px-1 lg:py-0">
|
||||
<ArrowDown class={cn('size-5 shrink-0 lg:hidden', active ? 'animate-pulse text-primary' : 'text-muted-fg/40')} />
|
||||
<ArrowRight
|
||||
class={cn('hidden size-5 shrink-0 lg:block', active ? 'animate-pulse text-primary' : 'text-muted-fg/40')}
|
||||
/>
|
||||
</div>
|
||||
{/snippet}
|
||||
|
||||
{#snippet toggle(enabled: boolean, onToggle: (value: boolean) => void, toggleLabel: string)}
|
||||
<label
|
||||
class="mt-auto flex items-center justify-between gap-2 border-t border-border pt-3 text-xs font-medium text-muted-fg"
|
||||
>
|
||||
{toggleLabel}
|
||||
<span
|
||||
class={cn(
|
||||
'relative inline-flex h-6 w-11 shrink-0 items-center rounded-full transition-colors',
|
||||
enabled ? 'bg-primary' : 'bg-border',
|
||||
)}
|
||||
>
|
||||
<input
|
||||
type="checkbox"
|
||||
class="peer absolute inset-0 size-full cursor-pointer opacity-0"
|
||||
checked={enabled}
|
||||
{disabled}
|
||||
aria-label={toggleLabel}
|
||||
onchange={(event) => onToggle((event.currentTarget as HTMLInputElement).checked)}
|
||||
/>
|
||||
<span
|
||||
class={cn(
|
||||
'pointer-events-none inline-block size-4 translate-x-1 rounded-full bg-white shadow transition-transform',
|
||||
enabled && 'translate-x-6',
|
||||
)}
|
||||
></span>
|
||||
</span>
|
||||
</label>
|
||||
{/snippet}
|
||||
|
||||
{#snippet detailsToggle(open: boolean, onClick: () => void)}
|
||||
<button
|
||||
type="button"
|
||||
class="flex items-center gap-1 self-start text-[11px] font-medium text-muted-fg hover:text-fg"
|
||||
onclick={onClick}
|
||||
>
|
||||
<ChevronDown class={cn('size-3 transition-transform', open && 'rotate-180')} />
|
||||
{open ? 'Hide details' : 'Show details'}
|
||||
</button>
|
||||
{/snippet}
|
||||
|
||||
{#snippet statusGrid(status: StageStatus, stage: StageKey, onRetry: () => void)}
|
||||
{@const panel = errorPanels[stage]}
|
||||
<div class="grid grid-cols-3 gap-2 text-center text-xs">
|
||||
<div>
|
||||
<p class="text-base font-semibold text-warning">{status.pending}</p>
|
||||
<p class="text-muted-fg">Pending</p>
|
||||
</div>
|
||||
<div>
|
||||
<p class="text-base font-semibold text-primary">{status.processing}</p>
|
||||
<p class="text-muted-fg">Processing</p>
|
||||
</div>
|
||||
<div>
|
||||
<p class="text-base font-semibold text-success">{status.processed}</p>
|
||||
<p class="text-muted-fg">Processed</p>
|
||||
</div>
|
||||
</div>
|
||||
{#if status.errors > 0}
|
||||
<div class="flex items-center justify-between gap-2 rounded-md bg-danger/10 px-2 py-1.5 text-xs text-danger">
|
||||
<span>{status.errors} error{status.errors === 1 ? '' : 's'}</span>
|
||||
<div class="flex items-center gap-3">
|
||||
<button
|
||||
type="button"
|
||||
class="font-medium underline decoration-dotted hover:text-danger/80 disabled:opacity-50"
|
||||
{disabled}
|
||||
onclick={() => void toggleErrors(stage)}
|
||||
>
|
||||
{panel?.open ? 'Hide text' : 'Show text'}
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
class="font-medium underline decoration-dotted hover:text-danger/80 disabled:opacity-50"
|
||||
{disabled}
|
||||
onclick={onRetry}
|
||||
>
|
||||
Retry
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
{#if panel?.open}
|
||||
<div class="max-h-40 space-y-1 overflow-y-auto rounded-md bg-bg p-2 text-[11px] text-danger">
|
||||
{#if panel.loading}
|
||||
<p class="text-muted-fg">Loading errors…</p>
|
||||
{:else if panel.items.length === 0}
|
||||
<p class="text-muted-fg">No recent error text available.</p>
|
||||
{:else}
|
||||
{#each panel.items as item (item.filePath)}
|
||||
<p><span class="font-medium text-fg">{item.filePath}:</span> {item.error}</p>
|
||||
{/each}
|
||||
{/if}
|
||||
</div>
|
||||
{/if}
|
||||
{/if}
|
||||
{/snippet}
|
||||
|
||||
<div class="flex flex-col lg:flex-row lg:items-stretch">
|
||||
<div
|
||||
class="flex flex-1 flex-col items-center justify-center gap-2 rounded-lg border border-border bg-surface p-4 text-center"
|
||||
>
|
||||
<Search class="size-5 text-muted-fg" />
|
||||
<p class="text-2xl font-semibold text-fg">{discovered}</p>
|
||||
<p class="text-xs font-medium uppercase tracking-wide text-muted-fg">{discoveredLabel} discovered</p>
|
||||
</div>
|
||||
|
||||
{@render connector(metadataStatus.active)}
|
||||
|
||||
<div
|
||||
class={cn(
|
||||
'flex flex-1 flex-col gap-3 rounded-lg border p-4 transition-opacity',
|
||||
metadataEnabled ? 'border-border bg-surface' : 'border-border/60 bg-surface/40 opacity-70',
|
||||
)}
|
||||
>
|
||||
<div class="flex items-center justify-between gap-2">
|
||||
<div class="flex items-center gap-2">
|
||||
<FileCog class="size-4 text-muted-fg" />
|
||||
<span class="text-sm font-semibold text-fg">Metadata</span>
|
||||
</div>
|
||||
{#if metadataStatus.active}
|
||||
<Badge tone="primary" class="animate-pulse">Active</Badge>
|
||||
{:else}
|
||||
<Badge tone="neutral">Idle</Badge>
|
||||
{/if}
|
||||
</div>
|
||||
<p class="text-xs text-muted-fg">{metadataDescription}</p>
|
||||
{@render detailsToggle(metadataDetailsOpen, () => (metadataDetailsOpen = !metadataDetailsOpen))}
|
||||
{#if metadataDetailsOpen}
|
||||
<p class="rounded-md bg-bg p-2 text-[11px] text-muted-fg">{metadataDetails}</p>
|
||||
{/if}
|
||||
{@render statusGrid(metadataStatus, 'metadata', () => onRetryErrors('metadata'))}
|
||||
{@render toggle(metadataEnabled, onToggleMetadata, 'Enabled')}
|
||||
</div>
|
||||
|
||||
{#if thumbnailsSupported}
|
||||
{@render connector(thumbnailsStatus.active)}
|
||||
|
||||
<div
|
||||
class={cn(
|
||||
'flex flex-1 flex-col gap-3 rounded-lg border p-4 transition-opacity',
|
||||
thumbnailsEnabled ? 'border-border bg-surface' : 'border-border/60 bg-surface/40 opacity-70',
|
||||
)}
|
||||
>
|
||||
<div class="flex items-center justify-between gap-2">
|
||||
<div class="flex items-center gap-2">
|
||||
<ImageIcon class="size-4 text-muted-fg" />
|
||||
<span class="text-sm font-semibold text-fg">Thumbnails</span>
|
||||
</div>
|
||||
{#if thumbnailsStatus.active}
|
||||
<Badge tone="primary" class="animate-pulse">Active</Badge>
|
||||
{:else}
|
||||
<Badge tone="neutral">Idle</Badge>
|
||||
{/if}
|
||||
</div>
|
||||
<p class="text-xs text-muted-fg">{thumbnailsDescription}</p>
|
||||
{@render detailsToggle(thumbnailsDetailsOpen, () => (thumbnailsDetailsOpen = !thumbnailsDetailsOpen))}
|
||||
{#if thumbnailsDetailsOpen}
|
||||
<p class="rounded-md bg-bg p-2 text-[11px] text-muted-fg">{thumbnailsDetails}</p>
|
||||
{/if}
|
||||
{@render statusGrid(thumbnailsStatus, 'thumbnails', () => onRetryErrors('thumbnails'))}
|
||||
{@render toggle(thumbnailsEnabled, onToggleThumbnails, 'Enabled')}
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
{#if showAiAnalysis}
|
||||
{@render connector(analysisStatus.active)}
|
||||
|
||||
<div
|
||||
class={cn(
|
||||
'flex flex-1 flex-col gap-3 rounded-lg border p-4 transition-opacity',
|
||||
aiActive ? 'border-border bg-surface' : 'border-border/60 bg-surface/40 opacity-70',
|
||||
)}
|
||||
>
|
||||
<div class="flex items-center justify-between gap-2">
|
||||
<div class="flex items-center gap-2">
|
||||
<Sparkles class="size-4 text-muted-fg" />
|
||||
<span class="text-sm font-semibold text-fg">AI analysis</span>
|
||||
</div>
|
||||
{#if analysisStatus.active}
|
||||
<Badge tone="primary" class="animate-pulse">Active</Badge>
|
||||
{:else}
|
||||
<Badge tone="neutral">Idle</Badge>
|
||||
{/if}
|
||||
</div>
|
||||
<p class="text-xs text-muted-fg">
|
||||
{hasAiModel
|
||||
? 'Toggle a task on, then choose which model handles it. Runs as part of the pipeline alongside metadata and thumbnails.'
|
||||
: 'No AI model is available for this media type yet.'}
|
||||
</p>
|
||||
{#if hasAiModel}
|
||||
{@render detailsToggle(aiDetailsOpen, () => (aiDetailsOpen = !aiDetailsOpen))}
|
||||
{#if aiDetailsOpen}
|
||||
<div class="flex flex-col gap-1 rounded-md bg-bg p-2 text-[11px] text-muted-fg">
|
||||
{#each aiStages as stage (stage.key)}
|
||||
<p><span class="font-medium text-fg">{stage.label}:</span> {MODEL_DETAILS[stage.model] ?? 'No description available for this model.'}</p>
|
||||
{/each}
|
||||
</div>
|
||||
{/if}
|
||||
{/if}
|
||||
<div class="flex flex-col gap-2">
|
||||
{#each aiStages as stage (stage.key)}
|
||||
<div
|
||||
class={cn(
|
||||
'flex flex-col gap-2 rounded-md border p-2 transition-opacity',
|
||||
stage.enabled ? 'border-border' : 'border-border/60 opacity-70',
|
||||
)}
|
||||
>
|
||||
<div class="flex items-center justify-between gap-2 text-[11px] font-medium text-muted-fg">
|
||||
{stage.label}
|
||||
<span
|
||||
class={cn(
|
||||
'relative inline-flex h-5 w-9 shrink-0 items-center rounded-full transition-colors',
|
||||
stage.enabled ? 'bg-primary' : 'bg-border',
|
||||
)}
|
||||
>
|
||||
<input
|
||||
type="checkbox"
|
||||
class="peer absolute inset-0 size-full cursor-pointer opacity-0"
|
||||
checked={stage.enabled}
|
||||
disabled={!hasAiModel || disabled}
|
||||
aria-label={`${stage.label} enabled`}
|
||||
onchange={(event) => onToggleStage(stage.key, (event.currentTarget as HTMLInputElement).checked)}
|
||||
/>
|
||||
<span
|
||||
class={cn(
|
||||
'pointer-events-none inline-block size-3.5 translate-x-1 rounded-full bg-white shadow transition-transform',
|
||||
stage.enabled && 'translate-x-4',
|
||||
)}
|
||||
></span>
|
||||
</span>
|
||||
</div>
|
||||
<select
|
||||
value={stage.model}
|
||||
disabled={!hasAiModel || disabled || !stage.enabled}
|
||||
onchange={(event) => onModelChange(stage.key, (event.currentTarget as HTMLSelectElement).value)}
|
||||
class="h-9 w-full rounded-md border border-border bg-surface px-2 text-xs font-normal text-fg outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:opacity-50"
|
||||
>
|
||||
{#each modelOptions as model (model)}
|
||||
<option value={model}>{model}</option>
|
||||
{/each}
|
||||
</select>
|
||||
</div>
|
||||
{/each}
|
||||
</div>
|
||||
{#if hasAiModel}
|
||||
{@render statusGrid(analysisStatus, 'analyze', () => onRetryErrors('analyze'))}
|
||||
{/if}
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
@@ -0,0 +1,20 @@
|
||||
<script lang="ts">
|
||||
import { Image, MonitorPlay, Play, ScanSearch, Server, Settings2, ShieldCheck, WandSparkles } from '@lucide/svelte'
|
||||
import type { ProjectIconName } from '$lib/types'
|
||||
|
||||
const icons: Record<ProjectIconName, typeof Play> = {
|
||||
image: Image,
|
||||
'monitor-play': MonitorPlay,
|
||||
play: Play,
|
||||
'scan-search': ScanSearch,
|
||||
server: Server,
|
||||
'settings-2': Settings2,
|
||||
'shield-check': ShieldCheck,
|
||||
'wand-sparkles': WandSparkles,
|
||||
}
|
||||
|
||||
let { icon, class: className = '' }: { icon: ProjectIconName; class?: string } = $props()
|
||||
const Icon = $derived(icons[icon])
|
||||
</script>
|
||||
|
||||
<Icon class={className} aria-hidden="true" />
|
||||
@@ -0,0 +1,10 @@
|
||||
<script lang="ts">
|
||||
let { title, description = '' }: { title: string; description?: string } = $props()
|
||||
</script>
|
||||
|
||||
<div class="flex items-start justify-between gap-3">
|
||||
<div>
|
||||
<h2 class="text-sm font-semibold text-fg">{title}</h2>
|
||||
{#if description}<p class="mt-1 text-xs text-muted-fg">{description}</p>{/if}
|
||||
</div>
|
||||
</div>
|
||||
@@ -0,0 +1,97 @@
|
||||
<script lang="ts">
|
||||
import { Moon, Sun, SunMoon } from '@lucide/svelte'
|
||||
import Button from '$lib/components/ui/button.svelte'
|
||||
import { currentLanguage, languages, setLanguage } from '$lib/language.svelte'
|
||||
import { themeState } from '$lib/theme.svelte'
|
||||
|
||||
let {
|
||||
open = $bindable(false),
|
||||
onClose,
|
||||
}: {
|
||||
open?: boolean
|
||||
onClose?: () => void
|
||||
} = $props()
|
||||
|
||||
const languageItems = languages.map((language) => ({ value: language.id, label: language.label }))
|
||||
let wasOpen = false
|
||||
|
||||
$effect(() => {
|
||||
if (wasOpen && !open) onClose?.()
|
||||
wasOpen = open
|
||||
})
|
||||
</script>
|
||||
|
||||
{#if open}
|
||||
<div
|
||||
class="fixed inset-0 z-50 grid place-items-center bg-black/70 p-4 backdrop-blur-sm"
|
||||
role="presentation"
|
||||
onclick={(event) => {
|
||||
if (event.target === event.currentTarget) open = false
|
||||
}}
|
||||
>
|
||||
<div
|
||||
class="w-full max-w-lg rounded-xl border border-border bg-surface p-6 shadow-xl"
|
||||
role="dialog"
|
||||
aria-modal="true"
|
||||
aria-label="Settings"
|
||||
tabindex="-1"
|
||||
>
|
||||
<div class="flex items-start justify-between gap-4">
|
||||
<h2 class="text-xl font-semibold">Settings</h2>
|
||||
<button
|
||||
class="rounded-md px-2 py-1 text-2xl leading-none text-muted-fg hover:bg-surface-hover hover:text-fg"
|
||||
type="button"
|
||||
aria-label="Close"
|
||||
onclick={() => (open = false)}>×</button
|
||||
>
|
||||
</div>
|
||||
|
||||
<div class="mt-6 space-y-5">
|
||||
<div>
|
||||
<span class="mb-2 block text-sm font-medium">Theme</span>
|
||||
<div class="flex w-full rounded-md border border-border p-1">
|
||||
<Button
|
||||
type="button"
|
||||
variant={themeState.mode === 'light' ? 'secondary' : 'ghost'}
|
||||
size="sm"
|
||||
class="flex-1 gap-1.5"
|
||||
onclick={() => themeState.setMode('light')}
|
||||
>
|
||||
<Sun class="size-4" />
|
||||
Light
|
||||
</Button>
|
||||
<Button
|
||||
type="button"
|
||||
variant={themeState.mode === 'dark' ? 'secondary' : 'ghost'}
|
||||
size="sm"
|
||||
class="flex-1 gap-1.5"
|
||||
onclick={() => themeState.setMode('dark')}
|
||||
>
|
||||
<Moon class="size-4" />
|
||||
Dark
|
||||
</Button>
|
||||
<Button
|
||||
type="button"
|
||||
variant={themeState.mode === 'system' ? 'secondary' : 'ghost'}
|
||||
size="sm"
|
||||
class="flex-1 gap-1.5"
|
||||
onclick={() => themeState.setMode('system')}
|
||||
>
|
||||
<SunMoon class="size-4" />
|
||||
System
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<label class="block">
|
||||
<span class="mb-2 block text-sm font-medium">Language</span>
|
||||
<select class="field" value={currentLanguage()} onchange={(event) => setLanguage(event.currentTarget.value)}>
|
||||
{#each languageItems as item (item.value)}
|
||||
<option value={item.value}>{item.label}</option>
|
||||
{/each}
|
||||
</select>
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
@@ -0,0 +1,102 @@
|
||||
<script lang="ts">
|
||||
import { AlertCircle, AlertTriangle, CheckCircle2, CircleHelp, LoaderCircle, RefreshCw, X } from '@lucide/svelte'
|
||||
import Button from '$lib/components/ui/button.svelte'
|
||||
import type { StatusProbe, StatusSnapshot } from '$lib/status'
|
||||
|
||||
let {
|
||||
open = $bindable(false),
|
||||
status,
|
||||
onRefresh,
|
||||
}: {
|
||||
open?: boolean
|
||||
status: StatusSnapshot
|
||||
onRefresh: () => Promise<void>
|
||||
} = $props()
|
||||
|
||||
const levelLabel = {
|
||||
checking: 'Checking',
|
||||
healthy: 'Healthy',
|
||||
degraded: 'Degraded',
|
||||
offline: 'Offline',
|
||||
}
|
||||
|
||||
const levelClass = {
|
||||
checking: 'text-muted-fg',
|
||||
healthy: 'text-success',
|
||||
degraded: 'text-warning',
|
||||
offline: 'text-danger',
|
||||
}
|
||||
|
||||
function probeLabel(probe: StatusProbe | null) {
|
||||
if (!probe) return 'Not checked'
|
||||
if (probe.ok) return 'OK'
|
||||
if (probe.error) return probe.error
|
||||
return probe.httpStatus ? `HTTP ${probe.httpStatus}` : 'Unavailable'
|
||||
}
|
||||
</script>
|
||||
|
||||
{#if open}
|
||||
<div
|
||||
class="fixed inset-0 z-50 grid place-items-center bg-black/70 px-4"
|
||||
role="presentation"
|
||||
onclick={(event) => event.target === event.currentTarget && (open = false)}
|
||||
>
|
||||
<div
|
||||
class="w-full max-w-lg rounded-xl border border-border bg-bg p-6 text-fg shadow-2xl"
|
||||
role="dialog"
|
||||
aria-modal="true"
|
||||
aria-labelledby="status-dialog-title"
|
||||
>
|
||||
<div class="mb-5 flex items-start justify-between gap-3">
|
||||
<div>
|
||||
<h2 id="status-dialog-title" class="text-xl font-semibold">Service status</h2>
|
||||
<p class="mt-1 text-sm text-muted-fg">Live liveness and database readiness checks.</p>
|
||||
</div>
|
||||
<Button variant="ghost" size="icon" aria-label="Close" onclick={() => (open = false)}>
|
||||
<X class="size-4" />
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
<div class="mb-5 flex items-center gap-3 rounded-lg border border-border bg-surface p-3" aria-live="polite">
|
||||
{#if status.loading && status.level === 'checking'}
|
||||
<LoaderCircle class="size-5 animate-spin text-muted-fg" />
|
||||
{:else if status.level === 'healthy'}
|
||||
<CheckCircle2 class="size-5 text-success" />
|
||||
{:else if status.level === 'degraded'}
|
||||
<AlertTriangle class="size-5 text-warning" />
|
||||
{:else if status.level === 'offline'}
|
||||
<AlertCircle class="size-5 text-danger" />
|
||||
{:else}
|
||||
<CircleHelp class="size-5 text-muted-fg" />
|
||||
{/if}
|
||||
<span class={`font-medium ${levelClass[status.level]}`}>{levelLabel[status.level]}</span>
|
||||
{#if status.checkedAt}
|
||||
<span class="ml-auto text-xs text-muted-fg">{new Date(status.checkedAt).toLocaleTimeString()}</span>
|
||||
{/if}
|
||||
</div>
|
||||
|
||||
<div class="space-y-2 text-sm">
|
||||
{#each [{ label: 'Liveness', probe: status.health }, { label: 'Readiness / database', probe: status.readiness }] as item (item.label)}
|
||||
<div class="flex items-center justify-between gap-4 rounded-md border border-border px-3 py-2">
|
||||
<span>{item.label}</span>
|
||||
<span class={item.probe?.ok ? 'text-success' : 'text-danger'}>{probeLabel(item.probe)}</span>
|
||||
</div>
|
||||
{/each}
|
||||
</div>
|
||||
|
||||
{#if status.health?.service || status.readiness?.service}
|
||||
<p class="mt-4 text-xs text-muted-fg">
|
||||
Service: {status.health?.service || status.readiness?.service}
|
||||
</p>
|
||||
{/if}
|
||||
|
||||
<div class="mt-6 flex justify-end gap-2">
|
||||
<Button variant="outline" disabled={status.loading} onclick={() => void onRefresh()}>
|
||||
<RefreshCw class={status.loading ? 'animate-spin' : ''} />
|
||||
Refresh
|
||||
</Button>
|
||||
<Button variant="secondary" onclick={() => (open = false)}>Dismiss</Button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
@@ -0,0 +1,97 @@
|
||||
<script lang="ts">
|
||||
import { AlertCircle, AlertTriangle, CheckCircle2, CircleHelp, LoaderCircle } from '@lucide/svelte'
|
||||
import { onMount } from 'svelte'
|
||||
import Button from '$lib/components/ui/button.svelte'
|
||||
import StatusDialog from '$lib/components/StatusDialog.svelte'
|
||||
import type { StatusProbe, StatusSnapshot } from '$lib/status'
|
||||
|
||||
const initialStatus: StatusSnapshot = {
|
||||
level: 'checking',
|
||||
health: null,
|
||||
readiness: null,
|
||||
checkedAt: null,
|
||||
loading: false,
|
||||
}
|
||||
|
||||
let status = $state<StatusSnapshot>(initialStatus)
|
||||
let open = $state(false)
|
||||
let requestInFlight = false
|
||||
|
||||
async function probe(path: string): Promise<StatusProbe> {
|
||||
try {
|
||||
const response = await fetch(path, {
|
||||
credentials: 'include',
|
||||
headers: { Accept: 'application/json' },
|
||||
})
|
||||
const payload = (await response.json().catch(() => null)) as {
|
||||
ok?: boolean
|
||||
service?: string
|
||||
error?: string
|
||||
} | null
|
||||
return {
|
||||
path,
|
||||
ok: response.ok && payload?.ok !== false,
|
||||
httpStatus: response.status,
|
||||
service: payload?.service || null,
|
||||
error: response.ok ? null : payload?.error || response.statusText || `HTTP ${response.status}`,
|
||||
}
|
||||
} catch (error) {
|
||||
return {
|
||||
path,
|
||||
ok: false,
|
||||
httpStatus: null,
|
||||
service: null,
|
||||
error: error instanceof Error ? error.message : 'Unavailable',
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async function refresh() {
|
||||
if (requestInFlight) return
|
||||
requestInFlight = true
|
||||
status = { ...status, loading: true, level: status.health || status.readiness ? status.level : 'checking' }
|
||||
|
||||
try {
|
||||
const [health, readiness] = await Promise.all([probe('/healthz'), probe('/ready')])
|
||||
const level = health.ok && readiness.ok ? 'healthy' : health.ok ? 'degraded' : 'offline'
|
||||
status = {
|
||||
level,
|
||||
health,
|
||||
readiness,
|
||||
checkedAt: new Date().toISOString(),
|
||||
loading: false,
|
||||
}
|
||||
} finally {
|
||||
requestInFlight = false
|
||||
if (status.loading) status = { ...status, loading: false }
|
||||
}
|
||||
}
|
||||
|
||||
onMount(() => {
|
||||
void refresh()
|
||||
const timer = window.setInterval(() => void refresh(), 15_000)
|
||||
return () => window.clearInterval(timer)
|
||||
})
|
||||
</script>
|
||||
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
aria-label="Service status"
|
||||
title={`Service status: ${status.level}`}
|
||||
onclick={() => (open = true)}
|
||||
>
|
||||
{#if status.loading && status.level === 'checking'}
|
||||
<LoaderCircle class="size-5 animate-spin text-muted-fg" />
|
||||
{:else if status.level === 'healthy'}
|
||||
<CheckCircle2 class="size-5 text-success" />
|
||||
{:else if status.level === 'degraded'}
|
||||
<AlertTriangle class="size-5 text-warning" />
|
||||
{:else if status.level === 'offline'}
|
||||
<AlertCircle class="size-5 text-danger" />
|
||||
{:else}
|
||||
<CircleHelp class="size-5 text-muted-fg" />
|
||||
{/if}
|
||||
</Button>
|
||||
|
||||
<StatusDialog bind:open {status} onRefresh={refresh} />
|
||||
@@ -0,0 +1,87 @@
|
||||
<script lang="ts">
|
||||
import { page } from '$app/state'
|
||||
import { getAppConfig, getPanelForPath, getPathForPanel } from '$lib/app-config'
|
||||
import AnalyzerWorkspace from '$lib/features/AnalyzerWorkspace.svelte'
|
||||
import ConfigWorkspace from '$lib/features/ConfigWorkspace.svelte'
|
||||
import DesktopWorkspace from '$lib/features/DesktopWorkspace.svelte'
|
||||
import FeedWorkspace from '$lib/features/FeedWorkspace.svelte'
|
||||
import KioskWorkspace from '$lib/features/KioskWorkspace.svelte'
|
||||
import MediaTypePipeline from '$lib/features/MediaTypePipeline.svelte'
|
||||
import ModeratorWorkspace from '$lib/features/ModeratorWorkspace.svelte'
|
||||
import ServantWorkspace from '$lib/features/ServantWorkspace.svelte'
|
||||
import TagsWorkspace from '$lib/features/TagsWorkspace.svelte'
|
||||
import VideoPage from '$lib/features/VideoPage.svelte'
|
||||
import ToolsWorkspace from '$lib/features/ToolsWorkspace.svelte'
|
||||
import ViewerWorkspace from '$lib/features/ViewerWorkspace.svelte'
|
||||
|
||||
const analyzerMediaTypePanels: Record<
|
||||
string,
|
||||
{ mediaType: 'image' | 'video' | 'audio' | 'funscript'; label: string }
|
||||
> = {
|
||||
images: { mediaType: 'image', label: 'Images' },
|
||||
videos: { mediaType: 'video', label: 'Videos' },
|
||||
audios: { mediaType: 'audio', label: 'Audios' },
|
||||
funscripts: { mediaType: 'funscript', label: 'Funscripts' },
|
||||
}
|
||||
|
||||
const app = getAppConfig(__MEDIA_APP__)
|
||||
const requestedPanel = $derived(page.url.searchParams.get('panel') || getPanelForPath(app, page.url.pathname))
|
||||
const panel = $derived(app.id === 'viewer' && requestedPanel === 'search' ? 'library' : requestedPanel)
|
||||
const videoId = $derived(app.id === 'viewer' ? getVideoId(page.url.pathname) : '')
|
||||
|
||||
function getVideoId(pathname: string) {
|
||||
const match = pathname.match(/^\/video\/([^/]+)\/?$/i)
|
||||
if (!match?.[1]) return ''
|
||||
try {
|
||||
return decodeURIComponent(match[1])
|
||||
} catch {
|
||||
return ''
|
||||
}
|
||||
}
|
||||
|
||||
$effect(() => {
|
||||
const legacyPanel = page.url.searchParams.get('panel')
|
||||
if (typeof window === 'undefined' || !legacyPanel || !app.nav.some((item) => item.panel === legacyPanel)) {
|
||||
return
|
||||
}
|
||||
|
||||
const query = Array.from(page.url.searchParams.entries())
|
||||
.filter(([key]) => key !== 'panel')
|
||||
.map(([key, value]) => `${encodeURIComponent(key)}=${encodeURIComponent(value)}`)
|
||||
.join('&')
|
||||
const target = `${getPathForPanel(app, legacyPanel)}${query ? `?${query}` : ''}`
|
||||
const current = `${page.url.pathname}${page.url.search}`
|
||||
if (target !== current) {
|
||||
window.location.replace(target)
|
||||
}
|
||||
})
|
||||
</script>
|
||||
|
||||
{#if app.id === 'viewer' && videoId}
|
||||
<VideoPage id={videoId} />
|
||||
{:else if app.id === 'viewer' && panel === 'view'}
|
||||
<FeedWorkspace />
|
||||
{:else if app.id === 'viewer' && panel === 'tags'}
|
||||
<TagsWorkspace />
|
||||
{:else if app.id === 'viewer'}
|
||||
<ViewerWorkspace {panel} />
|
||||
{:else if app.id === 'analyzer' && panel in analyzerMediaTypePanels}
|
||||
<MediaTypePipeline
|
||||
mediaType={analyzerMediaTypePanels[panel].mediaType}
|
||||
label={analyzerMediaTypePanels[panel].label}
|
||||
/>
|
||||
{:else if app.id === 'tools'}
|
||||
<ToolsWorkspace {panel} />
|
||||
{:else if app.id === 'analyzer'}
|
||||
<AnalyzerWorkspace {panel} />
|
||||
{:else if app.id === 'config'}
|
||||
<ConfigWorkspace {panel} />
|
||||
{:else if app.id === 'moderator'}
|
||||
<ModeratorWorkspace {panel} />
|
||||
{:else if app.id === 'kiosk'}
|
||||
<KioskWorkspace {panel} />
|
||||
{:else if app.id === 'servant'}
|
||||
<ServantWorkspace {panel} />
|
||||
{:else}
|
||||
<DesktopWorkspace {panel} />
|
||||
{/if}
|
||||
@@ -0,0 +1,32 @@
|
||||
<script lang="ts">
|
||||
import type { HTMLAttributes } from 'svelte/elements'
|
||||
import { cn } from '$lib/utils/cn'
|
||||
|
||||
let {
|
||||
class: className,
|
||||
tone = 'neutral',
|
||||
children,
|
||||
...rest
|
||||
}: HTMLAttributes<HTMLSpanElement> & {
|
||||
tone?: 'neutral' | 'primary' | 'success' | 'warning' | 'danger'
|
||||
children?: import('svelte').Snippet
|
||||
} = $props()
|
||||
const toneClasses = {
|
||||
neutral: 'border-border bg-surface-hover text-muted-fg',
|
||||
primary: 'border-primary/30 bg-primary/15 text-primary',
|
||||
success: 'border-success/30 bg-success/15 text-success',
|
||||
warning: 'border-warning/30 bg-warning/15 text-warning',
|
||||
danger: 'border-danger/30 bg-danger/15 text-danger',
|
||||
}
|
||||
</script>
|
||||
|
||||
<span
|
||||
class={cn(
|
||||
'inline-flex items-center rounded-full border px-2 py-0.5 text-xs font-medium',
|
||||
toneClasses[tone],
|
||||
className,
|
||||
)}
|
||||
{...rest}
|
||||
>
|
||||
{@render children?.()}
|
||||
</span>
|
||||
@@ -0,0 +1,43 @@
|
||||
<script lang="ts">
|
||||
import { cva, type VariantProps } from 'class-variance-authority'
|
||||
import type { HTMLButtonAttributes } from 'svelte/elements'
|
||||
import { cn } from '$lib/utils/cn'
|
||||
|
||||
export const buttonVariants = cva(
|
||||
'inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-md text-sm font-medium transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:pointer-events-none disabled:opacity-50 [&_svg]:size-4 [&_svg]:shrink-0',
|
||||
{
|
||||
variants: {
|
||||
variant: {
|
||||
default: 'bg-primary text-primary-fg hover:opacity-90',
|
||||
secondary: 'border border-border bg-surface text-fg hover:bg-surface-hover',
|
||||
outline: 'border border-border bg-transparent text-fg hover:bg-surface-hover',
|
||||
ghost: 'text-fg hover:bg-surface-hover',
|
||||
danger: 'bg-danger text-danger-fg hover:opacity-90',
|
||||
success: 'bg-success text-success-fg hover:opacity-90',
|
||||
link: 'text-primary underline-offset-4 hover:underline',
|
||||
},
|
||||
size: {
|
||||
default: 'h-9 px-4 py-2',
|
||||
sm: 'h-8 rounded-md px-3 text-xs',
|
||||
lg: 'h-10 rounded-md px-6',
|
||||
icon: 'h-9 w-9',
|
||||
},
|
||||
},
|
||||
defaultVariants: { variant: 'default', size: 'default' },
|
||||
},
|
||||
)
|
||||
|
||||
type Variant = VariantProps<typeof buttonVariants>
|
||||
let {
|
||||
class: className,
|
||||
variant = 'default',
|
||||
size = 'default',
|
||||
type = 'button',
|
||||
children,
|
||||
...rest
|
||||
}: HTMLButtonAttributes & Variant & { children?: import('svelte').Snippet } = $props()
|
||||
</script>
|
||||
|
||||
<button {type} class={cn(buttonVariants({ variant, size }), className)} {...rest}>
|
||||
{@render children?.()}
|
||||
</button>
|
||||
@@ -0,0 +1,14 @@
|
||||
<script lang="ts">
|
||||
import type { HTMLAttributes } from 'svelte/elements'
|
||||
import { cn } from '$lib/utils/cn'
|
||||
|
||||
let {
|
||||
class: className,
|
||||
children,
|
||||
...rest
|
||||
}: HTMLAttributes<HTMLDivElement> & { children?: import('svelte').Snippet } = $props()
|
||||
</script>
|
||||
|
||||
<div class={cn('rounded-lg border border-border bg-surface p-4 shadow-sm', className)} {...rest}>
|
||||
{@render children?.()}
|
||||
</div>
|
||||
@@ -0,0 +1,32 @@
|
||||
<script lang="ts">
|
||||
import { cn } from '$lib/utils/cn'
|
||||
|
||||
let {
|
||||
label,
|
||||
value,
|
||||
detail = '',
|
||||
tone = 'default',
|
||||
}: {
|
||||
label: string
|
||||
value: string | number
|
||||
detail?: string
|
||||
tone?: 'default' | 'primary' | 'success' | 'warning' | 'danger'
|
||||
} = $props()
|
||||
</script>
|
||||
|
||||
<div class="rounded-lg border border-border bg-surface p-4">
|
||||
<p class="text-xs font-medium uppercase tracking-wider text-muted-fg">{label}</p>
|
||||
<p
|
||||
class={cn(
|
||||
'mt-2 text-2xl font-semibold tracking-tight',
|
||||
tone === 'primary' && 'text-primary',
|
||||
tone === 'success' && 'text-success',
|
||||
tone === 'warning' && 'text-warning',
|
||||
tone === 'danger' && 'text-danger',
|
||||
tone === 'default' && 'text-fg',
|
||||
)}
|
||||
>
|
||||
{value}
|
||||
</p>
|
||||
{#if detail}<p class="mt-1 text-xs text-muted-fg">{detail}</p>{/if}
|
||||
</div>
|
||||
Reference in new issue
Block a user