Update library lists when a move finishes (#1)
CI / test (push) Successful in 1m14s

The Library now follows moves on both servers: an item shows "Moving to …" while it moves and "Moved to …" until the source's Jellyfin drops
it after its rescan; the list reloads when a move finishes and checks again every 20 s for a few minutes. The destination shows the new item
straight away.
This commit is contained in:
IxianPixel committed 2026-11-06 17:21:22 +00:00
1 parent 484ac50508
commit 2bd4489b1a
9 files changed
+236 -61

No files matched your search

+9 -37
View File
@@ -1,52 +1,24 @@
<script lang="ts">
import { onMount } from 'svelte';
import { api, bytes, STAGE_LABEL, STAGES, type Job } from './api';
import { moves, trackMove } from './moves.svelte';
interface Props {
localName: string;
}
let { localName }: Props = $props();
let jobs = $state<Record<string, Job>>({});
let peerError = $state<string | null>(null);
let error = $state<string | null>(null);
let retryError = $state<string | null>(null);
let open = $state<Record<string, boolean>>({});
const sorted = $derived(Object.values(jobs).sort((a, b) => b.created.localeCompare(a.created)));
async function load() {
try {
const view = await api.jobs();
const next: Record<string, Job> = {};
for (const j of [...view.local, ...view.peer]) next[j.id] = j;
jobs = next;
peerError = view.peer_error;
error = null;
} catch (e) {
error = (e as Error).message;
}
}
onMount(() => {
load();
// Live progress for jobs running here; poll for jobs running on the peer.
const es = new EventSource('/api/events');
es.addEventListener('job', (ev) => {
const j = JSON.parse((ev as MessageEvent).data) as Job;
jobs[j.id] = j;
});
const t = setInterval(load, 2000);
return () => {
es.close();
clearInterval(t);
};
});
const sorted = $derived(Object.values(moves.jobs).sort((a, b) => b.created.localeCompare(a.created)));
const error = $derived(retryError ?? moves.error);
async function retry(id: string) {
try {
jobs[id] = await api.retry(id);
trackMove(await api.retry(id));
retryError = null;
} catch (e) {
error = (e as Error).message;
retryError = (e as Error).message;
}
}
@@ -75,9 +47,9 @@
</script>
{#if error}<p class="panel msg error">{error}</p>{/if}
{#if peerError}<p class="panel msg muted">Couldn't load moves running on the peer: {peerError}</p>{/if}
{#if moves.peerError}<p class="panel msg muted">Couldn't load moves running on the peer: {moves.peerError}</p>{/if}
{#if !sorted.length}
{#if moves.loaded && !sorted.length}
<p class="panel empty muted">No moves yet. Pick something in Library to get started.</p>
{/if}