Add new binary update mechanism
All checks were successful
ci / Image build (push) Successful in 50s
ci / Deployment (push) Successful in 11s

This commit is contained in:
Joris Bertomeu
2024-10-01 17:44:39 +02:00
parent b8ae4ca0f0
commit 4802f808cf
5 changed files with 330 additions and 5 deletions

View File

@@ -1,12 +1,13 @@
const express = require('express');
const Queue = require('bull');
const { exec, spawn } = require('child_process');
const fs = require('fs').promises;
const { spawn } = require('child_process');
const fs = require('fs');
const path = require('path');
const cors = require('cors');
const EventEmitter = require('events');
const softwareService = require('./services/softwares');
const BASE_PATH = `/data`;
const BASE_PATH = process.env.DATA_PATH || `./data`;
const OUTPUT_PATH = `${BASE_PATH}/output`;
const TMP_PATH = `${BASE_PATH}/tmp`;
@@ -134,6 +135,28 @@ app.get('/download/:filename', async (req, res) => {
res.download(file);
});
app.get('/hello', async (req, res, next) => {
try {
res.json({
downloader: await softwareService.checkDownloaderUpdate(),
mp4decrypt: await softwareService.checkMp4decryptUpdate()
})
} catch(e) {
console.log(e);
next(e);
}
});
app.post('/processUpdate', async (req, res, next) => {
try {
console.log(req.body);
await softwareService.processUpdate(req.body);
res.end();
} catch(e) {
console.log(e);
next(e);
}
});
const checkFilesExistance = (pattern) => {
return new Promise(async (resolve, reject) => {
@@ -235,7 +258,7 @@ videoQueue.process((job) => {
let counter = 1;
for (const file of audioFiles) {
if (file.startsWith(`${mp4TmpFilepath}_encrypted`) && file.endsWith('.srt')) {
await fs.rename(file, `${mp4FinalFilepath}_${counter}.srt`);
fs.renameSync(file, `${mp4FinalFilepath}_${counter}.srt`);
counter++;
}
}
@@ -254,4 +277,25 @@ videoQueue.process((job) => {
app.listen(port, () => {
console.log(`Server running at http://localhost:${port}`);
const dirsToCheck = [{
path: BASE_PATH,
name: 'data'
}, {
path: OUTPUT_PATH,
name: 'output'
}, {
path: TMP_PATH,
name: 'tmp'
}];
for (let i = 0; i < dirsToCheck.length; i++) {
const dir = dirsToCheck[i];
if (!fs.existsSync(dir.path)) {
console.log(`Creating ${dir.name} directory...`);
fs.mkdirSync(dir.path);
}
}
softwareService.init();
});