- Extract shared utilities (HIDDEN_FILES, VIDEO_EXTENSIONS, fileApiUrl, thumbnailApiUrl, findFile) into new src/lib/media-utils.ts, removing identical copies from games.ts, movies.ts, tv.ts, files.ts, and scanner.ts - Add comment in files.ts clarifying why its VIDEO_EXTENSIONS set intentionally differs from the media library set (web-playable formats for the mixed browser) - Rewrite README to reflect the current feature set: Movies/TV libraries, auth system, tag system, background scanner, updated project structure, folder conventions for all four library types, and a complete API reference Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
32 lines
1.0 KiB
TypeScript
32 lines
1.0 KiB
TypeScript
import fs from 'fs'
|
|
import path from 'path'
|
|
|
|
export const HIDDEN_FILES = /^\./
|
|
|
|
/** Video extensions for dedicated media libraries (movies, TV). */
|
|
export const VIDEO_EXTENSIONS = new Set(['.mkv', '.mp4', '.avi', '.mov', '.m4v', '.wmv', '.ts', '.m2ts'])
|
|
|
|
export function fileApiUrl(libraryId: string, relativePath: string): string {
|
|
return `/api/file?libraryId=${encodeURIComponent(libraryId)}&path=${encodeURIComponent(relativePath)}`
|
|
}
|
|
|
|
export function thumbnailApiUrl(libraryId: string, relativePath: string): string {
|
|
return `/api/thumbnail?libraryId=${encodeURIComponent(libraryId)}&path=${encodeURIComponent(relativePath)}`
|
|
}
|
|
|
|
/**
|
|
* Finds the first non-hidden file in a directory whose basename (without extension)
|
|
* matches the given pattern (case-insensitive).
|
|
*/
|
|
export function findFile(dir: string, pattern: RegExp): string | null {
|
|
let entries: string[]
|
|
try {
|
|
entries = fs.readdirSync(dir)
|
|
} catch {
|
|
return null
|
|
}
|
|
return entries.find(
|
|
(e) => !HIDDEN_FILES.test(e) && pattern.test(path.basename(e, path.extname(e)))
|
|
) ?? null
|
|
}
|