mirror of
https://github.com/kilyabin/psysonic.git
synced 2026-07-21 22:15:40 +00:00
4d564e5016
First slice of the authStore split. Pure code-move: no behaviour change. - `authStoreTypes.ts` — `ServerProfile`, `AuthState`, plus all union types (`SeekbarStyle`, `LoggingMode`, `NormalizationEngine`, `DiscordCoverSource`, `LoudnessLufsPreset`, `LyricsSourceId`, `LyricsSourceConfig`, `TrackPreviewLocation`, `TrackPreviewLocations`). - `authStoreDefaults.ts` — `LOUDNESS_LUFS_PRESETS`, `DEFAULT_LOUDNESS_PRE_ANALYSIS_ATTENUATION_DB`, `TRACK_PREVIEW_LOCATIONS`, `DEFAULT_TRACK_PREVIEW_LOCATIONS`, `DEFAULT_LYRICS_SOURCES`, `MIX_MIN_RATING_FILTER_MAX_STARS`, `RANDOM_MIX_SIZE_OPTIONS`. - `authStoreHelpers.ts` — `generateId`, `sanitizeLoudnessLufsPreset`, `sanitizeLoudnessPreAnalysisFromStorage`, `clampMixFilterMinStars`, `clampRandomMixSize`, `clampSkipStarThreshold`, `skipStarCountStorageKey`, `sanitizeSkipStarCounts`. 12 external call sites migrated to direct imports from the new modules (no re-export shims left in authStore.ts — applies the [feedback_prevent_god_modules] rule 5: avoid re-export debt). authStore.ts: 889 → 518 LOC (−371).
36 lines
1.2 KiB
TypeScript
36 lines
1.2 KiB
TypeScript
import type { ServerProfile } from '../store/authStoreTypes';
|
|
/** Host (+ port) from a server base URL, e.g. `https://music.one.com/foo` → `music.one.com`. */
|
|
export function shortHostFromServerUrl(urlRaw: string): string {
|
|
const t = urlRaw.trim();
|
|
if (!t) return '';
|
|
try {
|
|
const u = new URL(t.includes('://') ? t : `https://${t}`);
|
|
return u.host;
|
|
} catch {
|
|
return t
|
|
.replace(/^https?:\/\//i, '')
|
|
.split('/')[0]
|
|
?.split('?')[0]
|
|
?.trim() ?? t;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Label for server lists and chrome: if several servers share the same effective name,
|
|
* show `username@host` so entries stay distinguishable.
|
|
*/
|
|
export function serverListDisplayLabel(server: ServerProfile, all: ServerProfile[]): string {
|
|
const nameTrim = (server.name || '').trim();
|
|
const shortHost = shortHostFromServerUrl(server.url);
|
|
const key = nameTrim || shortHost;
|
|
const collisions = all.filter(s => {
|
|
const nt = (s.name || '').trim();
|
|
const sh = shortHostFromServerUrl(s.url);
|
|
return (nt || sh) === key;
|
|
});
|
|
if (collisions.length < 2) {
|
|
return nameTrim || shortHost || server.url.trim();
|
|
}
|
|
return `${server.username}@${shortHost}`;
|
|
}
|