The whole of music moves to plugins/music/: the sidecar (index, indexer,
stream-audio, nightly-reindex), the four Postgres tables and their queries,
the /music workspace panels, MUSIC_API.md and the reindex CLI. The platform
keeps no music routes, no music capability entry, no music screen and no
music schema.
Three things stayed, each on purpose.
cliamp and the widget were out of scope by the owner's decision. The plugin's
sidecar still serves the two cliamp sockets, so it imports cliamp-ws.ts and
pulse-audio.ts from @@/sidecar/music/ — the files stay where they were.
The player did not move, and that was the open judgement call. Deciding it
took one fact: the dashboard widget imports useMusicPlayer and PlayerTrack
from officerdev, and the platform cannot import from a plugin. So the player
STATE stays whatever is decided about the UI around it, and two copies would
mean two audio engines. Given that, the engine and the bar stayed with the
state rather than being split from the thing they drive. Moving them would
also have needed a shell slot rendering a plugin-provided component on every
route — the one escape hatch this system deleted on purpose. MusicPlayerHost
gates on can('music'), which is now the plugin's permission, so the seam
switches itself off with the plugin.
api/music/router.ts stays too: api/cliamp/relay.ts imports getMusicServerWsUrl
from it. The plugin's api/router.ts re-exports that proxy rather than building
a second one — two subscribers to the one-shot music:server port announcement
would work today and 503 on the first reconnect where only one was listening.
Two bugs found on the way, neither visible from reading.
The app-store catalogue still listed music. Availability is derived from
sidecar_installs and a PLUGIN never gets a row there, so `music` would have
been permanently unavailable — which puts /music into deniedRoutes and blanks
the screen on a server where the plugin was installed and healthy. Exactly
the headscale bug documented six lines above it in the same file, and it would
have fired on the first install. Entry removed.
[test] root was "./src", so moving lyrics.test.ts into plugins/ stopped it
running and said nothing — the count fell by nine and the suite still read
green. Root is now the repo. Positional filters cannot fix this: `bun test
plugins` matches under root and finds src/servers/plugins/ instead.
registry.test.ts tested the `personal` mechanism THROUGH the music capability.
Re-anchored on a fixture rather than on another entry, because borrowing a
feature only moves the problem to the next extraction — and three of those
four tests had been passing for the wrong reason since music's api was
commented out on 2026-08-13, when everything started resolving to "refused
because nothing is claimed". The cliamp sockets being claimed by nothing is
now pinned by a test instead of being rediscovered.
music's `personal` paths ride across on readOnlyWrites, the one field a
manifest has. isRequestAllowedAtLevel concatenates the two lists, so a read
grant permits exactly the four paths it permitted yesterday, and no field was
added to the manifest to design a per-user model that is not this work.
bunx tsgo clean. 772 tests, 762 pass, 7 fail — all seven pre-existing and
unrelated (cliamp, pty, and five capability tests that other switched-off
plugins break). Baseline was 757/10; the three that went green are the ones
re-anchored above.
Not yet verified on the live server — that is next.
216 lines
7.4 KiB
TypeScript
216 lines
7.4 KiB
TypeScript
import { useState, type ReactNode } from 'react';
|
|
import { Link, useNavigate } from 'react-router';
|
|
import { useClient } from 'hooks/useClient';
|
|
import { usePanelChannel } from 'hooks/usePanelChannel';
|
|
import { Heart, User, Disc3, Music, ChevronRight, X } from 'lucide-react';
|
|
import { useMusicPlayer, type PlayerTrack } from 'officerdev';
|
|
import { MusicHeart } from 'officerdev';
|
|
import { useMusicFavorites } from 'officerdev';
|
|
import {
|
|
MUSIC_FAV_CHANNEL,
|
|
coverUrl,
|
|
musicPath,
|
|
parseAlbumName,
|
|
sortTracks,
|
|
toRel,
|
|
type AlbumMeta,
|
|
type FavoriteKind,
|
|
} from './shared';
|
|
|
|
// The user's favorited artists / albums / tracks, grouped — shown in the right panel. Keys follow the
|
|
// favorites convention: album/artist are music-relative ("Albums/…"), tracks are home paths
|
|
// ("Music/…/file"). An album/artist row is a link into the library; a track row plays, so it stays a
|
|
// button — it mutates rather than navigates, even though it also moves the library to the album.
|
|
export const FavoritesView = () => {
|
|
const { get, token } = useClient();
|
|
const navigate = useNavigate();
|
|
const player = useMusicPlayer();
|
|
const { favorites } = useMusicFavorites();
|
|
const [, setFavOpen] = usePanelChannel<boolean>(MUSIC_FAV_CHANNEL, false);
|
|
|
|
const playTrack = async (homePath: string) => {
|
|
const cut = homePath.lastIndexOf('/');
|
|
const albumHome = homePath.slice(0, cut);
|
|
const file = homePath.slice(cut + 1);
|
|
const albumRel = toRel(albumHome);
|
|
try {
|
|
const meta = await get<AlbumMeta>(`/music/meta?path=${encodeURIComponent(albumRel)}`);
|
|
const q: PlayerTrack[] = sortTracks(meta.tracks).map((t) => ({
|
|
albumRel,
|
|
file: t.file,
|
|
title: t.title,
|
|
artist: t.artist,
|
|
}));
|
|
player.playQueue(
|
|
q,
|
|
Math.max(
|
|
0,
|
|
q.findIndex((t) => t.file === file),
|
|
),
|
|
);
|
|
} catch {
|
|
player.playQueue([{ albumRel, file }], 0);
|
|
}
|
|
navigate(musicPath(albumRel));
|
|
setFavOpen(false);
|
|
};
|
|
|
|
const empty = !favorites.artists.length && !favorites.albums.length && !favorites.tracks.length;
|
|
|
|
return (
|
|
<div className="h-full overflow-y-auto p-4 md:p-6">
|
|
<div className="mb-4 flex items-center gap-2">
|
|
<Heart size={20} className="fill-red-500 text-red-500" />
|
|
<h1 className="flex-1 text-2xl font-bold text-foreground">Favorites</h1>
|
|
<button
|
|
type="button"
|
|
onClick={() => setFavOpen(false)}
|
|
className="cursor-pointer rounded p-1.5 text-muted-foreground hover:bg-muted hover:text-foreground"
|
|
>
|
|
<X size={18} />
|
|
</button>
|
|
</div>
|
|
|
|
{empty ? (
|
|
<div className="flex flex-col items-center justify-center gap-3 py-24 text-center">
|
|
<Heart size={44} className="text-muted-foreground/30" />
|
|
<p className="text-sm text-muted-foreground">
|
|
No favorites yet. Click the heart on any artist, album or track.
|
|
</p>
|
|
</div>
|
|
) : (
|
|
<div className="flex flex-col gap-6">
|
|
<Section title="Artists" count={favorites.artists.length}>
|
|
{favorites.artists.map((key) => {
|
|
const segs = key.split('/');
|
|
return (
|
|
<FavRow
|
|
key={key}
|
|
kind="artist"
|
|
favKey={key}
|
|
cover={coverUrl(key, token)}
|
|
fallback={<User size={18} className="text-muted-foreground" />}
|
|
title={segs[segs.length - 1] ?? key}
|
|
to={musicPath(key)}
|
|
onClick={() => setFavOpen(false)}
|
|
chevron
|
|
/>
|
|
);
|
|
})}
|
|
</Section>
|
|
|
|
<Section title="Albums" count={favorites.albums.length}>
|
|
{favorites.albums.map((key) => {
|
|
const segs = key.split('/');
|
|
const { title, year } = parseAlbumName(segs[segs.length - 1] ?? key);
|
|
const artist = segs.length >= 3 ? segs[1] : '';
|
|
return (
|
|
<FavRow
|
|
key={key}
|
|
kind="album"
|
|
favKey={key}
|
|
cover={coverUrl(key, token)}
|
|
fallback={<Disc3 size={18} className="text-muted-foreground" />}
|
|
title={title}
|
|
subtitle={[artist, year].filter(Boolean).join(' · ')}
|
|
to={musicPath(key)}
|
|
onClick={() => setFavOpen(false)}
|
|
chevron
|
|
/>
|
|
);
|
|
})}
|
|
</Section>
|
|
|
|
<Section title="Tracks" count={favorites.tracks.length}>
|
|
{favorites.tracks.map((key) => {
|
|
const segs = key.split('/');
|
|
const base = segs[segs.length - 1] ?? key;
|
|
const albumRel = toRel(key.slice(0, Math.max(0, key.lastIndexOf('/'))));
|
|
const album = segs.length >= 2 ? parseAlbumName(segs[segs.length - 2]!).title : '';
|
|
return (
|
|
<FavRow
|
|
key={key}
|
|
kind="track"
|
|
favKey={key}
|
|
cover={coverUrl(albumRel, token)}
|
|
fallback={<Music size={18} className="text-muted-foreground" />}
|
|
title={base.replace(/\.[^/.]+$/, '')}
|
|
subtitle={album}
|
|
onClick={() => playTrack(key)}
|
|
/>
|
|
);
|
|
})}
|
|
</Section>
|
|
</div>
|
|
)}
|
|
</div>
|
|
);
|
|
};
|
|
|
|
const Section = ({ title, count, children }: { title: string; count: number; children: ReactNode }) =>
|
|
count ? (
|
|
<div>
|
|
<h2 className="mb-1 px-2 text-xs font-semibold uppercase tracking-wide text-muted-foreground">
|
|
{title} <span className="text-muted-foreground/60">{count}</span>
|
|
</h2>
|
|
<div className="flex flex-col">{children}</div>
|
|
</div>
|
|
) : null;
|
|
|
|
// `to` makes the row an anchor (an album or artist, which is a place); without it the row is a button
|
|
// (a track, which plays). The heart stays a sibling either way — it must not be inside either one.
|
|
const FavRow = ({
|
|
kind,
|
|
favKey,
|
|
cover,
|
|
fallback,
|
|
title,
|
|
subtitle,
|
|
to,
|
|
onClick,
|
|
chevron,
|
|
}: {
|
|
kind: FavoriteKind;
|
|
favKey: string;
|
|
cover: string;
|
|
fallback: ReactNode;
|
|
title: string;
|
|
subtitle?: string;
|
|
to?: string;
|
|
onClick: () => void;
|
|
chevron?: boolean;
|
|
}) => {
|
|
const [failed, setFailed] = useState(false);
|
|
const inner = (
|
|
<>
|
|
<div className="flex h-11 w-11 shrink-0 items-center justify-center overflow-hidden rounded bg-muted">
|
|
{cover && !failed ? (
|
|
<img src={cover} alt="" className="h-full w-full object-cover" onError={() => setFailed(true)} />
|
|
) : (
|
|
fallback
|
|
)}
|
|
</div>
|
|
<div className="min-w-0 flex-1">
|
|
<span className="block truncate text-sm text-foreground">{title}</span>
|
|
{subtitle ? <span className="block truncate text-xs text-muted-foreground">{subtitle}</span> : null}
|
|
</div>
|
|
</>
|
|
);
|
|
const cls = 'flex min-w-0 flex-1 cursor-pointer items-center gap-3 text-left';
|
|
return (
|
|
<div className="group flex items-center gap-3 rounded-md px-2 py-1.5 hover:bg-muted">
|
|
{to ? (
|
|
<Link to={to} onClick={onClick} className={cls}>
|
|
{inner}
|
|
</Link>
|
|
) : (
|
|
<button type="button" onClick={onClick} className={cls}>
|
|
{inner}
|
|
</button>
|
|
)}
|
|
<MusicHeart kind={kind} favKey={favKey} size={16} className="shrink-0" />
|
|
{chevron ? <ChevronRight size={16} className="shrink-0 text-muted-foreground" /> : null}
|
|
</div>
|
|
);
|
|
};
|