39 lines
1.0 KiB
JavaScript
39 lines
1.0 KiB
JavaScript
import { exec } from "child_process";
|
|
import { promisify } from "util";
|
|
|
|
const execAsync = promisify(exec);
|
|
|
|
async function checkBinary(binary) {
|
|
try {
|
|
const { stdout } = await execAsync(`which ${binary}`);
|
|
const location = stdout.trim();
|
|
return { name: binary, ok: Boolean(location), location: location || null };
|
|
} catch (err) {
|
|
return { name: binary, ok: false, error: err.message };
|
|
}
|
|
}
|
|
|
|
export async function buildHealthReport({ ffmpegPath = "ffmpeg", ffprobePath = "ffprobe", tmdbKey, tvdbKey, fanartKey }) {
|
|
const binaries = await Promise.all([
|
|
checkBinary(ffmpegPath),
|
|
checkBinary(ffprobePath)
|
|
]);
|
|
|
|
return {
|
|
binaries,
|
|
apis: {
|
|
tmdb: { configured: Boolean(tmdbKey) },
|
|
tvdb: { configured: Boolean(tvdbKey) },
|
|
fanart: { configured: Boolean(fanartKey) }
|
|
},
|
|
timestamp: new Date().toISOString()
|
|
};
|
|
}
|
|
|
|
export function healthRouter(getReport) {
|
|
return (req, res) => {
|
|
const report = typeof getReport === "function" ? getReport() : null;
|
|
res.json(report || { status: "unknown" });
|
|
};
|
|
}
|