Add Copy to Working Directory

This commit is contained in:
HaveAGitGat 2023-08-28 11:16:44 +01:00
parent ca8ec26b81
commit 312c98801e
4 changed files with 178 additions and 38 deletions

View file

@ -42,19 +42,6 @@ const details = (): IpluginDetails => ({
},
tooltip: 'Specify whether to keep the relative path',
},
{
name: 'copyToWorkDir',
type: 'boolean',
defaultValue: 'false',
inputUI: {
type: 'text',
options: [
'false',
'true',
],
},
tooltip: 'Specify whether to copy to the working directory',
},
{
name: 'makeWorkingFile',
type: 'boolean',
@ -84,7 +71,7 @@ const plugin = async (args: IpluginInputArgs): Promise<IpluginOutputArgs> => {
args.inputs = lib.loadDefaultValues(args.inputs, details);
const {
copyToWorkDir, keepRelativePath, makeWorkingFile,
keepRelativePath, makeWorkingFile,
} = args.inputs;
const outputDirectory = String(args.inputs.outputDirectory);
@ -94,9 +81,7 @@ const plugin = async (args: IpluginInputArgs): Promise<IpluginOutputArgs> => {
let outputPath = '';
if (copyToWorkDir) {
outputPath = args.workDir;
} else if (keepRelativePath) {
if (keepRelativePath) {
const subStem = getSubStem({
inputPathStem: args.librarySettings.folder,
inputPath: args.originalLibraryFile._id,
@ -123,7 +108,7 @@ const plugin = async (args: IpluginInputArgs): Promise<IpluginOutputArgs> => {
let workingFile = args.inputFileObj._id;
if (makeWorkingFile || copyToWorkDir) {
if (makeWorkingFile) {
workingFile = ouputFilePath;
}

View file

@ -0,0 +1,69 @@
import { promises as fs } from 'fs';
import { getContainer, getFileName } from '../../../../FlowHelpers/1.0.0/fileUtils';
import {
IpluginDetails,
IpluginInputArgs,
IpluginOutputArgs,
} from '../../../../FlowHelpers/1.0.0/interfaces/interfaces';
import normJoinPath from '../../../../FlowHelpers/1.0.0/normJoinPath';
/* eslint no-plusplus: ["error", { "allowForLoopAfterthoughts": true }] */
const details = (): IpluginDetails => ({
name: 'Copy to Working Directory',
description: 'Copy the working file to the working directory of the Tdarr worker. '
+ 'Useful if you want to copy the file to the library cache before transcoding begins',
style: {
borderColor: 'green',
},
tags: '',
isStartPlugin: false,
sidebarPosition: -1,
icon: 'faArrowRight',
inputs: [],
outputs: [
{
number: 1,
tooltip: 'Continue to next plugin',
},
],
});
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const plugin = async (args: IpluginInputArgs): Promise<IpluginOutputArgs> => {
const lib = require('../../../../../methods/lib')();
// eslint-disable-next-line @typescript-eslint/no-unused-vars,no-param-reassign
args.inputs = lib.loadDefaultValues(args.inputs, details);
const originalFileName = getFileName(args.originalLibraryFile._id);
const newContainer = getContainer(args.inputFileObj._id);
const outputPath = args.workDir;
const ouputFilePath = normJoinPath({
upath: args.deps.upath,
paths: [
outputPath,
`${originalFileName}.${newContainer}`,
],
});
args.jobLog(`Input path: ${args.inputFileObj._id}`);
args.jobLog(`Output path: ${outputPath}`);
args.deps.fsextra.ensureDirSync(outputPath);
await fs.copyFile(args.inputFileObj._id, ouputFilePath);
return {
outputFileObj: {
_id: ouputFilePath,
},
outputNumber: 1,
variables: args.variables,
};
};
export {
details,
plugin,
};