Warn before watch history is left behind, and re-apply it later (#2)
CI / test (push) Successful in 1m16s

This commit is contained in:
IxianPixel committed 2026-11-06 17:34:22 +00:00
1 parent 2bd4489b1a
commit 8cfa0f05eb
15 files changed
+611 -73

No files matched your search

+45
View File
@@ -8,11 +8,24 @@
let { localName }: Props = $props();
let retryError = $state<string | null>(null);
let reapplying = $state<string | null>(null);
let open = $state<Record<string, boolean>>({});
const sorted = $derived(Object.values(moves.jobs).sort((a, b) => b.created.localeCompare(a.created)));
const error = $derived(retryError ?? moves.error);
async function reapply(id: string) {
reapplying = id;
try {
trackMove(await api.reapply(id));
retryError = null;
} catch (e) {
retryError = (e as Error).message;
} finally {
reapplying = null;
}
}
async function retry(id: string) {
try {
trackMove(await api.retry(id));
@@ -97,6 +110,21 @@
<p class="error why">{j.status.detail}</p>
{/if}
{#if j.missing_users?.length}
{@const one = j.missing_users.length === 1}
{@const done = j.status.kind === 'Done'}
<div class="missing">
<p>
Watch history {done ? "didn't" : "won't"} carry over for <strong>{j.missing_users.join(', ')}</strong>:
{j.target_node} has no user with {one ? 'that name' : 'those names'}.
{#if done}Create {one ? 'the user' : 'them'} in Jellyfin on {j.target_node}, then re-apply it.{/if}
</p>
{#if done}
<button disabled={reapplying === j.id} onclick={() => reapply(j.id)}>Re-apply watch history</button>
{/if}
</div>
{/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>
@@ -229,6 +257,23 @@
margin: 0.7rem 0 0;
font-size: 0.9rem;
}
.missing {
margin-top: 0.7rem;
padding: 0.6rem 0.8rem;
border: 1px solid color-mix(in srgb, var(--local) 55%, var(--line));
border-radius: 8px;
font-size: 0.9rem;
display: flex;
gap: 0.8rem;
align-items: center;
justify-content: space-between;
flex-wrap: wrap;
}
.missing p {
margin: 0;
flex: 1;
min-width: 16rem;
}
.logtoggle {
margin-top: 0.7rem;
font-size: 0.8rem;
+62 -1
View File
@@ -196,11 +196,28 @@
return () => clearTimeout(timer);
});
async function move(item: Movable, dryRun: boolean) {
/** A move waiting for the user to accept that some watch history won't carry over. */
type Confirm = { item: Movable; missing: string[] };
let confirming = $state<Confirm | null>(null);
function names(list: string[]): string {
return list.length < 2 ? list.join('') : `${list.slice(0, -1).join(', ')} and ${list[list.length - 1]}`;
}
async function move(item: Movable, dryRun: boolean, checked = false) {
busy = item.id;
notice = null;
error = null;
confirming = null;
try {
// Watch history is matched by user name; warn before it gets left behind.
if (!dryRun && !checked) {
const check = await api.checkMove(side, item);
if (check.missing_users.length) {
confirming = { item, missing: check.missing_users };
return;
}
}
trackMove(await api.move(side, item, dryRun));
notice = dryRun
? `Planning a dry run for “${item.name}”. Check Moves for the plan.`
@@ -213,6 +230,22 @@
}
</script>
{#snippet missingUsers(c: Confirm)}
{@const one = c.missing.length === 1}
<div class="confirm-move" role="alertdialog" aria-label="Some watch history won't carry over">
<p>
<strong>{names(c.missing)}</strong>
{one ? 'has' : 'have'} watch history for this, but {destName} has no user with {one ? 'that name' : 'those names'}, so
it won't carry over. Create {one ? 'the user' : 'them'} in Jellyfin on {destName} first, or move anyway and re-apply
it later from Moves.
</p>
<div class="confirm-buttons">
<button class="primary" disabled={busy === c.item.id} onclick={() => move(c.item, false, true)}>Move anyway</button>
<button onclick={() => (confirming = null)}>Cancel</button>
</div>
</div>
{/snippet}
{#snippet moveTag(mark: Mark)}
{#if mark.moving}
<span class="tag moving">Moving to {mark.to}…</span>
@@ -293,6 +326,9 @@
{/if}
</div>
</div>
{#if confirming?.item.id === item.id}
{@render missingUsers(confirming)}
{/if}
{#if open[item.id]}
{@const st = seasons[item.id]}
{#if !st || 'loading' in st}
@@ -324,6 +360,9 @@
{/if}
</td>
</tr>
{#if confirming?.item.id === season.id}
<tr><td colspan="4" class="wrap">{@render missingUsers(confirming)}</td></tr>
{/if}
{:else}
<tr><td colspan="4" class="muted">Jellyfin lists no seasons for this show.</td></tr>
{/each}
@@ -446,6 +485,28 @@
padding-right: 0;
white-space: nowrap;
}
.confirm-move {
margin: 0.6rem 0 0.1rem 3.5rem;
padding: 0.7rem 0.9rem;
border: 1px solid color-mix(in srgb, var(--local) 55%, var(--line));
border-radius: 8px;
font-size: 0.9rem;
white-space: normal;
}
.parts .confirm-move {
margin-left: 0;
}
.parts td.wrap {
white-space: normal;
}
.confirm-move p {
margin: 0;
}
.confirm-buttons {
display: flex;
gap: 0.4rem;
margin-top: 0.6rem;
}
.tag {
font-size: 0.82rem;
border: 1px solid var(--line);
+10
View File
@@ -105,6 +105,13 @@ export interface Job {
target_folder_jellyfin: string | null;
progress: { bytes_done: number; bytes_total: number; current_file: string | null };
log: string[];
/** Users whose watch history didn't (or won't) carry over: no account on the target. */
missing_users?: string[];
}
export interface MoveCheck {
watchers: string[];
missing_users: string[];
}
export interface JobsView {
@@ -167,10 +174,13 @@ export const api = {
),
seasons: (node: Side, series: string) =>
call<SeasonItem[]>('GET', `/seasons?${new URLSearchParams({ node, series })}`),
checkMove: (from: Side, item: Movable) =>
call<MoveCheck>('GET', `/moves/check?${new URLSearchParams({ from, item_id: item.id })}`),
move: (from: Side, item: Movable, 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`),
reapply: (id: string) => call<Job>('POST', `/jobs/${id}/reapply`),
trash: (node: Side) => call<TrashEntry[]>('GET', `/trash?node=${node}`),
emptyTrash: (node: Side, ids: string[]) => call<EmptyResult>('POST', '/trash/empty', { node, ids }),
};