From de5a5771903c847055a73d3d9d2da9991d454432 Mon Sep 17 00:00:00 2001 From: Joris Bertomeu Date: Tue, 1 Oct 2024 18:03:22 +0200 Subject: [PATCH] Some fixes relative to job launch --- index.js | 24 ++++++++++++------------ services/softwares.js | 1 + 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/index.js b/index.js index 56abdcd..36f554d 100644 --- a/index.js +++ b/index.js @@ -158,10 +158,10 @@ app.post('/processUpdate', async (req, res, next) => { } }); -const checkFilesExistance = (pattern) => { +const checkFilesExistance = (pattern, path) => { return new Promise(async (resolve, reject) => { try { - const files = await fs.readdir(process.cwd()); + const files = fs.readdirSync(path); resolve(files.filter(file => file.includes(pattern))); } catch(e) { reject(e); @@ -186,15 +186,15 @@ const extractPercentage = (line) => { // Processus de la file d'attente videoQueue.process((job) => { return new Promise(async (resolve, reject) => { - const { mp4Filename, mpdUrl, keys, wantedResolution } = job.data; - const downloaderPath = path.join(process.env.HOME, 'Downloads/N_m3u8DL-RE_Beta_osx-arm64/N_m3u8DL-RE'); - const mp4decryptPath = path.join(process.env.HOME, 'Downloads/Bento4-SDK-1-6-0-641.universal-apple-macosx/bin/mp4decrypt'); - const mp4TmpFilepath = path.join(TMP_PATH, `${mp4Filename}.mp4`); - const mp4FinalFilepath = path.join(OUTPUT_PATH, `${mp4Filename}.mp4`); - try { - const filesExist = await checkFilesExistance('encrypted'); - + const { mp4Filename, mpdUrl, keys, wantedResolution } = job.data; + const downloaderPath = softwareService.getLocalBinFileInfo('downloader').path; + const mp4decryptPath = softwareService.getLocalBinFileInfo('mp4decrypt').path; + const mp4TmpFilepath = path.join(TMP_PATH, `${mp4Filename}.mp4`); + const mp4FinalFilepath = path.join(OUTPUT_PATH, `${mp4Filename}.mp4`); + console.log('1') + const filesExist = await checkFilesExistance('encrypted', TMP_PATH); + console.log('2') if (filesExist.length === 0) { const resPattern = { '4k': [3840, 2160], @@ -224,7 +224,7 @@ videoQueue.process((job) => { job.progress(50); // Décryptage audio - const audioFiles = await fs.readdir('.'); + const audioFiles = fs.readdirSync(mp4TmpFilepath); const finalAudio = []; for (const file of audioFiles) { if (file.startsWith(`${mp4TmpFilepath}_encrypted`) && file.endsWith('.m4a')) { @@ -264,7 +264,7 @@ videoQueue.process((job) => { } // Nettoyage (commenté pour correspondre au script original) - await runCommand(`rm ${mp4TmpFilepath}_encrypted* && rm ${mp4TmpFilepath}_decrypted*`); + await runCommand(`rm ${mp4TmpFilepath}_encrypted* && rm ${mp4TmpFilepath}_decrypted*`); job.progress(100); resolve({ message: `File fetched and decrypted with success: ${mp4Filename}.mp4`, filePath: `${mp4FinalFilepath}.mp4`, fileName: `${mp4Filename}.mp4` }); diff --git a/services/softwares.js b/services/softwares.js index cc8c8f2..58c408f 100644 --- a/services/softwares.js +++ b/services/softwares.js @@ -207,6 +207,7 @@ const processUpdate = async (data) => { fs.renameSync(`${unzippedFolderDest}/${uncompressedFoldersS[0]}/${uncompressedFolders[0]}`, data.details.localInfos.path); else if (data.binType === 'mp4decrypt') fs.renameSync(`${unzippedFolderDest}/${uncompressedFoldersS[0]}/bin/mp4decrypt`, data.details.localInfos.path); + fs.chmodSync(data.details.localInfos.path, 0o755); writeBinVersion(`${BIN_PATH}/.${data.binType}.version`, data.details.remoteInfos[data.binType === 'downloader' ? 'id' : 'version']) } catch(e) { throw e;