48 lines
1.3 KiB
JavaScript
48 lines
1.3 KiB
JavaScript
'use strict';
|
|
/**
|
|
* Local mock of Tdarr FlowHelpers/1.0.0/cliUtils.js
|
|
* Used only for local testing — on real Tdarr this file comes from the server.
|
|
*
|
|
* Matches the real Tdarr CLI constructor signature:
|
|
* new CLI({ cli, spawnArgs, WorkDir, jobLog, inputFileObj })
|
|
* inputFileObj is accepted but unused here (only used by real Tdarr for progress tracking).
|
|
*/
|
|
const { spawn } = require('child_process');
|
|
|
|
class CLI {
|
|
constructor(config) {
|
|
this.config = config;
|
|
}
|
|
|
|
runCli() {
|
|
return new Promise((resolve) => {
|
|
const { cli, spawnArgs, WorkDir, jobLog } = this.config;
|
|
|
|
if (jobLog) jobLog(`[CLI] Running: ${cli} ${spawnArgs.join(' ')}\n`);
|
|
|
|
const proc = spawn(cli, spawnArgs, {
|
|
cwd: WorkDir || process.cwd(),
|
|
stdio: ['ignore', 'pipe', 'pipe'],
|
|
shell: false,
|
|
});
|
|
|
|
proc.stdout.on('data', (d) => { if (jobLog) jobLog(d.toString()); });
|
|
proc.stderr.on('data', (d) => { if (jobLog) jobLog(d.toString()); });
|
|
|
|
proc.on('close', (code) => {
|
|
resolve({ cliExitCode: code || 0 });
|
|
});
|
|
|
|
proc.on('error', (err) => {
|
|
if (jobLog) jobLog(`[CLI] Error: ${err.message}\n`);
|
|
resolve({ cliExitCode: 1 });
|
|
});
|
|
});
|
|
}
|
|
}
|
|
|
|
const getFFmpegVar = () => {};
|
|
|
|
module.exports = { CLI, getFFmpegVar };
|
|
|