Files
Aryan SinghandClaude Opus 5 e1b7b69261 Recover blocked searches, fall through to the next peer, rebuild the UI
Measured against a live instance: 47 failed jobs against 33 imported. Three
independent causes, all of which ended the request.

The Soulseek server filters some artist names. "Michael Jackson Billie Jean"
and bare "Michael Jackson" both return zero responses; "Billie Jean" returns
1083 files. The Weeknd, Kanye West and Frank Ocean behave the same way. Since
pick_and_enqueue sent exactly one query of `artist title`, every request for a
filtered artist failed reporting "searched 0 files" -- 28 of 29 occurrences.
search_queries() now walks a ladder, loosest last, ending at the bare title,
and escalates only when a search underdelivers so the common case still costs
one search. Dropping the artist from the query does not mean ignoring it:
match_ratio() looks for it in the folder path, where an organised share puts it.

A rejected transfer ended the request. pick_and_enqueue kept a running maximum
and discarded every runner-up, so "Transfer rejected: File not shared." -- a
per-file condition where candidate two almost always works -- was terminal, as
were timeouts and slskd's 500 on an unreachable peer. The ranked list is now
persisted on the job row, ordered to put a different peer next, and
try_next_candidate() advances through it. A job fails only once the list is
exhausted, and then reports every peer it tried and what each one said.

norm() destroyed every non-ASCII character, so "Beyonce" never matched
Beyonce, nor Bjork Bjork, nor Dont Don't. It now folds accents and drops
apostrophes while leaving & as a separator.

Also: availability outranks format in score(), because a FLAC behind 5000
queued users used to beat an immediately available MP3; transfers that stall or
that slskd forgets are abandoned instead of sitting in `downloading` forever;
searches are deleted only once finished, since deleting one mid-flight makes
slskd throw an optimistic-concurrency error and lose the record; a failed
search POST is retried rather than failing the job on one blip.

The UI moves to a sidebar shell -- rail at tablet, bottom bar on phones -- with
neutral chrome and the sampled artwork colour confined to hero areas rather
than repainting the whole interface. Adds URL routing, a primitive set under
components/ui, and a request sheet showing the attempt ladder. Fixes
hover:bg-glass-hi, which was never a valid class, so track rows and the search
field had no hover or focus state at all; a reduced-motion path that could
strand elements at opacity 0; the login page's hardcoded palette; and the
missing 404 and error boundaries.

tests/test_acquisition.py covers this path against a faked slskd. It had none.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-02 11:33:52 -05:00

172 lines
6.4 KiB
TypeScript

"use client";
import * as React from "react";
import { motion } from "framer-motion";
import { Bell, BellOff, Mail } from "lucide-react";
import { api, type Me } from "@/lib/api";
import { useToast } from "@/components/toast";
import { Button } from "@/components/ui/button";
import { cn } from "@/lib/utils";
/** Your own notification settings. Not behind admin on purpose: an address
* you cannot change yourself turns into someone else's chore. */
export function Settings({ me, refresh }: { me: Me; refresh: () => void }) {
const toast = useToast();
const [email, setEmail] = React.useState(me.email ?? "");
const [notify, setNotify] = React.useState(me.notify ?? true);
const [busy, setBusy] = React.useState(false);
const dirty = email !== (me.email ?? "") || notify !== (me.notify ?? true);
const save = async () => {
setBusy(true);
try {
await api.settings({ email: email.trim(), notify });
toast("Settings saved");
refresh();
} catch (e) {
toast((e as Error).message, true);
}
setBusy(false);
};
const googleImplicit = me.provider === "google" && !me.email;
// MUSE_AUTH=off means there is no account to attach a preference to, and
// PATCH /api/me would 401. Say so rather than offering a form that fails.
const anonymous = !me.user;
return (
<motion.div
initial={{ opacity: 0, y: 10 }}
animate={{ opacity: 1, y: 0 }}
className="flex flex-col gap-4"
>
{anonymous && (
<div className="card rounded-panel border-warn/40 p-4 text-callout text-warn">
Authentication is turned off on this instance, so there is no account to
save preferences against. Set <code className="font-mono text-[12px]">MUSE_AUTH</code>{" "}
to <code className="font-mono text-[12px]">github</code> or{" "}
<code className="font-mono text-[12px]">google</code> to enable sign-in.
</div>
)}
<section className="card rounded-panel p-5">
<div className="mb-1 flex items-center gap-2">
<Mail className="h-4 w-4 text-accent" />
<h2 className="text-headline">Notifications</h2>
</div>
<p className="mb-4 max-w-[58ch] text-callout text-dim">
muse can email you when a request lands in your library, or when a download
finished but needs your call before it&rsquo;s filed.
</p>
{!me.mail_configured && (
<div className="mb-4 rounded-card border border-warn/40 bg-[var(--surface)] p-3 text-callout text-warn">
No SMTP server is configured on this instance, so nothing will actually be
sent. Set <code className="font-mono text-[12px]">MUSE_SMTP_HOST</code> and{" "}
<code className="font-mono text-[12px]">MUSE_SMTP_FROM</code> to turn it on.
</div>
)}
<label className="flex max-w-md flex-col gap-1.5">
<span className="text-caption uppercase tracking-[0.7px] text-dim">
Where to write
</span>
<input
type="email"
value={email}
onChange={(e) => setEmail(e.target.value)}
onKeyDown={(e) => e.key === "Enter" && dirty && save()}
disabled={anonymous}
placeholder={googleImplicit ? me.user ?? "you@example.com" : "you@example.com"}
className="focus-ring rounded-control border border-edge-hi bg-transparent px-3 py-2
text-body outline-none transition focus:border-accent-line
disabled:opacity-45"
/>
{googleImplicit && (
<span className="text-caption text-dim">
Blank uses your Google address, {me.user}.
</span>
)}
</label>
<button
onClick={() => setNotify(!notify)}
role="switch"
aria-checked={notify}
disabled={anonymous}
className="focus-ring mt-4 flex cursor-pointer items-center gap-3 rounded-card
text-left disabled:cursor-default disabled:opacity-45"
>
<span
className={cn(
"relative h-[26px] w-[44px] shrink-0 rounded-pill border transition-colors",
notify ? "border-accent-line bg-accent-soft" : "border-edge bg-faint",
)}
>
<motion.span
layout
transition={{ type: "spring", stiffness: 520, damping: 34 }}
className={cn(
"absolute top-[2px] h-[20px] w-[20px] rounded-full",
notify ? "left-[21px] bg-accent" : "left-[2px] bg-dim",
)}
/>
</span>
<span className="flex items-center gap-1.5 text-body">
{notify ? (
<Bell className="h-3.5 w-3.5 text-accent" />
) : (
<BellOff className="h-3.5 w-3.5 text-dim" />
)}
{notify ? "Email me about my requests" : "Don't email me"}
</span>
</button>
<div className="mt-5">
<Button onClick={save} disabled={!dirty || busy || anonymous}>
{busy ? "Saving…" : "Save"}
</Button>
</div>
</section>
<section className="card rounded-panel p-5">
<h2 className="mb-3 text-headline">Account</h2>
{anonymous ? (
<p className="text-callout text-dim">
Nobody is signed in — every request is anonymous and every role check
reports admin.
</p>
) : (
<dl className="grid gap-x-6 gap-y-2 text-callout sm:grid-cols-[auto_1fr]">
<Field k="Signed in as" v={me.display || me.user || "—"} />
<Field k="Identity" v={`${me.user} · ${me.provider ?? "—"}`} />
<Field k="Role" v={me.role ?? "—"} />
<Field
k="Requests this month"
v={
me.quota
? `${me.usage?.requests ?? 0} of ${me.quota}`
: `${me.usage?.requests ?? 0} · no limit`
}
/>
</dl>
)}
<p className="mt-4 max-w-[58ch] text-caption text-dim">
muse is the front door. Playback, playlists and listening history live in
Navidrome — this only decides what gets into the library.
</p>
</section>
</motion.div>
);
}
function Field({ k, v }: { k: string; v: string }) {
return (
<>
<dt className="text-dim">{k}</dt>
<dd className="clamp1">{v}</dd>
</>
);
}