diff --git a/FlowPluginsTs/CommunityFlowPlugins/file/deleteFile/1.0.0/index.ts b/FlowPluginsTs/CommunityFlowPlugins/file/deleteFile/1.0.0/index.ts index e403d9c..98338a0 100644 --- a/FlowPluginsTs/CommunityFlowPlugins/file/deleteFile/1.0.0/index.ts +++ b/FlowPluginsTs/CommunityFlowPlugins/file/deleteFile/1.0.0/index.ts @@ -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 => { 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);