mirror of
https://github.com/gabehf/Tdarr_Plugins.git
synced 2026-03-08 23:18:16 -07:00
Add deleteWorkingFileIfOriginal toggle
This commit is contained in:
parent
0bdfa5551d
commit
88ae273f5f
1 changed files with 47 additions and 3 deletions
|
|
@ -35,6 +35,32 @@ const details = (): IpluginDetails => ({
|
|||
},
|
||||
tooltip: 'Specify the file to delete',
|
||||
},
|
||||
{
|
||||
label: 'Delete Working File If It\'s The Original File',
|
||||
name: 'deleteWorkingFileIfOriginal',
|
||||
type: 'boolean',
|
||||
defaultValue: 'true',
|
||||
inputUI: {
|
||||
type: 'switch',
|
||||
displayConditions: {
|
||||
logic: 'AND',
|
||||
sets: [
|
||||
{
|
||||
logic: 'AND',
|
||||
inputs: [
|
||||
{
|
||||
name: 'fileToDelete',
|
||||
value: 'workingFile',
|
||||
condition: '===',
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
tooltip: 'If the option above is set to delete the working file,'
|
||||
+ ' and the working file is the original file, delete the file.',
|
||||
},
|
||||
{
|
||||
label: 'Delete Parent Folder If Empty',
|
||||
name: 'deleteParentFolderIfEmpty',
|
||||
|
|
@ -61,11 +87,29 @@ const plugin = async (args: IpluginInputArgs): Promise<IpluginOutputArgs> => {
|
|||
args.inputs = lib.loadDefaultValues(args.inputs, details);
|
||||
|
||||
const fileToDelete = String(args.inputs.fileToDelete);
|
||||
const { deleteParentFolderIfEmpty } = args.inputs;
|
||||
const {
|
||||
deleteParentFolderIfEmpty,
|
||||
deleteWorkingFileIfOriginal,
|
||||
} = args.inputs;
|
||||
|
||||
if (fileToDelete === 'workingFile') {
|
||||
args.jobLog(`Deleting working file ${args.inputFileObj._id}`);
|
||||
await fsp.unlink(args.inputFileObj._id);
|
||||
const workingFileIsOriginal = args.originalLibraryFile._id === args.inputFileObj._id;
|
||||
|
||||
if (workingFileIsOriginal) {
|
||||
args.jobLog('Working file is the original file!');
|
||||
} else {
|
||||
args.jobLog('Working file is not the original file!');
|
||||
}
|
||||
|
||||
if (
|
||||
(workingFileIsOriginal && deleteWorkingFileIfOriginal)
|
||||
|| !workingFileIsOriginal
|
||||
) {
|
||||
args.jobLog(`Deleting working file ${args.inputFileObj._id}`);
|
||||
await fsp.unlink(args.inputFileObj._id);
|
||||
} else {
|
||||
args.jobLog('Skipping delete of working file because it is the original file');
|
||||
}
|
||||
} else if (fileToDelete === 'originalFile') {
|
||||
args.jobLog(`Deleting original file ${args.originalLibraryFile._id}`);
|
||||
await fsp.unlink(args.originalLibraryFile._id);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue