Rewrites the web app's comments to rule 32. Task, milestone, rule and spec ids are gone; regression stories are restated as the trap they guard (public auth routes, the menu's stopPropagation, universal loads under adapter-static, metric deltas with their margin). Flutter and Tauri mentions now name the Android app or a native shell, operator quotes and dates are dropped, and one library's counts no longer appear outside test fixtures. Verified with a TypeScript-scanner token comparison (template literals and regex literals re-scanned): only comment text changed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
63 lines
2.3 KiB
TypeScript
63 lines
2.3 KiB
TypeScript
import { api, apiFetch } from './client';
|
|
|
|
// Loudness normalization preference. One per user, stored on
|
|
// the server so the web player, the Android app and casts agree.
|
|
export type NormalizationMode = 'off' | 'auto' | 'track' | 'album';
|
|
export type NormalizationTarget = -18 | -16 | -14;
|
|
export type NormalizationBoost = 'headroom' | 'limiter';
|
|
|
|
export type NormalizationPrefs = {
|
|
mode: NormalizationMode;
|
|
target_lufs: NormalizationTarget;
|
|
boost: NormalizationBoost;
|
|
};
|
|
|
|
// Must match library.DefaultNormalizationPrefs on the server.
|
|
export const DEFAULT_NORMALIZATION: NormalizationPrefs = {
|
|
mode: 'auto',
|
|
target_lufs: -18,
|
|
boost: 'headroom'
|
|
};
|
|
|
|
export const NORMALIZATION_MODES: NormalizationMode[] = ['off', 'auto', 'track', 'album'];
|
|
export const NORMALIZATION_TARGETS: NormalizationTarget[] = [-18, -16, -14];
|
|
|
|
export function isNormalizationPrefs(v: unknown): v is NormalizationPrefs {
|
|
if (typeof v !== 'object' || v === null) return false;
|
|
const p = v as Record<string, unknown>;
|
|
return (
|
|
NORMALIZATION_MODES.includes(p.mode as NormalizationMode) &&
|
|
NORMALIZATION_TARGETS.includes(p.target_lufs as NormalizationTarget) &&
|
|
(p.boost === 'headroom' || p.boost === 'limiter')
|
|
);
|
|
}
|
|
|
|
export function getNormalization(): Promise<NormalizationPrefs> {
|
|
return api.get<NormalizationPrefs>('/api/me/normalization');
|
|
}
|
|
|
|
// The whole preference is sent every time; the server keeps the last write.
|
|
export function putNormalization(p: NormalizationPrefs): Promise<NormalizationPrefs> {
|
|
return api.put<NormalizationPrefs>('/api/me/normalization', p);
|
|
}
|
|
|
|
// Per-track gains: dB to the -18 LUFS ReplayGain reference and linear
|
|
// peaks. A field is absent until the server has measured it.
|
|
export type ReplayGain = {
|
|
track_gain?: number;
|
|
track_peak?: number;
|
|
album_gain?: number;
|
|
album_peak?: number;
|
|
};
|
|
|
|
/**
|
|
* Gains for up to 200 tracks; an id missing from items has none yet. Given
|
|
* a deadline: the player waits on it, and a request that never answers
|
|
* would leave those tracks unleveled for the rest of the session.
|
|
*/
|
|
export function getReplayGain(ids: string[]): Promise<{ items: Record<string, ReplayGain> }> {
|
|
return apiFetch(`/api/tracks/replay-gain?ids=${ids.map(encodeURIComponent).join(',')}`, {
|
|
signal: AbortSignal.timeout(10_000)
|
|
}) as Promise<{ items: Record<string, ReplayGain> }>;
|
|
}
|