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.
65 lines
2.6 KiB
TypeScript
65 lines
2.6 KiB
TypeScript
/**
|
|
* Parse lyrics text into displayable lines. `.lrc` carries `[mm:ss.xx]` timestamps (possibly several per
|
|
* line, e.g. repeated choruses) and metadata tags ([ar:], [ti:], …) which are dropped. `.txt` is plain.
|
|
* A synced result is sorted by time so the active-line lookup is a simple scan.
|
|
*
|
|
* Ported from the mobile app (packages/core/src/services/lyrics.ts) — same file format, same server,
|
|
* so the two must agree on what a line is.
|
|
*/
|
|
export type LyricLine = { timeSec?: number; text: string };
|
|
export type ParsedLyrics = { synced: boolean; lines: LyricLine[] };
|
|
|
|
const TIME_RE = /\[(\d{1,2}):(\d{2})(?:[.:](\d{1,3}))?\]/g;
|
|
const META_RE = /^\[(ar|ti|al|by|offset|length|re|ve|au|la|id):/i;
|
|
|
|
/**
|
|
* Lines are treated as synced whenever the text actually contains `[mm:ss]` timestamps — the server's
|
|
* `X-Lyrics-Format` header is not trusted (it need not survive a proxy, and embedded lyrics carrying
|
|
* timestamps should sync regardless of which file they came from). No timestamps → plain text.
|
|
*/
|
|
export function parseLyrics(text: string): ParsedLyrics {
|
|
if (!/\[\d{1,2}:\d{2}/.test(text)) {
|
|
return { synced: false, lines: text.split(/\r?\n/).map((t) => ({ text: t.trim() })) };
|
|
}
|
|
|
|
const out: LyricLine[] = [];
|
|
for (const rawLine of text.split(/\r?\n/)) {
|
|
if (META_RE.test(rawLine.trim())) continue;
|
|
const stamps: number[] = [];
|
|
let m: RegExpExecArray | null;
|
|
TIME_RE.lastIndex = 0;
|
|
while ((m = TIME_RE.exec(rawLine)) !== null) {
|
|
const min = Number(m[1]);
|
|
const sec = Number(m[2]);
|
|
// "[00:12.3]" is three tenths, not three milliseconds — pad right before reading as thousandths.
|
|
const frac = m[3] ? Number(`${m[3]}00`.slice(0, 3)) / 1000 : 0;
|
|
stamps.push(min * 60 + sec + frac);
|
|
}
|
|
const lyric = rawLine.replace(TIME_RE, '').trim();
|
|
if (!stamps.length) {
|
|
if (lyric) out.push({ text: lyric }); // a plain line inside an otherwise-synced file
|
|
continue;
|
|
}
|
|
for (const t of stamps) out.push({ timeSec: t, text: lyric });
|
|
}
|
|
|
|
const synced = out.some((l) => l.timeSec != null);
|
|
if (synced) out.sort((a, b) => (a.timeSec ?? 0) - (b.timeSec ?? 0));
|
|
return { synced, lines: out };
|
|
}
|
|
|
|
/**
|
|
* Index of the active line for a playback position (synced only); -1 before the first line. The 0.2s
|
|
* lookahead lands the highlight fractionally early, which reads as on-time — arriving late reads as lag.
|
|
*/
|
|
export function activeLineIndex(lines: LyricLine[], positionSec: number): number {
|
|
let idx = -1;
|
|
for (let i = 0; i < lines.length; i++) {
|
|
const t = lines[i]?.timeSec;
|
|
if (t == null) continue;
|
|
if (t <= positionSec + 0.2) idx = i;
|
|
else break;
|
|
}
|
|
return idx;
|
|
}
|