Initial code commit
CI / test (push) Successful in 5m7s

This commit is contained in:
IxianPixel committed 2026-11-05 14:19:37 +00:00
1 parent f47217d5a3
commit 8ceb3c8be8
60 files changed
+10884

No files matched your search

+2
View File
@@ -0,0 +1,2 @@
node_modules/
dist/
+13
View File
@@ -0,0 +1,13 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="color-scheme" content="dark light" />
<title>jellymove</title>
</head>
<body>
<div id="app"></div>
<script type="module" src="/src/main.ts"></script>
</body>
</html>
+1189
View File
File diff suppressed because it is too large. Load diff
+19
View File
@@ -0,0 +1,19 @@
{
"name": "jellymove-ui",
"private": true,
"version": "0.1.0",
"type": "module",
"scripts": {
"dev": "vite",
"build": "vite build",
"check": "svelte-check --tsconfig ./tsconfig.json"
},
"devDependencies": {
"@sveltejs/vite-plugin-svelte": "^7.3.1",
"@tsconfig/svelte": "^5.0.8",
"svelte": "^5.57.3",
"svelte-check": "^4.7.8",
"typescript": "^6.0.3",
"vite": "^8.3.5"
}
}
+146
View File
@@ -0,0 +1,146 @@
<script lang="ts">
import { onMount } from 'svelte';
import { api, type Status } from './lib/api';
import Library from './lib/Library.svelte';
import Jobs from './lib/Jobs.svelte';
import StatusView from './lib/StatusView.svelte';
type Tab = 'library' | 'jobs' | 'status';
let tab = $state<Tab>('library');
let status = $state<Status | null>(null);
let statusError = $state<string | null>(null);
async function loadStatus() {
try {
status = await api.status();
statusError = null;
} catch (e) {
statusError = (e as Error).message;
}
}
onMount(() => {
loadStatus();
const t = setInterval(loadStatus, 30_000);
return () => clearInterval(t);
});
const localName = $derived(status?.node.node_name ?? 'this server');
const peerName = $derived(status?.peer?.node_name ?? 'peer');
const healthy = $derived(
!!status &&
!status.jellyfin_error &&
!status.peer_error &&
status.locations.every((l) => l.exists && l.writable),
);
</script>
<header>
<div class="brand">
<span class="logo" aria-hidden="true">⇄</span>
<span>jellymove</span>
</div>
<div class="nodes" aria-label="Connected servers">
<span class="node local"><span class="dot"></span>{localName}</span>
<span class="link" class:down={!!status?.peer_error}>{status?.peer_error ? '╳' : '⟷'}</span>
<span class="node peer"><span class="dot"></span>{peerName}</span>
</div>
<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 === 'status'} onclick={() => (tab = 'status')}>
Status
{#if status && !healthy}<span class="dot warn" title="Something needs attention"></span>{/if}
</button>
</nav>
</header>
<main>
{#if statusError}
<p class="panel banner error">Can't reach this jellymove agent: {statusError}</p>
{/if}
{#if tab === 'library'}
<Library {localName} {peerName} onmoved={() => (tab = 'jobs')} />
{:else if tab === 'jobs'}
<Jobs {localName} />
{:else}
<StatusView {status} reload={loadStatus} />
{/if}
</main>
<style>
header {
display: flex;
align-items: center;
gap: 1.5rem;
padding: 0.8rem 1.5rem;
border-bottom: 1px solid var(--line);
background: var(--panel);
flex-wrap: wrap;
}
.brand {
display: flex;
align-items: center;
gap: 0.5rem;
font-weight: 700;
letter-spacing: -0.01em;
font-size: 1.1rem;
}
.logo {
color: var(--local);
}
.nodes {
display: flex;
align-items: center;
gap: 0.6rem;
font-size: 0.9rem;
}
.node {
display: inline-flex;
align-items: center;
gap: 0.4rem;
padding: 0.2rem 0.65rem;
border-radius: 999px;
border: 1px solid var(--line);
}
.node.local .dot {
background: var(--local);
}
.node.peer .dot {
background: var(--peer);
}
.link {
color: var(--muted);
}
.link.down {
color: var(--bad);
}
nav {
margin-left: auto;
display: flex;
gap: 0.25rem;
}
nav button {
background: transparent;
border-color: transparent;
color: var(--muted);
}
nav button.active {
color: var(--text);
background: var(--panel-2);
border-color: var(--line);
}
.dot.warn {
background: var(--bad);
margin-left: 0.3rem;
}
main {
max-width: 1100px;
margin: 0 auto;
padding: 1.5rem;
}
.banner {
padding: 0.8rem 1rem;
}
</style>
+113
View File
@@ -0,0 +1,113 @@
:root {
--bg: #0f1216;
--panel: #161b21;
--panel-2: #1c232b;
--line: #2a333d;
--text: #e6e9ee;
--muted: #8b96a3;
--local: #f2a541; /* this node */
--peer: #4cc3d9; /* the other node */
--ok: #5ccf8a;
--bad: #ef6b6b;
--radius: 10px;
--mono: ui-monospace, 'SF Mono', 'Cascadia Code', 'JetBrains Mono', Menlo, monospace;
font-family: 'Inter', system-ui, -apple-system, 'Segoe UI', sans-serif;
font-size: 15px;
line-height: 1.45;
color: var(--text);
background: var(--bg);
}
@media (prefers-color-scheme: light) {
:root {
--bg: #f4f5f7;
--panel: #ffffff;
--panel-2: #f0f2f5;
--line: #dde1e6;
--text: #1b2027;
--muted: #5f6b78;
--local: #c77a12;
--peer: #1a8ea3;
--ok: #23874d;
--bad: #c43c3c;
}
}
* {
box-sizing: border-box;
}
body {
margin: 0;
}
button {
font: inherit;
color: inherit;
background: var(--panel-2);
border: 1px solid var(--line);
border-radius: 8px;
padding: 0.45rem 0.85rem;
cursor: pointer;
}
button:hover:not(:disabled) {
border-color: var(--muted);
}
button:disabled {
opacity: 0.5;
cursor: default;
}
button.primary {
background: var(--text);
color: var(--bg);
border-color: var(--text);
font-weight: 600;
}
input,
select {
font: inherit;
color: inherit;
background: var(--panel-2);
border: 1px solid var(--line);
border-radius: 8px;
padding: 0.45rem 0.7rem;
}
input:focus-visible,
select:focus-visible,
button:focus-visible {
outline: 2px solid var(--peer);
outline-offset: 1px;
}
code,
.mono {
font-family: var(--mono);
font-size: 0.85em;
}
.muted {
color: var(--muted);
}
.error {
color: var(--bad);
}
.panel {
background: var(--panel);
border: 1px solid var(--line);
border-radius: var(--radius);
}
.dot {
display: inline-block;
width: 0.55rem;
height: 0.55rem;
border-radius: 50%;
vertical-align: middle;
}
+278
View File
@@ -0,0 +1,278 @@
<script lang="ts">
import { onMount } from 'svelte';
import { api, bytes, STAGE_LABEL, STAGES, type Job } from './api';
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 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);
};
});
async function retry(id: string) {
try {
jobs[id] = await api.retry(id);
} catch (e) {
error = (e as Error).message;
}
}
function pct(j: Job): number {
if (j.status.kind === 'Done') return 100;
if (!j.progress.bytes_total) return 0;
return Math.min(100, (j.progress.bytes_done / j.progress.bytes_total) * 100);
}
function statusText(j: Job): string {
switch (j.status.kind) {
case 'Done':
return 'Moved';
case 'Planned':
return 'Dry run complete';
case 'Failed':
return 'Failed';
case 'Queued':
return 'Queued';
default:
return STAGE_LABEL[j.stage];
}
}
const sideClass = (node: string) => (node === localName ? 'local' : 'peer');
</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 !sorted.length}
<p class="panel empty muted">No moves yet. Pick something in Library to get started.</p>
{/if}
<ul class="jobs">
{#each sorted as j (j.id)}
<li class="panel job" class:failed={j.status.kind === 'Failed'}>
<div class="top">
<div class="what">
<div class="name">{j.name}</div>
<div class="route">
<span class={sideClass(j.source_node)}>{j.source_node}</span>
<span class="muted">→</span>
<span class={sideClass(j.target_node)}>{j.target_node}</span>
{#if j.target_library}<span class="muted">· {j.target_library}</span>{/if}
{#if j.dry_run}<span class="tag">dry run</span>{/if}
</div>
</div>
<div class="state">
<span class="label s-{j.status.kind.toLowerCase()}">{statusText(j)}</span>
{#if (j.status.kind === 'Failed' || j.status.kind === 'Planned') && j.target_node === localName}
<button onclick={() => retry(j.id)}>{j.status.kind === 'Planned' ? 'Run for real' : 'Retry'}</button>
{/if}
</div>
</div>
<div class="steps" aria-hidden="true">
{#each STAGES.slice(0, -1) as s, i (s)}
<span class="step" class:done={STAGES.indexOf(j.stage) > i} class:now={STAGES.indexOf(j.stage) === i && j.status.kind === 'Running'}></span>
{/each}
</div>
{#if j.progress.bytes_total}
<div class="bar" role="progressbar" aria-valuenow={Math.round(pct(j))} aria-valuemin={0} aria-valuemax={100}>
<div style:width="{pct(j)}%"></div>
</div>
<div class="meta muted">
{bytes(j.progress.bytes_done)} of {bytes(j.progress.bytes_total)}
{#if j.progress.current_file && j.status.kind === 'Running'}
· <span class="mono">{j.progress.current_file}</span>
{/if}
</div>
{/if}
{#if j.status.kind === 'Failed'}
<p class="error why">{j.status.detail}</p>
{/if}
<button class="logtoggle" onclick={() => (open[j.id] = !open[j.id])} aria-expanded={!!open[j.id]}>
{open[j.id] ? 'Hide' : 'Show'} log ({j.log.length})
</button>
{#if open[j.id]}
<pre class="log">{j.log.join('\n')}</pre>
{/if}
</li>
{/each}
</ul>
<style>
.msg,
.empty {
padding: 0.8rem 1rem;
}
.empty {
text-align: center;
padding: 2rem;
}
.jobs {
list-style: none;
margin: 0;
padding: 0;
display: grid;
gap: 0.8rem;
}
.job {
padding: 1rem 1.1rem;
}
.job.failed {
border-color: color-mix(in srgb, var(--bad) 50%, var(--line));
}
.top {
display: flex;
gap: 1rem;
align-items: flex-start;
justify-content: space-between;
}
.name {
font-weight: 650;
font-size: 1.05rem;
}
.route {
font-size: 0.88rem;
display: flex;
gap: 0.35rem;
align-items: center;
flex-wrap: wrap;
}
.route .local {
color: var(--local);
}
.route .peer {
color: var(--peer);
}
.tag {
font-size: 0.72rem;
border: 1px solid var(--line);
border-radius: 5px;
padding: 0 0.35rem;
color: var(--muted);
}
.state {
display: flex;
gap: 0.6rem;
align-items: center;
flex-shrink: 0;
}
.label {
font-size: 0.85rem;
font-weight: 600;
}
.s-done {
color: var(--ok);
}
.s-failed {
color: var(--bad);
}
.s-running {
color: var(--peer);
}
.steps {
display: grid;
grid-template-columns: repeat(7, 1fr);
gap: 4px;
margin: 0.8rem 0 0.5rem;
}
.step {
height: 4px;
border-radius: 2px;
background: var(--line);
}
.step.done {
background: var(--ok);
}
.step.now {
background: var(--peer);
animation: pulse 1.4s ease-in-out infinite;
}
@keyframes pulse {
50% {
opacity: 0.45;
}
}
@media (prefers-reduced-motion: reduce) {
.step.now {
animation: none;
}
}
.bar {
height: 8px;
border-radius: 4px;
background: var(--panel-2);
overflow: hidden;
margin-top: 0.6rem;
}
.bar div {
height: 100%;
background: linear-gradient(90deg, var(--local), var(--peer));
transition: width 0.4s ease;
}
.meta {
font-size: 0.82rem;
margin-top: 0.35rem;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
.why {
margin: 0.7rem 0 0;
font-size: 0.9rem;
}
.logtoggle {
margin-top: 0.7rem;
font-size: 0.8rem;
padding: 0.2rem 0.6rem;
background: transparent;
color: var(--muted);
}
.log {
margin: 0.5rem 0 0;
padding: 0.7rem;
background: var(--panel-2);
border-radius: 8px;
font-family: var(--mono);
font-size: 0.78rem;
max-height: 18rem;
overflow: auto;
white-space: pre-wrap;
}
</style>
+239
View File
@@ -0,0 +1,239 @@
<script lang="ts">
import { onMount } from 'svelte';
import { api, type Library, type LibraryItem, type Side } from './api';
interface Props {
localName: string;
peerName: string;
onmoved: () => void;
}
let { localName, peerName, onmoved }: Props = $props();
let side = $state<Side>('local');
let libraries = $state<Library[]>([]);
let libraryId = $state('');
let search = $state('');
let items = $state<LibraryItem[]>([]);
let loading = $state(false);
let error = $state<string | null>(null);
let busy = $state<string | null>(null); // item id being submitted
let notice = $state<string | null>(null);
const sourceName = $derived(side === 'local' ? localName : peerName);
const destName = $derived(side === 'local' ? peerName : localName);
async function loadLibraries(s: Side) {
error = null;
items = [];
libraries = [];
try {
libraries = await api.libraries(s);
libraryId = libraries[0]?.id ?? '';
} catch (e) {
error = (e as Error).message;
}
}
async function loadItems() {
if (!libraryId) return;
loading = true;
error = null;
try {
items = await api.items(side, libraryId, search.trim());
} catch (e) {
error = (e as Error).message;
items = [];
} finally {
loading = false;
}
}
function choose(s: Side) {
if (s === side) return;
side = s;
loadLibraries(s);
}
onMount(() => {
loadLibraries(side);
});
// Reload items when the library or search text changes, debounced.
$effect(() => {
void libraryId;
void search;
const timer = setTimeout(loadItems, 250);
return () => clearTimeout(timer);
});
async function move(item: LibraryItem, dryRun: boolean) {
busy = item.id;
notice = null;
error = null;
try {
await api.move(side, item, dryRun);
if (dryRun) {
notice = `Planning a dry run for “${item.name}”. Check Moves for the plan.`;
} else {
onmoved();
}
} catch (e) {
error = (e as Error).message;
} finally {
busy = null;
}
}
</script>
<section class="toolbar">
<div class="sides" role="radiogroup" aria-label="Browse 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>
<select bind:value={libraryId} aria-label="Library" disabled={!libraries.length}>
{#each libraries as lib (lib.id)}
<option value={lib.id}>{lib.name}</option>
{/each}
</select>
<input type="search" placeholder="Search titles…" bind:value={search} aria-label="Search" />
</section>
<p class="direction muted">
Moving from <strong class={side}>{sourceName}</strong> to
<strong class={side === 'local' ? 'peer' : 'local'}>{destName}</strong>. The whole folder moves, including
subtitles, artwork, NFOs and extras, along with everyone's watch history.
</p>
{#if error}<p class="panel msg error">{error}</p>{/if}
{#if notice}<p class="panel msg">{notice}</p>{/if}
<ul class="panel list" aria-busy={loading}>
{#if loading && !items.length}
<li class="empty muted">Loading…</li>
{:else if !items.length}
<li class="empty muted">{libraryId ? 'Nothing here.' : 'No movie or TV libraries found.'}</li>
{/if}
{#each items as item (item.id)}
<li>
<span class="kind" title={item.kind}>{item.kind === 'Series' ? 'TV' : 'Film'}</span>
<div class="title">
<span class="name">{item.name}</span>
{#if item.year}<span class="muted">{item.year}</span>{/if}
{#if item.path}<div class="path mono muted" title={item.path}>{item.path}</div>{/if}
</div>
<div class="actions">
<button disabled={busy === item.id} onclick={() => move(item, true)} title="Check and plan without copying anything">
Dry run
</button>
<button class="primary" disabled={busy === item.id} onclick={() => move(item, false)}>
Move to {destName} →
</button>
</div>
</li>
{/each}
</ul>
<style>
.toolbar {
display: flex;
gap: 0.6rem;
flex-wrap: wrap;
align-items: center;
}
.toolbar input {
flex: 1;
min-width: 12rem;
}
.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);
}
.direction {
margin: 0.9rem 0;
font-size: 0.9rem;
}
.msg {
padding: 0.7rem 1rem;
}
.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;
}
.empty {
justify-content: center;
padding: 2rem !important;
}
.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;
margin-right: 0.4rem;
}
.path {
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
margin-top: 0.1rem;
}
.actions {
display: flex;
gap: 0.4rem;
flex-shrink: 0;
}
</style>
+169
View File
@@ -0,0 +1,169 @@
<script lang="ts">
import type { Status } from './api';
interface Props {
status: Status | null;
reload: () => Promise<void>;
}
let { status, reload }: Props = $props();
let checking = $state(false);
async function recheck() {
checking = true;
await reload();
checking = false;
}
</script>
{#if !status}
<p class="panel box muted">Loading…</p>
{:else}
<div class="grid">
<section class="panel box">
<h2>This agent</h2>
<dl>
<dt>Node</dt>
<dd>{status.node.node_name} <span class="muted">v{status.node.version}</span></dd>
<dt>Jellyfin</dt>
<dd>
{#if status.jellyfin_error}
<span class="error">{status.jellyfin_error}</span>
{:else}
<span class="dot ok"></span> {status.node.jellyfin_server}
<span class="muted">{status.node.jellyfin_version}</span>
{/if}
</dd>
</dl>
</section>
<section class="panel box">
<h2>Peer</h2>
<dl>
<dt>URL</dt>
<dd class="mono">{status.peer_url ?? 'not configured'}</dd>
<dt>Connection</dt>
<dd>
{#if status.peer_error}
<span class="error">{status.peer_error}</span>
{:else if status.peer}
<span class="dot ok"></span> {status.peer.node_name}
<span class="muted">v{status.peer.version} · Jellyfin {status.peer.jellyfin_version ?? '?'}</span>
{:else}
<span class="muted">No peer configured</span>
{/if}
</dd>
</dl>
</section>
</div>
<section class="panel box">
<div class="head">
<h2>Library folders</h2>
<button onclick={recheck} disabled={checking}>{checking ? 'Checking…' : 'Check again'}</button>
</div>
<p class="muted small">
jellymove must see each library folder Jellyfin uses, and be able to write to it. If a folder fails, check
the container's volume mounts, PUID/PGID, or <code>path_map</code>.
</p>
<table>
<thead><tr><th>Library</th><th>Jellyfin path</th><th>Seen here as</th><th>Status</th></tr></thead>
<tbody>
{#each status.locations as loc (loc.library + loc.jellyfin_path)}
<tr>
<td>{loc.library}</td>
<td class="mono">{loc.jellyfin_path}</td>
<td class="mono">{loc.local_path}</td>
<td>
{#if !loc.exists}<span class="error">not found</span>
{:else if !loc.writable}<span class="error">read-only</span>
{:else}<span class="okt">OK</span>{/if}
</td>
</tr>
{:else}
<tr><td colspan="4" class="muted">No libraries reported.</td></tr>
{/each}
</tbody>
</table>
</section>
<details class="panel box">
<summary>Effective configuration (secrets hidden)</summary>
<pre>{JSON.stringify(status.config, null, 2)}</pre>
</details>
{/if}
<style>
.grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
gap: 0.8rem;
margin-bottom: 0.8rem;
}
.box {
padding: 1rem 1.2rem;
margin-bottom: 0.8rem;
}
.grid .box {
margin-bottom: 0;
}
h2 {
font-size: 0.8rem;
text-transform: uppercase;
letter-spacing: 0.08em;
color: var(--muted);
margin: 0 0 0.7rem;
}
.head {
display: flex;
justify-content: space-between;
align-items: center;
}
.small {
font-size: 0.88rem;
}
dl {
display: grid;
grid-template-columns: 7rem 1fr;
gap: 0.4rem;
margin: 0;
}
dt {
color: var(--muted);
}
dd {
margin: 0;
overflow-wrap: anywhere;
}
.dot.ok {
background: var(--ok);
}
.okt {
color: var(--ok);
font-weight: 600;
}
table {
width: 100%;
border-collapse: collapse;
font-size: 0.9rem;
}
th {
text-align: left;
color: var(--muted);
font-weight: 500;
border-bottom: 1px solid var(--line);
padding: 0.4rem 0.5rem;
}
td {
padding: 0.45rem 0.5rem;
border-bottom: 1px solid var(--line);
}
summary {
cursor: pointer;
color: var(--muted);
}
pre {
font-family: var(--mono);
font-size: 0.8rem;
overflow: auto;
}
</style>
+145
View File
@@ -0,0 +1,145 @@
// Types mirror the Rust structs in jm-core / jm-server.
export type Side = 'local' | 'peer';
export interface NodeInfo {
node_name: string;
version: string;
jellyfin_server: string | null;
jellyfin_version: string | null;
}
export interface LocationCheck {
library: string;
jellyfin_path: string;
local_path: string;
exists: boolean;
writable: boolean;
}
export interface Status {
node: NodeInfo;
jellyfin_error: string | null;
locations: LocationCheck[];
peer_url: string | null;
peer: NodeInfo | null;
peer_error: string | null;
config: unknown;
}
export interface Library {
id: string;
name: string;
collection_type: string | null;
locations: string[];
}
export interface LibraryItem {
id: string;
name: string;
kind: 'Movie' | 'Series' | string;
year: number | null;
path: string | null;
}
export type Stage =
| 'Created'
| 'ExportReady'
| 'Copied'
| 'Promoted'
| 'TargetScanned'
| 'UserDataApplied'
| 'SourceCleaned'
| 'Done';
export type JobStatus =
| { kind: 'Queued' }
| { kind: 'Running' }
| { kind: 'Planned' }
| { kind: 'Failed'; detail: string }
| { kind: 'Done' };
export interface Job {
id: string;
created: string;
updated: string;
source_item_id: string;
name: string;
source_node: string;
target_node: string;
dry_run: boolean;
stage: Stage;
status: JobStatus;
target_library: string | null;
target_folder_jellyfin: string | null;
progress: { bytes_done: number; bytes_total: number; current_file: string | null };
log: string[];
}
export interface JobsView {
local: Job[];
peer: Job[];
peer_error: string | null;
}
export class ApiError extends Error {}
async function call<T>(method: string, path: string, body?: unknown): Promise<T> {
const res = await fetch(`/api${path}`, {
method,
headers: {
// Required on POSTs; stops cross-site form submissions (CSRF).
'X-Jellymove': '1',
...(body !== undefined ? { 'Content-Type': 'application/json' } : {}),
},
body: body !== undefined ? JSON.stringify(body) : undefined,
});
if (!res.ok) {
let msg = `HTTP ${res.status}`;
try {
msg = (await res.json()).error ?? msg;
} catch {
/* not JSON */
}
throw new ApiError(msg);
}
return res.json() as Promise<T>;
}
export const api = {
status: () => call<Status>('GET', '/status'),
libraries: (node: Side) => call<Library[]>('GET', `/libraries?node=${node}`),
items: (node: Side, library: string, search: string) =>
call<LibraryItem[]>(
'GET',
`/items?${new URLSearchParams({ node, library, ...(search ? { search } : {}) })}`,
),
move: (from: Side, item: LibraryItem, dry_run: boolean) =>
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`),
};
export const STAGE_LABEL: Record<Stage, string> = {
Created: 'Preparing at source',
ExportReady: 'Copying',
Copied: 'Moving into library',
Promoted: 'Waiting for Jellyfin scan',
TargetScanned: 'Restoring watch history',
UserDataApplied: 'Cleaning up source',
SourceCleaned: 'Finishing',
Done: 'Done',
};
export const STAGES: Stage[] = Object.keys(STAGE_LABEL) as Stage[];
export function bytes(n: number): string {
const units = ['B', 'KB', 'MB', 'GB', 'TB'];
let v = n;
let u = 0;
while (v >= 1000 && u < units.length - 1) {
v /= 1000;
u++;
}
return u === 0 ? `${n} B` : `${v.toFixed(1)} ${units[u]}`;
}
+5
View File
@@ -0,0 +1,5 @@
import { mount } from 'svelte';
import './app.css';
import App from './App.svelte';
export default mount(App, { target: document.getElementById('app')! });
+2
View File
@@ -0,0 +1,2 @@
/// <reference types="svelte" />
/// <reference types="vite/client" />
+2
View File
@@ -0,0 +1,2 @@
import { vitePreprocess } from '@sveltejs/vite-plugin-svelte';
export default { preprocess: vitePreprocess() };
+14
View File
@@ -0,0 +1,14 @@
{
"extends": "@tsconfig/svelte/tsconfig.json",
"compilerOptions": {
"target": "ES2022",
"module": "ESNext",
"moduleResolution": "bundler",
"strict": true,
"noEmit": true,
"isolatedModules": true,
"verbatimModuleSyntax": true,
"types": ["svelte", "vite/client"]
},
"include": ["src/**/*.ts", "src/**/*.svelte"]
}
+11
View File
@@ -0,0 +1,11 @@
import { defineConfig } from 'vite';
import { svelte } from '@sveltejs/vite-plugin-svelte';
// `npm run dev` proxies the API to a locally running daemon.
const daemon = process.env.JELLYMOVE_URL ?? 'http://127.0.0.1:8097';
export default defineConfig({
plugins: [svelte()],
server: { proxy: { '/api': daemon } },
build: { outDir: 'dist', emptyOutDir: true },
});