Add a Trash view to see and empty .jellymove-trash (#3)
CI / test (push) Successful in 1m18s
CI / test (push) Successful in 1m18s
Moved folders sat in each library's .jellymove-trash until removed by hand on the server. The new Trash tab lists them on either server with
size, file count, when and where they went, and empties one item, a library or everything after a confirmation.
- trash.rs: list and empty entries. Entries are referred to by an opaque ID and resolved by scanning; only real folders directly inside a trash folder can be deleted.
- Each move now gets its own trash entry folder, with a small metadata file. Fixes moves failing when the same item had been trashed before.
- Peer API: GET /trash, POST /trash/empty, and /exports/{id}/complete now records the job and destination.
- e2e tests for listing, emptying from either side, refusing paths as IDs, and moving the same item away twice.
Closes #3
This commit is contained in:
1 parent
38319e0987
commit
4c6217bd40
16 files changed
+935
-23
No files matched your search
+5
-1
@@ -4,8 +4,9 @@
|
||||
import Library from './lib/Library.svelte';
|
||||
import Jobs from './lib/Jobs.svelte';
|
||||
import StatusView from './lib/StatusView.svelte';
|
||||
import Trash from './lib/Trash.svelte';
|
||||
|
||||
type Tab = 'library' | 'jobs' | 'status';
|
||||
type Tab = 'library' | 'jobs' | 'trash' | 'status';
|
||||
let tab = $state<Tab>('library');
|
||||
let status = $state<Status | null>(null);
|
||||
let statusError = $state<string | null>(null);
|
||||
@@ -48,6 +49,7 @@
|
||||
<nav>
|
||||
<button class:active={tab === 'library'} onclick={() => (tab = 'library')}>Library</button>
|
||||
<button class:active={tab === 'jobs'} onclick={() => (tab = 'jobs')}>Moves</button>
|
||||
<button class:active={tab === 'trash'} onclick={() => (tab = 'trash')}>Trash</button>
|
||||
<button class:active={tab === 'status'} onclick={() => (tab = 'status')}>
|
||||
Status
|
||||
{#if status && !healthy}<span class="dot warn" title="Something needs attention"></span>{/if}
|
||||
@@ -64,6 +66,8 @@
|
||||
<Library {localName} {peerName} onmoved={() => (tab = 'jobs')} />
|
||||
{:else if tab === 'jobs'}
|
||||
<Jobs {localName} />
|
||||
{:else if tab === 'trash'}
|
||||
<Trash {localName} {peerName} />
|
||||
{:else}
|
||||
<StatusView {status} reload={loadStatus} />
|
||||
{/if}
|
||||
|
||||
@@ -0,0 +1,288 @@
|
||||
<script lang="ts">
|
||||
import { onMount } from 'svelte';
|
||||
import { api, bytes, type Side, type TrashEntry } from './api';
|
||||
|
||||
interface Props {
|
||||
localName: string;
|
||||
peerName: string;
|
||||
}
|
||||
let { localName, peerName }: Props = $props();
|
||||
|
||||
let side = $state<Side>('local');
|
||||
let entries = $state<TrashEntry[]>([]);
|
||||
let loading = $state(false);
|
||||
let error = $state<string | null>(null);
|
||||
let notice = $state<string | null>(null);
|
||||
/** What's waiting for a second click: an entry ID, `lib:<name>` or `all`. */
|
||||
let confirming = $state<string | null>(null);
|
||||
let busy = $state(false);
|
||||
|
||||
const nodeName = $derived(side === 'local' ? localName : peerName);
|
||||
const total = $derived(entries.reduce((n, e) => n + e.size, 0));
|
||||
const groups = $derived(
|
||||
[...new Set(entries.map((e) => e.library))].map((library) => {
|
||||
const items = entries.filter((e) => e.library === library);
|
||||
return { library, items, size: items.reduce((n, e) => n + e.size, 0) };
|
||||
}),
|
||||
);
|
||||
|
||||
async function load() {
|
||||
loading = true;
|
||||
error = null;
|
||||
confirming = null;
|
||||
try {
|
||||
entries = await api.trash(side);
|
||||
} catch (e) {
|
||||
error = (e as Error).message;
|
||||
entries = [];
|
||||
} finally {
|
||||
loading = false;
|
||||
}
|
||||
}
|
||||
|
||||
function choose(s: Side) {
|
||||
if (s === side) return;
|
||||
side = s;
|
||||
notice = null;
|
||||
entries = [];
|
||||
load();
|
||||
}
|
||||
|
||||
onMount(load);
|
||||
|
||||
async function empty(ids: string[], what: string) {
|
||||
busy = true;
|
||||
error = null;
|
||||
notice = null;
|
||||
try {
|
||||
const r = await api.emptyTrash(side, ids);
|
||||
notice = r.removed
|
||||
? `Emptied ${what} on ${nodeName}, freeing ${bytes(r.freed)}.`
|
||||
: `Nothing to empty: ${what} had already gone.`;
|
||||
} catch (e) {
|
||||
error = (e as Error).message;
|
||||
} finally {
|
||||
busy = false;
|
||||
confirming = null;
|
||||
await load();
|
||||
}
|
||||
}
|
||||
|
||||
function when(iso: string | null): string {
|
||||
if (!iso) return 'an unknown date';
|
||||
return new Date(iso).toLocaleString('en-GB', { dateStyle: 'medium', timeStyle: 'short' });
|
||||
}
|
||||
|
||||
function kindLabel(e: TrashEntry): string {
|
||||
if (e.kind === 'Series') return 'TV';
|
||||
if (e.kind === 'Movie') return 'Film';
|
||||
return '—';
|
||||
}
|
||||
|
||||
const fileCount = (n: number) => `${n} ${n === 1 ? 'file' : 'files'}`;
|
||||
</script>
|
||||
|
||||
{#snippet emptyButton(key: string, ids: string[], what: string, label: string)}
|
||||
{#if confirming === key}
|
||||
<span class="confirm" role="group" aria-label="Confirm deletion">
|
||||
<span class="error small">Delete for good?</span>
|
||||
<button class="danger" disabled={busy} onclick={() => empty(ids, what)}>Yes, delete</button>
|
||||
<button disabled={busy} onclick={() => (confirming = null)}>Cancel</button>
|
||||
</span>
|
||||
{:else}
|
||||
<button disabled={busy || !ids.length} onclick={() => (confirming = key)}>{label}</button>
|
||||
{/if}
|
||||
{/snippet}
|
||||
|
||||
<section class="toolbar">
|
||||
<div class="sides" role="radiogroup" aria-label="Show the trash on which server">
|
||||
<button role="radio" aria-checked={side === 'local'} class="local" class:on={side === 'local'} onclick={() => choose('local')}>
|
||||
<span class="dot"></span>{localName}
|
||||
</button>
|
||||
<button role="radio" aria-checked={side === 'peer'} class="peer" class:on={side === 'peer'} onclick={() => choose('peer')}>
|
||||
<span class="dot"></span>{peerName}
|
||||
</button>
|
||||
</div>
|
||||
<span class="summary">
|
||||
{#if loading}
|
||||
<span class="muted">Loading…</span>
|
||||
{:else if !error}
|
||||
<strong>{bytes(total)}</strong> <span class="muted">in {entries.length} {entries.length === 1 ? 'item' : 'items'}</span>
|
||||
{/if}
|
||||
</span>
|
||||
<button onclick={load} disabled={loading || busy}>Refresh</button>
|
||||
{@render emptyButton('all', entries.map((e) => e.id), `the trash`, 'Empty all')}
|
||||
</section>
|
||||
|
||||
<p class="intro muted">
|
||||
When something moves off <strong class={side}>{nodeName}</strong>, its folder waits here in case anything went
|
||||
wrong. Emptying deletes it for good. The moved copy on the other server isn't affected.
|
||||
</p>
|
||||
|
||||
{#if error}<p class="panel msg error">{error}</p>{/if}
|
||||
{#if notice}<p class="panel msg" role="status">{notice}</p>{/if}
|
||||
|
||||
{#if !loading && !error && !entries.length}
|
||||
<p class="panel msg empty muted">The trash on {nodeName} is empty.</p>
|
||||
{/if}
|
||||
|
||||
{#each groups as g (g.library)}
|
||||
<section class="panel group">
|
||||
<div class="head">
|
||||
<h2>{g.library} <span class="muted">· {bytes(g.size)}</span></h2>
|
||||
{@render emptyButton(`lib:${g.library}`, g.items.map((e) => e.id), `${g.library}'s trash`, `Empty ${g.library}`)}
|
||||
</div>
|
||||
<ul class="list">
|
||||
{#each g.items as e (e.id)}
|
||||
<li>
|
||||
<span class="kind" title={e.kind ?? 'Unknown'}>{kindLabel(e)}</span>
|
||||
<div class="title">
|
||||
<span class="name">{e.name}</span>
|
||||
<div class="meta muted">
|
||||
Moved{#if e.moved_to} to {e.moved_to}{/if} on {when(e.moved_at)} · {fileCount(e.files)}
|
||||
</div>
|
||||
<div class="path mono muted" title={e.folder}>{e.folder}</div>
|
||||
</div>
|
||||
<span class="size">{bytes(e.size)}</span>
|
||||
<div class="actions">
|
||||
{@render emptyButton(e.id, [e.id], `“${e.name}”`, 'Empty')}
|
||||
</div>
|
||||
</li>
|
||||
{/each}
|
||||
</ul>
|
||||
</section>
|
||||
{/each}
|
||||
|
||||
<style>
|
||||
.toolbar {
|
||||
display: flex;
|
||||
gap: 0.6rem;
|
||||
flex-wrap: wrap;
|
||||
align-items: center;
|
||||
}
|
||||
.summary {
|
||||
flex: 1;
|
||||
min-width: 8rem;
|
||||
}
|
||||
.sides {
|
||||
display: inline-flex;
|
||||
border: 1px solid var(--line);
|
||||
border-radius: 8px;
|
||||
overflow: hidden;
|
||||
}
|
||||
.sides button {
|
||||
border: none;
|
||||
border-radius: 0;
|
||||
background: transparent;
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 0.4rem;
|
||||
color: var(--muted);
|
||||
}
|
||||
.sides button.on {
|
||||
background: var(--panel-2);
|
||||
color: var(--text);
|
||||
}
|
||||
.sides .local .dot {
|
||||
background: var(--local);
|
||||
}
|
||||
.sides .peer .dot {
|
||||
background: var(--peer);
|
||||
}
|
||||
strong.local {
|
||||
color: var(--local);
|
||||
}
|
||||
strong.peer {
|
||||
color: var(--peer);
|
||||
}
|
||||
.intro {
|
||||
margin: 0.9rem 0;
|
||||
font-size: 0.9rem;
|
||||
}
|
||||
.msg {
|
||||
padding: 0.7rem 1rem;
|
||||
}
|
||||
.empty {
|
||||
text-align: center;
|
||||
padding: 2rem;
|
||||
}
|
||||
.group {
|
||||
margin-bottom: 0.8rem;
|
||||
}
|
||||
.head {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
gap: 0.6rem;
|
||||
padding: 0.7rem 1rem;
|
||||
border-bottom: 1px solid var(--line);
|
||||
}
|
||||
h2 {
|
||||
font-size: 0.95rem;
|
||||
margin: 0;
|
||||
}
|
||||
.list {
|
||||
list-style: none;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
}
|
||||
.list li {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.9rem;
|
||||
padding: 0.7rem 1rem;
|
||||
border-top: 1px solid var(--line);
|
||||
}
|
||||
.list li:first-child {
|
||||
border-top: none;
|
||||
}
|
||||
.kind {
|
||||
font-size: 0.7rem;
|
||||
font-weight: 700;
|
||||
letter-spacing: 0.06em;
|
||||
text-transform: uppercase;
|
||||
color: var(--muted);
|
||||
border: 1px solid var(--line);
|
||||
border-radius: 5px;
|
||||
padding: 0.1rem 0.35rem;
|
||||
min-width: 2.6rem;
|
||||
text-align: center;
|
||||
}
|
||||
.title {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
}
|
||||
.name {
|
||||
font-weight: 600;
|
||||
}
|
||||
.meta {
|
||||
font-size: 0.85rem;
|
||||
}
|
||||
.path {
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
.size {
|
||||
font-variant-numeric: tabular-nums;
|
||||
white-space: nowrap;
|
||||
}
|
||||
.actions {
|
||||
flex-shrink: 0;
|
||||
}
|
||||
.confirm {
|
||||
display: inline-flex;
|
||||
gap: 0.4rem;
|
||||
align-items: center;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
.small {
|
||||
font-size: 0.85rem;
|
||||
}
|
||||
button.danger {
|
||||
background: var(--bad);
|
||||
border-color: var(--bad);
|
||||
color: #fff;
|
||||
font-weight: 600;
|
||||
}
|
||||
</style>
|
||||
@@ -82,6 +82,26 @@ export interface JobsView {
|
||||
peer_error: string | null;
|
||||
}
|
||||
|
||||
export interface TrashEntry {
|
||||
id: string;
|
||||
name: string;
|
||||
/** Missing for items trashed before v0.2.0. */
|
||||
kind: 'Movie' | 'Series' | null;
|
||||
library: string;
|
||||
folder: string;
|
||||
moved_at: string | null;
|
||||
moved_to: string | null;
|
||||
job_id: string | null;
|
||||
size: number;
|
||||
files: number;
|
||||
}
|
||||
|
||||
export interface EmptyResult {
|
||||
removed: number;
|
||||
freed: number;
|
||||
missing: string[];
|
||||
}
|
||||
|
||||
export class ApiError extends Error {}
|
||||
|
||||
async function call<T>(method: string, path: string, body?: unknown): Promise<T> {
|
||||
@@ -118,6 +138,8 @@ export const api = {
|
||||
call<Job>('POST', '/moves', { from, item_id: item.id, name: item.name, dry_run }),
|
||||
jobs: () => call<JobsView>('GET', '/jobs'),
|
||||
retry: (id: string) => call<Job>('POST', `/jobs/${id}/retry`),
|
||||
trash: (node: Side) => call<TrashEntry[]>('GET', `/trash?node=${node}`),
|
||||
emptyTrash: (node: Side, ids: string[]) => call<EmptyResult>('POST', '/trash/empty', { node, ids }),
|
||||
};
|
||||
|
||||
export const STAGE_LABEL: Record<Stage, string> = {
|
||||
|
||||
Reference in new issue
Block a user