feat: refactor audio token management and implement cover art retrieval
All checks were successful
Build and Push Docker Image / docker (push) Successful in 9s
All checks were successful
Build and Push Docker Image / docker (push) Successful in 9s
This commit is contained in:
33
src/server/routes/audio/pathUtils.js
Normal file
33
src/server/routes/audio/pathUtils.js
Normal 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;
|
||||
}
|
||||
Reference in New Issue
Block a user