ajout du support des bdinfo au niveau du lien mediainfo
This commit is contained in:
parent
a27a46df23
commit
403e900ce6
@ -490,21 +490,43 @@ autopostRouter.get('/mediainfo', (req, res) => {
|
|||||||
if (!filename) {
|
if (!filename) {
|
||||||
return res.status(400).json({ error: "Nom du fichier non spécifié." });
|
return res.status(400).json({ error: "Nom du fichier non spécifié." });
|
||||||
}
|
}
|
||||||
let base = filename.includes('.') ? filename.split('.').slice(0, -1).join('.') : filename;
|
const base = filename.includes('.') ? filename.split('.').slice(0, -1).join('.') : filename;
|
||||||
const mediainfoFilePath = path.join(config.infodirectory, base + '.json');
|
const jsonPath = path.join(config.infodirectory, base + '.json');
|
||||||
fs.readFile(mediainfoFilePath, 'utf8', (err, data) => {
|
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) {
|
if (err) {
|
||||||
console.error(err.message);
|
console.error(err.message);
|
||||||
return res.status(500).json({ error: "Erreur lors du chargement du fichier mediainfo." });
|
return res.status(500).json({ error: "Erreur lors du chargement du fichier mediainfo." });
|
||||||
}
|
}
|
||||||
|
// Essaie de prettifier si JSON
|
||||||
try {
|
try {
|
||||||
const obj = JSON.parse(data);
|
const obj = JSON.parse(data);
|
||||||
const pretty = JSON.stringify(obj, null, 2);
|
const pretty = JSON.stringify(obj, null, 2);
|
||||||
res.json({ content: pretty });
|
res.json({ content: pretty });
|
||||||
} catch(e) {
|
} catch (e) {
|
||||||
res.json({ content: data });
|
res.json({ content: data });
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// --------------------------- Download -----------------------------
|
// --------------------------- Download -----------------------------
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user