shared.ts
| 1 | import path from "node:path"; |
| 2 | import type { ProbeData } from "./utils"; |
| 3 | import commandExists from "command-exists"; |
| 4 | |
| 5 | export const coverRegex = process.env.COVER_REGEX === undefined ? /(cover)|(folder).(png|jpg)$/i : ""; |
| 6 | export const musicRoot = process.env.MUSIC_ROOT || ""; |
| 7 | if (musicRoot === "") { |
| 8 | console.error("Please define the environment variable MUSIC_ROOT"); |
| 9 | process.exit(1); |
| 10 | } |
| 11 | |
| 12 | if (!path.isAbsolute(musicRoot)) { |
| 13 | console.error(`Music root ${musicRoot} is not absolute`); |
| 14 | process.exit(1); |
| 15 | } |
| 16 | |
| 17 | export const excludeExtension = |
| 18 | process.env.EXCLUDE_EXTENSION === undefined ? ["txt", "log", "nfo", "m3u", "htm", "html"] : process.env.EXCLUDE_EXTENSION.split(","); |
| 19 | |
| 20 | if (!commandExists.sync("ffmpeg")) { |
| 21 | console.error("Required command ffmpeg not found in PATH"); |
| 22 | process.exit(1); |
| 23 | } |
| 24 | if (!commandExists.sync("tar")) { |
| 25 | console.error("Required command tar not found in PATH"); |
| 26 | process.exit(1); |
| 27 | } |
| 28 | if (!commandExists.sync("avifenc")) { |
| 29 | console.error("Required command avifenc not found in PATH"); |
| 30 | process.exit(1); |
| 31 | } |
| 32 | |
| 33 | export const mediaTypes = ["audio", "video"]; |
| 34 | export const allowedTypes = [...mediaTypes, "image"]; |
| 35 | |
| 36 | export const fileTypeCache = new Map<string, string>(); |
| 37 | export const probeCache = new Map<string, ProbeData>(); |
| 38 | export const generatedPlaylistIds = new Map<string, string[]>(); |
| 39 | |
| 40 | export class PathInfo { |
| 41 | constructor(public mimeType: string) {} |
| 42 | } |
| 43 | |
| 44 | export class ServerError { |
| 45 | constructor( |
| 46 | public status: number, |
| 47 | public error: string, |
| 48 | ) {} |
| 49 | } |
| 50 |