Add new binary update mechanism
This commit is contained in:
52
index.js
52
index.js
@@ -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();
|
||||
|
||||
});
|
||||
Reference in New Issue
Block a user