mirror of
https://github.com/gabehf/Tdarr_Plugins.git
synced 2026-03-14 01:36:08 -07:00
Add new copy/move options
This commit is contained in:
parent
f410caf1ad
commit
ca8ec26b81
9 changed files with 326 additions and 33 deletions
|
|
@ -1,10 +1,11 @@
|
|||
import { promises as fs } from 'fs';
|
||||
import { getContainer, getFileName } from '../../../../FlowHelpers/1.0.0/fileUtils';
|
||||
import { getContainer, getFileName, getSubStem } 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 => ({
|
||||
|
|
@ -24,16 +25,42 @@ const details = (): IpluginDetails => ({
|
|||
type: 'string',
|
||||
defaultValue: '',
|
||||
inputUI: {
|
||||
type: 'text',
|
||||
type: 'directory',
|
||||
},
|
||||
tooltip: 'Specify ouput directory',
|
||||
},
|
||||
{
|
||||
name: 'keepRelativePath',
|
||||
type: 'boolean',
|
||||
defaultValue: 'false',
|
||||
inputUI: {
|
||||
type: 'text',
|
||||
options: [
|
||||
'false',
|
||||
'true',
|
||||
],
|
||||
},
|
||||
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',
|
||||
defaultValue: 'false',
|
||||
inputUI: {
|
||||
type: 'text',
|
||||
type: 'dropdown',
|
||||
options: [
|
||||
'false',
|
||||
'true',
|
||||
|
|
@ -56,19 +83,57 @@ const plugin = async (args: IpluginInputArgs): Promise<IpluginOutputArgs> => {
|
|||
// eslint-disable-next-line @typescript-eslint/no-unused-vars,no-param-reassign
|
||||
args.inputs = lib.loadDefaultValues(args.inputs, details);
|
||||
|
||||
const {
|
||||
copyToWorkDir, keepRelativePath, makeWorkingFile,
|
||||
} = args.inputs;
|
||||
|
||||
const outputDirectory = String(args.inputs.outputDirectory);
|
||||
|
||||
const originalFileName = getFileName(args.originalLibraryFile._id);
|
||||
const newContainer = getContainer(args.inputFileObj._id);
|
||||
|
||||
const outputPath = `${args.inputs.outputDirectory}/${originalFileName}.${newContainer}`;
|
||||
let outputPath = '';
|
||||
|
||||
await fs.copyFile(args.inputFileObj._id, outputPath);
|
||||
if (copyToWorkDir) {
|
||||
outputPath = args.workDir;
|
||||
} else if (keepRelativePath) {
|
||||
const subStem = getSubStem({
|
||||
inputPathStem: args.librarySettings.folder,
|
||||
inputPath: args.originalLibraryFile._id,
|
||||
});
|
||||
|
||||
outputPath = normJoinPath({
|
||||
upath: args.deps.upath,
|
||||
paths: [
|
||||
outputDirectory,
|
||||
subStem,
|
||||
],
|
||||
});
|
||||
} else {
|
||||
outputPath = outputDirectory;
|
||||
}
|
||||
|
||||
const ouputFilePath = normJoinPath({
|
||||
upath: args.deps.upath,
|
||||
paths: [
|
||||
outputPath,
|
||||
`${originalFileName}.${newContainer}`,
|
||||
],
|
||||
});
|
||||
|
||||
let workingFile = args.inputFileObj._id;
|
||||
|
||||
if (args.inputs.makeWorkingFile) {
|
||||
workingFile = outputPath;
|
||||
if (makeWorkingFile || copyToWorkDir) {
|
||||
workingFile = ouputFilePath;
|
||||
}
|
||||
|
||||
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: workingFile,
|
||||
|
|
|
|||
|
|
@ -1,10 +1,11 @@
|
|||
import { promises as fs } from 'fs';
|
||||
import { getContainer, getFileName } from '../../../../FlowHelpers/1.0.0/fileUtils';
|
||||
import { getContainer, getFileName, getSubStem } 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 => ({
|
||||
|
|
@ -24,10 +25,23 @@ const details = ():IpluginDetails => ({
|
|||
type: 'string',
|
||||
defaultValue: '',
|
||||
inputUI: {
|
||||
type: 'text',
|
||||
type: 'directory',
|
||||
},
|
||||
tooltip: 'Specify ouput directory',
|
||||
},
|
||||
{
|
||||
name: 'keepRelativePath',
|
||||
type: 'boolean',
|
||||
defaultValue: 'false',
|
||||
inputUI: {
|
||||
type: 'text',
|
||||
options: [
|
||||
'false',
|
||||
'true',
|
||||
],
|
||||
},
|
||||
tooltip: 'Specify whether to keep the relative path',
|
||||
},
|
||||
],
|
||||
outputs: [
|
||||
{
|
||||
|
|
@ -43,16 +57,51 @@ const plugin = async (args:IpluginInputArgs):Promise<IpluginOutputArgs> => {
|
|||
// eslint-disable-next-line @typescript-eslint/no-unused-vars,no-param-reassign
|
||||
args.inputs = lib.loadDefaultValues(args.inputs, details);
|
||||
|
||||
const {
|
||||
keepRelativePath,
|
||||
} = args.inputs;
|
||||
|
||||
const outputDirectory = String(args.inputs.outputDirectory);
|
||||
|
||||
const originalFileName = getFileName(args.originalLibraryFile._id);
|
||||
const newContainer = getContainer(args.inputFileObj._id);
|
||||
|
||||
const outputPath = `${args.inputs.outputDirectory}/${originalFileName}.${newContainer}`;
|
||||
let outputPath = '';
|
||||
|
||||
await fs.rename(args.inputFileObj._id, outputPath);
|
||||
if (keepRelativePath) {
|
||||
const subStem = getSubStem({
|
||||
inputPathStem: args.librarySettings.folder,
|
||||
inputPath: args.originalLibraryFile._id,
|
||||
});
|
||||
|
||||
outputPath = normJoinPath({
|
||||
upath: args.deps.upath,
|
||||
paths: [
|
||||
outputDirectory,
|
||||
subStem,
|
||||
],
|
||||
});
|
||||
} else {
|
||||
outputPath = outputDirectory;
|
||||
}
|
||||
|
||||
const ouputFilePath = normJoinPath({
|
||||
upath: args.deps.upath,
|
||||
paths: [
|
||||
outputPath,
|
||||
`${originalFileName}.${newContainer}`,
|
||||
],
|
||||
});
|
||||
|
||||
args.jobLog(`Input path: ${args.inputFileObj._id}`);
|
||||
args.jobLog(`Output path: ${ouputFilePath}`);
|
||||
|
||||
args.deps.fsextra.ensureDirSync(outputPath);
|
||||
await fs.rename(args.inputFileObj._id, ouputFilePath);
|
||||
|
||||
return {
|
||||
outputFileObj: {
|
||||
_id: outputPath,
|
||||
_id: ouputFilePath,
|
||||
},
|
||||
outputNumber: 1,
|
||||
variables: args.variables,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue