TRACES: | DR-204 484 ungated `console.*` calls across 63 non-test frontend files shipped to end users with no way to turn them off. Mechanical substitution, no control flow, error handling or message semantics changed: console.log / console.debug -> log.debug console.info -> log.info console.warn -> log.warn console.error -> log.error Hand-written `"[Scope] …"` prefixes are dropped where the logger's scope now carries them; scope names that already existed are preserved verbatim (`[Auth]`, `[VideoPlayer]`, `[PiP]`, …) and inferred from the filename where a file had none. `src/routes/player/[id]/+page.svelte` keeps its `NextEpisode` and `AutoPlay` sub-scopes as separate loggers rather than flattening them into the page scope. `grep -rn 'console\.' src/` now matches nothing outside the tests and the facade itself.
61 lines
1.6 KiB
TypeScript
61 lines
1.6 KiB
TypeScript
/**
|
|
* Device ID Management Service
|
|
*
|
|
* Manages device identification for Jellyfin server communication.
|
|
* The Rust backend handles UUID generation and persistent storage in the database.
|
|
* This service provides a simple interface with in-memory caching.
|
|
*
|
|
* TRACES: UR-009 | DR-011
|
|
*/
|
|
|
|
import { commands } from "$lib/api/bindings";
|
|
import { createLogger } from "$lib/utils/logger";
|
|
|
|
const log = createLogger("deviceId");
|
|
|
|
let cachedDeviceId: string | null = null;
|
|
|
|
/**
|
|
* Get or create the device ID.
|
|
* Device ID is a UUID v4 that persists across app restarts.
|
|
* On first call, the Rust backend generates and stores a new UUID.
|
|
* On subsequent calls, the stored UUID is retrieved.
|
|
*
|
|
* @returns The device ID string (UUID v4)
|
|
*
|
|
* TRACES: UR-009 | DR-011
|
|
*/
|
|
export async function getDeviceId(): Promise<string> {
|
|
// Return cached value if available
|
|
if (cachedDeviceId) {
|
|
return cachedDeviceId;
|
|
}
|
|
|
|
try {
|
|
// Rust backend handles generation and storage atomically
|
|
const deviceId = await commands.deviceGetId();
|
|
cachedDeviceId = deviceId;
|
|
return deviceId;
|
|
} catch (e) {
|
|
log.error("Failed to get device ID from backend:", e);
|
|
throw new Error("Failed to initialize device ID: " + String(e));
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Get cached device ID synchronously (if available)
|
|
* This should only be used after initial getDeviceId() call
|
|
*
|
|
* @returns The cached device ID, or empty string if not yet initialized
|
|
*/
|
|
export function getDeviceIdSync(): string {
|
|
return cachedDeviceId || "";
|
|
}
|
|
|
|
/**
|
|
* Clear cached device ID (for testing or logout scenarios)
|
|
*/
|
|
export function clearCache(): void {
|
|
cachedDeviceId = null;
|
|
}
|