diff --git a/Dockerfile b/Dockerfile index 5d4bd61..47eea8c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -64,6 +64,7 @@ RUN npm config set strict-ssl false && \ npm install pm2 -g && \ npm install && chown -R $UID:$GID ./ +# needed for ubuntu, see #596 RUN ln -s /usr/bin/python3 /usr/bin/python COPY --chown=$UID:$GID --from=frontend [ "/build/backend/public/", "/app/public/" ] diff --git a/backend/app.js b/backend/app.js index 2ec7f98..af6089a 100644 --- a/backend/app.js +++ b/backend/app.js @@ -249,14 +249,6 @@ async function startServer() { }); } -async function restartServer(is_update = false) { - logger.info(`${is_update ? 'Update complete! ' : ''}Restarting server...`); - - // the following line restarts the server through nodemon - fs.writeFileSync(`restart${is_update ? '_update' : '_general'}.json`, 'internal use only'); - process.exit(1); -} - async function updateServer(tag) { // no tag provided means update to the latest version if (!tag) { @@ -297,7 +289,7 @@ async function updateServer(tag) { updating: true, 'details': 'Update complete! Restarting server...' } - restartServer(true); + utils.restartServer(true); }, err => { logger.error(err); updaterStatus = { @@ -676,6 +668,7 @@ async function getUrlInfos(url) { async function startYoutubeDL() { // auto update youtube-dl + youtubedl_api.verifyBinaryExistsLinux(); const update_available = await youtubedl_api.checkForYoutubeDLUpdate(); if (update_available) await youtubedl_api.updateYoutubeDL(update_available); } @@ -764,7 +757,7 @@ app.get('/api/versionInfo', (req, res) => { app.post('/api/restartServer', optionalJwt, (req, res) => { // delayed by a little bit so that the client gets a response - setTimeout(() => {restartServer()}, 100); + setTimeout(() => {utils.restartServer()}, 100); res.send({success: true}); }); @@ -1802,6 +1795,7 @@ app.post('/api/updateTaskData', optionalJwt, async (req, res) => { app.post('/api/getDBBackups', optionalJwt, async (req, res) => { const backup_dir = path.join('appdata', 'db_backup'); + fs.ensureDirSync(backup_dir); const db_backups = []; const candidate_backups = await utils.recFindByExt(backup_dir, 'bak', null, [], false); diff --git a/backend/utils.js b/backend/utils.js index a6eaf7e..4aeb4a9 100644 --- a/backend/utils.js +++ b/backend/utils.js @@ -415,6 +415,14 @@ async function fetchFile(url, path, file_label) { }); } +async function restartServer(is_update = false) { + logger.info(`${is_update ? 'Update complete! ' : ''}Restarting server...`); + + // the following line restarts the server through nodemon + fs.writeFileSync(`restart${is_update ? '_update' : '_general'}.json`, 'internal use only'); + process.exit(1); +} + // objects function File(id, title, thumbnailURL, isAudio, duration, url, uploader, size, path, upload_date, description, view_count, height, abr) { @@ -458,5 +466,6 @@ module.exports = { wait: wait, checkExistsWithTimeout: checkExistsWithTimeout, fetchFile: fetchFile, + restartServer: restartServer, File: File } diff --git a/backend/youtube-dl.js b/backend/youtube-dl.js index 80432fb..a94e566 100644 --- a/backend/youtube-dl.js +++ b/backend/youtube-dl.js @@ -6,6 +6,8 @@ const utils = require('./utils'); const CONSTS = require('./consts'); const config_api = require('./config.js'); +const OUTDATED_VERSION = "2020.00.00"; + const is_windows = process.platform === 'win32'; const download_sources = { @@ -31,7 +33,7 @@ exports.checkForYoutubeDLUpdate = async () => { let current_app_details_exists = fs.existsSync(CONSTS.DETAILS_BIN_PATH); if (!current_app_details_exists) { logger.warn(`Failed to get youtube-dl binary details at location '${CONSTS.DETAILS_BIN_PATH}'. Generating file...`); - fs.writeJSONSync(CONSTS.DETAILS_BIN_PATH, {"version":"2020.00.00", "downloader": default_downloader}); + fs.writeJSONSync(CONSTS.DETAILS_BIN_PATH, {"version": OUTDATED_VERSION, "downloader": default_downloader}); } let current_app_details = JSON.parse(fs.readFileSync(CONSTS.DETAILS_BIN_PATH)); let current_version = current_app_details['version']; @@ -86,6 +88,18 @@ exports.updateYoutubeDL = async (latest_update_version) => { await download_sources[default_downloader]['func'](latest_update_version); } +exports.verifyBinaryExistsLinux = () => { + const details_json = fs.readJSONSync(CONSTS.DETAILS_BIN_PATH); + if (!is_windows && details_json && details_json['path'].includes('.exe')) { + details_json['path'] = 'node_modules/youtube-dl/bin/youtube-dl'; + details_json['exec'] = 'youtube-dl'; + details_json['version'] = OUTDATED_VERSION; + fs.writeJSONSync(CONSTS.DETAILS_BIN_PATH, details_json); + + utils.restartServer(); + } +} + async function downloadLatestYoutubeDLBinary(new_version) { const file_ext = is_windows ? '.exe' : '';