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 || /(C|c)over.(png|jpg)$/; |
| 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 | if (!commandExists.sync("ffmpeg")) { |
| 18 | console.error("Required command ffmpeg not found in PATH"); |
| 19 | process.exit(1); |
| 20 | } |
| 21 | if (!commandExists.sync("ffprobe")) { |
| 22 | console.error("Required command ffprobe not found in PATH"); |
| 23 | process.exit(1); |
| 24 | } |
| 25 | if (!commandExists.sync("tar")) { |
| 26 | console.error("Required command tar not found in PATH"); |
| 27 | process.exit(1); |
| 28 | } |
| 29 | |
| 30 | export const mediaTypes = ["audio", "video"]; |
| 31 | export const allowedTypes = [...mediaTypes, "image"]; |
| 32 | |
| 33 | export const fileTypeCache = new Map<string, string>(); |
| 34 | export const probeCache = new Map<string, ProbeData>(); |
| 35 | export const generatedPlaylistIds = new Map<string, string[]>(); |
| 36 | |
| 37 | export class PathInfo { |
| 38 | constructor(public mimeType: string) {} |
| 39 | } |
| 40 | |
| 41 | export class ServerError { |
| 42 | constructor( |
| 43 | public status: number, |
| 44 | public error: string, |
| 45 | ) {} |
| 46 | } |
| 47 |