feat: refactor audio token management and implement cover art retrieval
All checks were successful
Build and Push Docker Image / docker (push) Successful in 9s

This commit is contained in:
2025-09-04 22:52:52 +02:00
parent 10a992c048
commit d89647cd5e
6 changed files with 194 additions and 184 deletions

View File

@@ -0,0 +1,33 @@
import fs from 'fs';
import path from 'path';
import mime from 'mime';
import { DATA_DIR as RAW_DATA_DIR } from '../../config.js';
// Resolve DATA_DIR once, ensure absolute path and normalized with trailing separator for prefix checks
const DATA_DIR = path.resolve(RAW_DATA_DIR);
const DATA_DIR_WITH_SEP = DATA_DIR.endsWith(path.sep) ? DATA_DIR : DATA_DIR + path.sep;
export function resolveSafePath(name) {
if (!name || typeof name !== 'string') return null;
// Prevent path traversal and normalize input
const joined = path.join(DATA_DIR, name);
const resolved = path.resolve(joined);
if (resolved === DATA_DIR || resolved.startsWith(DATA_DIR_WITH_SEP)) return resolved;
return null;
}
export function fileExists(p) {
try {
return fs.existsSync(p);
} catch {
return false;
}
}
export function statFile(p) {
return fs.statSync(p);
}
export function getMimeType(p, fallback = 'audio/mpeg') {
return mime.getType(p) || fallback;
}