1
0

ajout du support des bdinfo au niveau du lien mediainfo

This commit is contained in:
unfr 2025-08-07 16:13:22 +02:00
parent a27a46df23
commit 403e900ce6

View File

@ -490,13 +490,34 @@ autopostRouter.get('/mediainfo', (req, res) => {
if (!filename) {
return res.status(400).json({ error: "Nom du fichier non spécifié." });
}
let base = filename.includes('.') ? filename.split('.').slice(0, -1).join('.') : filename;
const mediainfoFilePath = path.join(config.infodirectory, base + '.json');
fs.readFile(mediainfoFilePath, 'utf8', (err, data) => {
const base = filename.includes('.') ? filename.split('.').slice(0, -1).join('.') : filename;
const jsonPath = path.join(config.infodirectory, base + '.json');
const bdinfoPath = path.join(config.infodirectory, base + '.bdinfo.txt');
// Vérifie lequel des deux existe, priorité au .json
fs.access(jsonPath, fs.constants.F_OK, (errJson) => {
if (!errJson) {
// .json existe
readAndSend(jsonPath);
} else {
// .json n'existe pas, on essaie .bdinfo.txt
fs.access(bdinfoPath, fs.constants.F_OK, (errBdinfo) => {
if (!errBdinfo) {
readAndSend(bdinfoPath);
} else {
res.status(404).json({ error: "Aucun fichier mediainfo trouvé." });
}
});
}
});
function readAndSend(filePath) {
fs.readFile(filePath, 'utf8', (err, data) => {
if (err) {
console.error(err.message);
return res.status(500).json({ error: "Erreur lors du chargement du fichier mediainfo." });
}
// Essaie de prettifier si JSON
try {
const obj = JSON.parse(data);
const pretty = JSON.stringify(obj, null, 2);
@ -505,6 +526,7 @@ autopostRouter.get('/mediainfo', (req, res) => {
res.json({ content: data });
}
});
}
});
// --------------------------- Download -----------------------------