2026-08-31 22:06:29 +02:00
|
|
|
<script lang="ts">
|
|
|
|
|
import { ArrowDown, ArrowRight, ChevronDown, FileCog, Image as ImageIcon, Search, Sparkles } from '@lucide/svelte'
|
2026-09-03 00:14:01 +02:00
|
|
|
import { Badge } from '@gabriel20xx/web-ui'
|
2026-08-31 22:06:29 +02:00
|
|
|
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}
|
2026-09-03 00:14:01 +02:00
|
|
|
<Badge variant="primary" class="animate-pulse">Active</Badge>
|
2026-08-31 22:06:29 +02:00
|
|
|
{:else}
|
2026-09-03 00:14:01 +02:00
|
|
|
<Badge>Idle</Badge>
|
2026-08-31 22:06:29 +02:00
|
|
|
{/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}
|
2026-09-03 00:14:01 +02:00
|
|
|
<Badge variant="primary" class="animate-pulse">Active</Badge>
|
2026-08-31 22:06:29 +02:00
|
|
|
{:else}
|
2026-09-03 00:14:01 +02:00
|
|
|
<Badge>Idle</Badge>
|
2026-08-31 22:06:29 +02:00
|
|
|
{/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}
|
2026-09-03 00:14:01 +02:00
|
|
|
<Badge variant="primary" class="animate-pulse">Active</Badge>
|
2026-08-31 22:06:29 +02:00
|
|
|
{:else}
|
2026-09-03 00:14:01 +02:00
|
|
|
<Badge>Idle</Badge>
|
2026-08-31 22:06:29 +02:00
|
|
|
{/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>
|