89 lines
3.1 KiB
JavaScript
89 lines
3.1 KiB
JavaScript
'use strict';
|
|
|
|
const path = require('path');
|
|
const fs = require('fs');
|
|
const { copyWithProgress } = require('../../../../FlowHelpers/1.0.0/copyWithProgress');
|
|
|
|
const details = () => ({
|
|
name: 'Copy Source to Work Dir (Progress)',
|
|
description:
|
|
'Copies the source file into the worker local workDir using a streamed, verified copy '
|
|
+ 'with progress updates. Use before transcode plugins for files on network shares.',
|
|
style: { borderColor: '#607D8B' },
|
|
tags: 'utility,copy,progress',
|
|
isStartPlugin: false,
|
|
pType: '',
|
|
requiresVersion: '2.11.01',
|
|
sidebarPosition: 0,
|
|
icon: 'faCopy',
|
|
inputs: [
|
|
{
|
|
label: 'Skip if already local',
|
|
name: 'skipIfLocal',
|
|
type: 'boolean',
|
|
defaultValue: 'true',
|
|
inputUI: { type: 'dropdown', options: ['true', 'false'] },
|
|
tooltip: 'Skip when the source is already inside workDir.',
|
|
},
|
|
{
|
|
label: 'Copy method',
|
|
name: 'copyMethod',
|
|
type: 'string',
|
|
defaultValue: 'auto',
|
|
inputUI: { type: 'dropdown', options: ['auto', 'native', 'stream'] },
|
|
tooltip: 'Auto uses the operating system copy API; stream is a fallback for problematic mounts.',
|
|
},
|
|
{
|
|
label: 'Stream buffer size (MB)',
|
|
name: 'bufferSizeMb',
|
|
type: 'string',
|
|
defaultValue: '16',
|
|
inputUI: { type: 'dropdown', options: ['4', '16', '64'] },
|
|
tooltip: 'Used only with stream copy; larger values can improve high-latency SMB mounts.',
|
|
},
|
|
],
|
|
outputs: [{ number: 1, tooltip: 'File is ready in workDir — continue to next plugin' }],
|
|
});
|
|
|
|
const plugin = async (args) => {
|
|
const { jobLog, inputFileObj, variables, workDir } = args;
|
|
const inputFile = inputFileObj._id;
|
|
const ext = path.extname(inputFile);
|
|
const baseName = path.basename(inputFile, ext);
|
|
const localCopy = path.join(workDir, `${baseName}_old${ext}`);
|
|
const skipIfLocal = (args.inputs.skipIfLocal || 'true') === 'true';
|
|
|
|
const relativeInput = path.relative(path.resolve(workDir), path.resolve(inputFile));
|
|
if (skipIfLocal && relativeInput !== '..' && !relativeInput.startsWith(`..${path.sep}`)
|
|
&& !path.isAbsolute(relativeInput)) {
|
|
jobLog('[copyToWorkDir] Source file is already inside workDir — skipping copy.\n');
|
|
return { outputNumber: 1, outputFileObj: inputFileObj, variables };
|
|
}
|
|
if (!fs.existsSync(inputFile)) throw new Error(`[copyToWorkDir] Source file not found: ${inputFile}`);
|
|
|
|
variables.originalLibraryFile = variables.originalLibraryFile || inputFile;
|
|
variables.originalLibraryDir = variables.originalLibraryDir || path.dirname(inputFile);
|
|
variables.workDirSourceBaseName = baseName;
|
|
variables.workDirCopyApplied = 'true';
|
|
|
|
jobLog(`[copyToWorkDir] Copying ${inputFile} to ${localCopy}\n`);
|
|
await copyWithProgress({
|
|
source: inputFile,
|
|
destination: localCopy,
|
|
jobLog,
|
|
updateProgress: args.updateProgress,
|
|
label: 'copyToWorkDir',
|
|
copyMethod: args.inputs.copyMethod || 'auto',
|
|
bufferSizeMb: args.inputs.bufferSizeMb || '16',
|
|
});
|
|
|
|
return {
|
|
outputNumber: 1,
|
|
outputFileObj: { ...inputFileObj, _id: localCopy },
|
|
variables,
|
|
};
|
|
};
|
|
|
|
module.exports.details = details;
|
|
module.exports.plugin = plugin;
|