Files
jellytau/src/lib/services/preload.ts
T
dtourolle d54d8cc7c4 refactor(logging): route frontend console calls through the logger
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.
2026-08-20 19:29:59 +02:00

75 lines
2.0 KiB
TypeScript

/**
* Smart preloading service for upcoming tracks
* Automatically queues downloads for the next few tracks in the queue
*
* TRACES: UR-004, UR-011 | DR-006, DR-015
*/
import { commands } from '$lib/api/bindings';
import type { CacheConfig } from '$lib/api/bindings';
import { auth } from '$lib/stores/auth';
import { createLogger } from '$lib/utils/logger';
const log = createLogger('Preload');
interface PreloadOptions {
/** Enable debug logging */
debug?: boolean;
/** Override user ID (defaults to current session user) */
userId?: string;
}
/**
* Trigger preloading for upcoming tracks in the queue
* This should be called after playback starts or advances to the next track
*/
export async function preloadUpcomingTracks(options: PreloadOptions = {}): Promise<void> {
const { debug = false, userId: overrideUserId } = options;
try {
// Get current user ID
const userId = overrideUserId || auth.getUserId();
if (!userId) {
if (debug) log.debug('No active user session, skipping preload');
return;
}
if (debug) log.debug('Triggering preload for user:', userId);
// downloadBasePath is currently unused in the backend
const result = await commands.playerPreloadUpcoming(userId, '/downloads');
if (debug) {
log.debug('Result:', {
queued: result.queuedCount,
alreadyDownloaded: result.alreadyDownloaded,
skipped: result.skipped
});
}
// Log meaningful results
if (result.queuedCount > 0) {
log.debug(`Queued ${result.queuedCount} track(s) for background download`);
}
} catch (error) {
// Fail silently - preloading is a background optimization
// Don't interrupt the user's playback experience
log.warn('Failed to preload upcoming tracks:', error);
}
}
/**
* Update smart cache configuration
*/
export async function updateCacheConfig(config: CacheConfig): Promise<void> {
await commands.playerSetCacheConfig(config);
}
/**
* Get current cache configuration
*/
export async function getCacheConfig(): Promise<CacheConfig> {
return await commands.playerGetCacheConfig();
}