Fix #498 : ffmpeg settings can't be updated after ffmpeg path changes.
This commit is contained in:
parent
4df39ed177
commit
17711fcb76
@ -1,7 +1,5 @@
|
|||||||
const databaseMigration = require('../database-migration');
|
const databaseMigration = require('../database-migration');
|
||||||
const DAY_MS = 1000 * 60 * 60 * 24;
|
const DAY_MS = 1000 * 60 * 60 * 24;
|
||||||
const path = require('path');
|
|
||||||
const fs = require('fs');
|
|
||||||
|
|
||||||
class FfmpegSettingsService {
|
class FfmpegSettingsService {
|
||||||
constructor(db) {
|
constructor(db) {
|
||||||
@ -10,9 +8,6 @@ class FfmpegSettingsService {
|
|||||||
|
|
||||||
get() {
|
get() {
|
||||||
let ffmpeg = this.getCurrentState();
|
let ffmpeg = this.getCurrentState();
|
||||||
if (isLocked(ffmpeg)) {
|
|
||||||
ffmpeg.lock = true;
|
|
||||||
}
|
|
||||||
// Hid this info from the API
|
// Hid this info from the API
|
||||||
delete ffmpeg.ffmpegPathLockDate;
|
delete ffmpeg.ffmpegPathLockDate;
|
||||||
return ffmpeg;
|
return ffmpeg;
|
||||||
@ -21,20 +16,7 @@ class FfmpegSettingsService {
|
|||||||
|
|
||||||
update(attempt) {
|
update(attempt) {
|
||||||
let ffmpeg = this.getCurrentState();
|
let ffmpeg = this.getCurrentState();
|
||||||
attempt.ffmpegPathLockDate = ffmpeg.ffmpegPathLockDate;
|
delete attempt.ffmpegPathLockDate;
|
||||||
if (isLocked(ffmpeg)) {
|
|
||||||
console.log("Note: ffmpeg path is not being updated since it's been locked for your security.");
|
|
||||||
attempt.ffmpegPath = ffmpeg.ffmpegPath;
|
|
||||||
if (typeof(ffmpeg.ffmpegPathLockDate) === 'undefined') {
|
|
||||||
// make sure to lock it even if it was undefined
|
|
||||||
attempt.ffmpegPathLockDate = new Date().getTime() - DAY_MS;
|
|
||||||
}
|
|
||||||
} else if (attempt.addLock === true) {
|
|
||||||
// lock it right now
|
|
||||||
attempt.ffmpegPathLockDate = new Date().getTime() - DAY_MS;
|
|
||||||
} else {
|
|
||||||
attempt.ffmpegPathLockDate = new Date().getTime() + DAY_MS;
|
|
||||||
}
|
|
||||||
delete attempt.addLock;
|
delete attempt.addLock;
|
||||||
delete attempt.lock;
|
delete attempt.lock;
|
||||||
|
|
||||||
@ -65,13 +47,7 @@ class FfmpegSettingsService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function fixupFFMPEGSettings(ffmpeg) {
|
function fixupFFMPEGSettings(ffmpeg) {
|
||||||
if (typeof(ffmpeg.ffmpegPath) !== 'string') {
|
|
||||||
return "ffmpeg path is required."
|
|
||||||
}
|
|
||||||
if (! isValidFilePath(ffmpeg.ffmpegPath)) {
|
|
||||||
return "ffmpeg path must be a valid file path."
|
|
||||||
}
|
|
||||||
|
|
||||||
if (typeof(ffmpeg.maxFPS) === 'undefined') {
|
if (typeof(ffmpeg.maxFPS) === 'undefined') {
|
||||||
ffmpeg.maxFPS = 60;
|
ffmpeg.maxFPS = 60;
|
||||||
return null;
|
return null;
|
||||||
@ -80,32 +56,6 @@ function fixupFFMPEGSettings(ffmpeg) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//These checks are good but might not be enough, as long as we are letting the
|
|
||||||
//user choose any path and we are making dizqueTV execute, it is too risky,
|
|
||||||
//hence why we are also adding the lock feature on top of these checks.
|
|
||||||
function isValidFilePath(filePath) {
|
|
||||||
const normalizedPath = path.normalize(filePath);
|
|
||||||
|
|
||||||
if (!path.isAbsolute(normalizedPath)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
const stats = fs.statSync(normalizedPath);
|
|
||||||
return stats.isFile();
|
|
||||||
} catch (err) {
|
|
||||||
// Handle potential errors (e.g., file not found, permission issues)
|
|
||||||
if (err.code === 'ENOENT') {
|
|
||||||
return false; // File does not exist
|
|
||||||
} else {
|
|
||||||
throw err; // Re-throw other errors for debugging
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function isLocked(ffmpeg) {
|
|
||||||
return isNaN(ffmpeg.ffmpegPathLockDate) || ffmpeg.ffmpegPathLockDate < new Date().getTime();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user