From 741e39f588d199edbb3522068e49d213a091f55e Mon Sep 17 00:00:00 2001 From: "jeanchristophe.mqt@gmail.com" Date: Wed, 20 Mar 2024 17:37:41 +0100 Subject: [PATCH] Removed the possibility for regex patterns to be a list. All patterns must be merged --- .../file/checkFileNameIncludes/2.0.0/index.js | 15 ++++++++------- .../file/checkFileNameIncludes/2.0.0/index.ts | 15 ++++++++------- 2 files changed, 16 insertions(+), 14 deletions(-) diff --git a/FlowPlugins/CommunityFlowPlugins/file/checkFileNameIncludes/2.0.0/index.js b/FlowPlugins/CommunityFlowPlugins/file/checkFileNameIncludes/2.0.0/index.js index f206a2b..eb86c17 100644 --- a/FlowPlugins/CommunityFlowPlugins/file/checkFileNameIncludes/2.0.0/index.js +++ b/FlowPlugins/CommunityFlowPlugins/file/checkFileNameIncludes/2.0.0/index.js @@ -29,8 +29,8 @@ var details = function () { return ({ tooltip: 'Specify terms to check for in file name using comma seperated list e.g. _720p,_1080p', }, { - label: 'Patterns', - name: 'patterns', + label: 'Pattern (regular expression)', + name: 'pattern', type: 'string', // eslint-disable-next-line no-template-curly-in-string defaultValue: '', @@ -38,7 +38,7 @@ var details = function () { return ({ type: 'text', }, // eslint-disable-next-line no-template-curly-in-string - tooltip: 'Specify patterns (regex) to check for in file name using comma seperated list e.g. ^Pattern*\.mkv$', + tooltip: 'Specify the pattern (regex) to check for in file name e.g. ^Pattern*\.mkv$', }, { label: 'Include file directory in check', @@ -71,15 +71,16 @@ var plugin = function (args) { // eslint-disable-next-line @typescript-eslint/no-unused-vars,no-param-reassign args.inputs = lib.loadDefaultValues(args.inputs, details); var buildArrayInput = function (arrayInput) { var _a, _b; return (_b = (_a = String(arrayInput)) === null || _a === void 0 ? void 0 : _a.trim().split(',')) !== null && _b !== void 0 ? _b : new Array(); }; + var isAMatch = false; var fileName = "".concat(Boolean(args.inputs.includeFileDirectory) ? (0, fileUtils_1.getFileAbosluteDir)(args.inputFileObj._id) + '/' : '').concat((0, fileUtils_1.getFileName)(args.inputFileObj._id), ".").concat((0, fileUtils_1.getContainer)(args.inputFileObj._id)); var searchCriteriasArray = buildArrayInput(args.inputs.terms) - .map(function (term) { return term.replace(/[\-\/\\^$*+?.()|[\]{}]/g, '\\$&'); }) // https://github.com/tc39/proposal-regex-escaping - .concat(buildArrayInput(args.inputs.patterns)); - var isAMatch = false; + .map(function (term) { return term.replace(/[\-\/\\^$*+?.()|[\]{}]/g, '\\$&'); }); // https://github.com/tc39/proposal-regex-escaping + if (args.inputs.pattern) + searchCriteriasArray.push(String(args.inputs.pattern)); for (var i = 0; i < searchCriteriasArray.length; i++) if (new RegExp(searchCriteriasArray[i]).test(fileName)) { isAMatch = true; - args.jobLog("".concat(fileName, " includes ").concat(searchCriteriasArray[i])); + args.jobLog("'".concat(fileName, "' includes '").concat(searchCriteriasArray[i], "'")); break; } return { diff --git a/FlowPluginsTs/CommunityFlowPlugins/file/checkFileNameIncludes/2.0.0/index.ts b/FlowPluginsTs/CommunityFlowPlugins/file/checkFileNameIncludes/2.0.0/index.ts index 3684018..30d6aae 100644 --- a/FlowPluginsTs/CommunityFlowPlugins/file/checkFileNameIncludes/2.0.0/index.ts +++ b/FlowPluginsTs/CommunityFlowPlugins/file/checkFileNameIncludes/2.0.0/index.ts @@ -32,8 +32,8 @@ const details = (): IpluginDetails => ({ tooltip: 'Specify terms to check for in file name using comma seperated list e.g. _720p,_1080p', }, { - label: 'Patterns', - name: 'patterns', + label: 'Pattern (regular expression)', + name: 'pattern', type: 'string', // eslint-disable-next-line no-template-curly-in-string defaultValue: '', @@ -41,7 +41,7 @@ const details = (): IpluginDetails => ({ type: 'text', }, // eslint-disable-next-line no-template-curly-in-string - tooltip: 'Specify patterns (regex) to check for in file name using comma seperated list e.g. ^Pattern*\.mkv$', + tooltip: 'Specify the pattern (regex) to check for in file name e.g. ^Pattern*\.mkv$', }, { label: 'Include file directory in check', @@ -77,16 +77,17 @@ const plugin = (args: IpluginInputArgs): IpluginOutputArgs => { const buildArrayInput = (arrayInput: any): string[] => String(arrayInput)?.trim().split(',') ?? new Array(); + let isAMatch = false; const fileName = `${Boolean(args.inputs.includeFileDirectory) ? getFileAbosluteDir(args.inputFileObj._id) + '/' : ''}${getFileName(args.inputFileObj._id)}.${getContainer(args.inputFileObj._id)}`; const searchCriteriasArray = buildArrayInput(args.inputs.terms) - .map(term => term.replace(/[\-\/\\^$*+?.()|[\]{}]/g, '\\$&')) // https://github.com/tc39/proposal-regex-escaping - .concat(buildArrayInput(args.inputs.patterns)); - let isAMatch = false; + .map(term => term.replace(/[\-\/\\^$*+?.()|[\]{}]/g, '\\$&')); // https://github.com/tc39/proposal-regex-escaping + if (args.inputs.pattern) + searchCriteriasArray.push(String(args.inputs.pattern)); for (let i = 0; i < searchCriteriasArray.length; i++) if (new RegExp(searchCriteriasArray[i]).test(fileName)) { isAMatch = true; - args.jobLog(`${fileName} includes ${searchCriteriasArray[i]}`); + args.jobLog(`'${fileName}' includes '${searchCriteriasArray[i]}'`); break; }