From 40eb15412e64c3871092b821bd9170dbed969d1b Mon Sep 17 00:00:00 2001 From: "jeanchristophe.mqt@gmail.com" Date: Wed, 20 Mar 2024 00:16:09 +0100 Subject: [PATCH 01/13] Added new version for checkFileNameIncludes flow plugin checking for regex patterns --- .../file/checkFileNameIncludes/2.0.0/index.js | 90 ++++++++++++++++ .../file/checkFileNameIncludes/2.0.0/index.ts | 101 ++++++++++++++++++ 2 files changed, 191 insertions(+) create mode 100644 FlowPlugins/CommunityFlowPlugins/file/checkFileNameIncludes/2.0.0/index.js create mode 100644 FlowPluginsTs/CommunityFlowPlugins/file/checkFileNameIncludes/2.0.0/index.ts diff --git a/FlowPlugins/CommunityFlowPlugins/file/checkFileNameIncludes/2.0.0/index.js b/FlowPlugins/CommunityFlowPlugins/file/checkFileNameIncludes/2.0.0/index.js new file mode 100644 index 0000000..14f3082 --- /dev/null +++ b/FlowPlugins/CommunityFlowPlugins/file/checkFileNameIncludes/2.0.0/index.js @@ -0,0 +1,90 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.plugin = exports.details = void 0; +var fileUtils_1 = require("../../../../FlowHelpers/1.0.0/fileUtils"); +/* eslint no-plusplus: ["error", { "allowForLoopAfterthoughts": true }] */ +var details = function () { return ({ + name: 'Check File Name Includes', + description: 'Check if a file name includes specific terms. Only needs to match one term', + style: { + borderColor: 'orange', + }, + tags: 'video', + isStartPlugin: false, + pType: '', + requiresVersion: '2.11.01', + sidebarPosition: -1, + icon: 'faQuestion', + inputs: [ + { + label: 'Terms', + name: 'terms', + type: 'string', + // eslint-disable-next-line no-template-curly-in-string + defaultValue: '_720p,_1080p', + inputUI: { + type: 'text', + }, + // eslint-disable-next-line no-template-curly-in-string + tooltip: 'Specify terms to check for in file name using comma seperated list e.g. _720p,_1080p', + }, + { + label: 'Patterns', + name: 'patterns', + type: 'string', + // eslint-disable-next-line no-template-curly-in-string + defaultValue: '', + inputUI: { + 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$', + }, + { + label: 'Include file directory in check', + name: 'includeFileDirectory', + type: 'boolean', + // eslint-disable-next-line no-template-curly-in-string + defaultValue: 'false', + inputUI: { + type: 'switch', + }, + // eslint-disable-next-line no-template-curly-in-string + tooltip: 'Should the terms and patterns be evaluated against the file directory e.g. false, true', + } + ], + outputs: [ + { + number: 1, + tooltip: 'File name contains terms or patterns', + }, + { + number: 2, + tooltip: 'File name does not contain any of the terms or patterns', + }, + ], +}); }; +exports.details = details; +// eslint-disable-next-line @typescript-eslint/no-unused-vars +var plugin = function (args) { + var lib = require('../../../../../methods/lib')(); + // 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 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) + .concat(buildArrayInput(args.inputs.patterns)); + var isAMatch = false; + 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])); + break; + } + return { + outputFileObj: args.inputFileObj, + outputNumber: isAMatch ? 1 : 2, + variables: args.variables, + }; +}; +exports.plugin = plugin; diff --git a/FlowPluginsTs/CommunityFlowPlugins/file/checkFileNameIncludes/2.0.0/index.ts b/FlowPluginsTs/CommunityFlowPlugins/file/checkFileNameIncludes/2.0.0/index.ts new file mode 100644 index 0000000..126fd50 --- /dev/null +++ b/FlowPluginsTs/CommunityFlowPlugins/file/checkFileNameIncludes/2.0.0/index.ts @@ -0,0 +1,101 @@ +import { getContainer, getFileAbosluteDir, getFileName } from '../../../../FlowHelpers/1.0.0/fileUtils'; +import { + IpluginDetails, + IpluginInputArgs, + IpluginOutputArgs, +} from '../../../../FlowHelpers/1.0.0/interfaces/interfaces'; + +/* eslint no-plusplus: ["error", { "allowForLoopAfterthoughts": true }] */ +const details = (): IpluginDetails => ({ + name: 'Check File Name Includes', + description: 'Check if a file name includes specific terms. Only needs to match one term', + style: { + borderColor: 'orange', + }, + tags: 'video', + isStartPlugin: false, + pType: '', + requiresVersion: '2.11.01', + sidebarPosition: -1, + icon: 'faQuestion', + inputs: [ + { + label: 'Terms', + name: 'terms', + type: 'string', + // eslint-disable-next-line no-template-curly-in-string + defaultValue: '_720p,_1080p', + inputUI: { + type: 'text', + }, + // eslint-disable-next-line no-template-curly-in-string + tooltip: 'Specify terms to check for in file name using comma seperated list e.g. _720p,_1080p', + }, + { + label: 'Patterns', + name: 'patterns', + type: 'string', + // eslint-disable-next-line no-template-curly-in-string + defaultValue: '', + inputUI: { + 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$', + }, + { + label: 'Include file directory in check', + name: 'includeFileDirectory', + type: 'boolean', + // eslint-disable-next-line no-template-curly-in-string + defaultValue: 'false', + inputUI: { + type: 'switch', + }, + // eslint-disable-next-line no-template-curly-in-string + tooltip: 'Should the terms and patterns be evaluated against the file directory e.g. false, true', + } + ], + outputs: [ + { + number: 1, + tooltip: 'File name contains terms or patterns', + }, + { + number: 2, + tooltip: 'File name does not contain any of the terms or patterns', + }, + ], +}); + +// eslint-disable-next-line @typescript-eslint/no-unused-vars +const plugin = (args: IpluginInputArgs): 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 buildArrayInput = (arrayInput: any): string[] => + String(arrayInput)?.trim().split(',') ?? new Array(); + + const fileName = `${Boolean(args.inputs.includeFileDirectory) ? getFileAbosluteDir(args.inputFileObj._id) + '/' : ''}${getFileName(args.inputFileObj._id)}.${getContainer(args.inputFileObj._id)}`; + const searchCriteriasArray = buildArrayInput(args.inputs.terms) + .concat(buildArrayInput(args.inputs.patterns)); + let isAMatch = false; + + for (let i = 0; i < searchCriteriasArray.length; i++) + if (new RegExp(searchCriteriasArray[i]).test(fileName)) { + isAMatch = true; + args.jobLog(`${fileName} includes ${searchCriteriasArray[i]}`); + break; + } + + return { + outputFileObj: args.inputFileObj, + outputNumber: isAMatch ? 1 : 2, + variables: args.variables, + }; +}; +export { + details, + plugin, +}; From 79419f6190e56f64987204660e4720644f2ca631 Mon Sep 17 00:00:00 2001 From: "jeanchristophe.mqt@gmail.com" Date: Wed, 20 Mar 2024 10:11:00 +0100 Subject: [PATCH 02/13] Escaping regex special caracters --- .../file/checkFileNameIncludes/2.0.0/index.js | 1 + .../file/checkFileNameIncludes/2.0.0/index.ts | 1 + 2 files changed, 2 insertions(+) diff --git a/FlowPlugins/CommunityFlowPlugins/file/checkFileNameIncludes/2.0.0/index.js b/FlowPlugins/CommunityFlowPlugins/file/checkFileNameIncludes/2.0.0/index.js index 14f3082..f206a2b 100644 --- a/FlowPlugins/CommunityFlowPlugins/file/checkFileNameIncludes/2.0.0/index.js +++ b/FlowPlugins/CommunityFlowPlugins/file/checkFileNameIncludes/2.0.0/index.js @@ -73,6 +73,7 @@ var plugin = function (args) { 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 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; for (var i = 0; i < searchCriteriasArray.length; i++) diff --git a/FlowPluginsTs/CommunityFlowPlugins/file/checkFileNameIncludes/2.0.0/index.ts b/FlowPluginsTs/CommunityFlowPlugins/file/checkFileNameIncludes/2.0.0/index.ts index 126fd50..3684018 100644 --- a/FlowPluginsTs/CommunityFlowPlugins/file/checkFileNameIncludes/2.0.0/index.ts +++ b/FlowPluginsTs/CommunityFlowPlugins/file/checkFileNameIncludes/2.0.0/index.ts @@ -79,6 +79,7 @@ const plugin = (args: IpluginInputArgs): IpluginOutputArgs => { 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; 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 03/13] 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; } From 9a02d4b34400593cef309b427b3e170c643b5ef0 Mon Sep 17 00:00:00 2001 From: "jeanchristophe.mqt@gmail.com" Date: Fri, 22 Mar 2024 23:25:07 +0100 Subject: [PATCH 04/13] Fix eslint warnings and errors --- .../file/checkFileNameIncludes/2.0.0/index.js | 14 ++++++++------ .../file/checkFileNameIncludes/2.0.0/index.ts | 19 ++++++++++--------- 2 files changed, 18 insertions(+), 15 deletions(-) diff --git a/FlowPlugins/CommunityFlowPlugins/file/checkFileNameIncludes/2.0.0/index.js b/FlowPlugins/CommunityFlowPlugins/file/checkFileNameIncludes/2.0.0/index.js index eb86c17..9e1ff36 100644 --- a/FlowPlugins/CommunityFlowPlugins/file/checkFileNameIncludes/2.0.0/index.js +++ b/FlowPlugins/CommunityFlowPlugins/file/checkFileNameIncludes/2.0.0/index.js @@ -38,7 +38,7 @@ var details = function () { return ({ type: 'text', }, // eslint-disable-next-line no-template-curly-in-string - tooltip: 'Specify the pattern (regex) to check for in file name 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', @@ -51,7 +51,7 @@ var details = function () { return ({ }, // eslint-disable-next-line no-template-curly-in-string tooltip: 'Should the terms and patterns be evaluated against the file directory e.g. false, true', - } + }, ], outputs: [ { @@ -70,19 +70,21 @@ var plugin = function (args) { var lib = require('../../../../../methods/lib')(); // 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 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 : []; }; 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 fileName = "".concat((args.inputs.includeFileDirectory ? "".concat((0, fileUtils_1.getFileAbosluteDir)(args.inputFileObj._id), "/") : '') + + (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 + .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++) + 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], "'")); break; } + } return { outputFileObj: args.inputFileObj, outputNumber: isAMatch ? 1 : 2, diff --git a/FlowPluginsTs/CommunityFlowPlugins/file/checkFileNameIncludes/2.0.0/index.ts b/FlowPluginsTs/CommunityFlowPlugins/file/checkFileNameIncludes/2.0.0/index.ts index 30d6aae..f3aedaa 100644 --- a/FlowPluginsTs/CommunityFlowPlugins/file/checkFileNameIncludes/2.0.0/index.ts +++ b/FlowPluginsTs/CommunityFlowPlugins/file/checkFileNameIncludes/2.0.0/index.ts @@ -41,7 +41,7 @@ const details = (): IpluginDetails => ({ type: 'text', }, // eslint-disable-next-line no-template-curly-in-string - tooltip: 'Specify the pattern (regex) to check for in file name 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', @@ -54,7 +54,7 @@ const details = (): IpluginDetails => ({ }, // eslint-disable-next-line no-template-curly-in-string tooltip: 'Should the terms and patterns be evaluated against the file directory e.g. false, true', - } + }, ], outputs: [ { @@ -74,22 +74,23 @@ const plugin = (args: IpluginInputArgs): IpluginOutputArgs => { // eslint-disable-next-line @typescript-eslint/no-unused-vars,no-param-reassign args.inputs = lib.loadDefaultValues(args.inputs, details); - const buildArrayInput = (arrayInput: any): string[] => - String(arrayInput)?.trim().split(',') ?? new Array(); + const buildArrayInput = (arrayInput: unknown): string[] => String(arrayInput)?.trim().split(',') ?? []; let isAMatch = false; - const fileName = `${Boolean(args.inputs.includeFileDirectory) ? getFileAbosluteDir(args.inputFileObj._id) + '/' : ''}${getFileName(args.inputFileObj._id)}.${getContainer(args.inputFileObj._id)}`; + const fileName = `${(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 - if (args.inputs.pattern) - searchCriteriasArray.push(String(args.inputs.pattern)); + .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++) + for (let i = 0; i < searchCriteriasArray.length; i++) { if (new RegExp(searchCriteriasArray[i]).test(fileName)) { isAMatch = true; args.jobLog(`'${fileName}' includes '${searchCriteriasArray[i]}'`); break; } + } return { outputFileObj: args.inputFileObj, From c04dba1453401936646feab95077f9db02f6eca1 Mon Sep 17 00:00:00 2001 From: "jeanchristophe.mqt@gmail.com" Date: Fri, 22 Mar 2024 23:35:39 +0100 Subject: [PATCH 05/13] Replaced custom code by array.prototype.find --- .../file/checkFileNameIncludes/2.0.0/index.js | 13 +++++-------- .../file/checkFileNameIncludes/2.0.0/index.ts | 12 ++++-------- 2 files changed, 9 insertions(+), 16 deletions(-) diff --git a/FlowPlugins/CommunityFlowPlugins/file/checkFileNameIncludes/2.0.0/index.js b/FlowPlugins/CommunityFlowPlugins/file/checkFileNameIncludes/2.0.0/index.js index 9e1ff36..5a1b11c 100644 --- a/FlowPlugins/CommunityFlowPlugins/file/checkFileNameIncludes/2.0.0/index.js +++ b/FlowPlugins/CommunityFlowPlugins/file/checkFileNameIncludes/2.0.0/index.js @@ -71,20 +71,17 @@ 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 : []; }; - var isAMatch = false; var fileName = "".concat((args.inputs.includeFileDirectory ? "".concat((0, fileUtils_1.getFileAbosluteDir)(args.inputFileObj._id), "/") : '') + (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 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], "'")); - break; - } - } + var searchCriteriaMatched = searchCriteriasArray + .find(function (searchCriteria) { return new RegExp(searchCriteria).test(fileName); }); + var isAMatch = searchCriteriaMatched !== undefined; + if (isAMatch) + args.jobLog("'".concat(fileName, "' includes '").concat(searchCriteriaMatched, "'")); return { outputFileObj: args.inputFileObj, outputNumber: isAMatch ? 1 : 2, diff --git a/FlowPluginsTs/CommunityFlowPlugins/file/checkFileNameIncludes/2.0.0/index.ts b/FlowPluginsTs/CommunityFlowPlugins/file/checkFileNameIncludes/2.0.0/index.ts index f3aedaa..3cbda14 100644 --- a/FlowPluginsTs/CommunityFlowPlugins/file/checkFileNameIncludes/2.0.0/index.ts +++ b/FlowPluginsTs/CommunityFlowPlugins/file/checkFileNameIncludes/2.0.0/index.ts @@ -76,7 +76,6 @@ const plugin = (args: IpluginInputArgs): IpluginOutputArgs => { const buildArrayInput = (arrayInput: unknown): string[] => String(arrayInput)?.trim().split(',') ?? []; - let isAMatch = false; const fileName = `${(args.inputs.includeFileDirectory ? `${getFileAbosluteDir(args.inputFileObj._id)}/` : '') + getFileName(args.inputFileObj._id) }.${getContainer(args.inputFileObj._id)}`; @@ -84,13 +83,10 @@ const plugin = (args: IpluginInputArgs): IpluginOutputArgs => { .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]}'`); - break; - } - } + const searchCriteriaMatched = searchCriteriasArray + .find((searchCriteria) => new RegExp(searchCriteria).test(fileName)); + const isAMatch = searchCriteriaMatched !== undefined; + if (isAMatch) args.jobLog(`'${fileName}' includes '${searchCriteriaMatched}'`); return { outputFileObj: args.inputFileObj, From 346a4598b947e6d1108ca16c11639fe5fa3e24fa Mon Sep 17 00:00:00 2001 From: HaveAGitGat <43864057+HaveAGitGat@users.noreply.github.com> Date: Tue, 7 May 2024 07:56:43 +0100 Subject: [PATCH 06/13] Update checkout actions --- .github/workflows/lint_and_test.yml | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/.github/workflows/lint_and_test.yml b/.github/workflows/lint_and_test.yml index 2747f26..518b292 100644 --- a/.github/workflows/lint_and_test.yml +++ b/.github/workflows/lint_and_test.yml @@ -23,7 +23,10 @@ jobs: git config --global core.autocrlf false git config --global core.eol lf - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 + with: + ref: ${{ github.event.pull_request.head.sha }} + - name: Use Node.js ${{ matrix.node-version }} uses: actions/setup-node@v1 with: @@ -46,9 +49,9 @@ jobs: contents: write steps: - - uses: actions/checkout@v4 + - uses: actions/checkout@v3 with: - ref: ${{ github.head_ref }} + ref: ${{ github.event.pull_request.head.sha }} - uses: actions/setup-node@v3 with: From 7bc3f8a082cb969903150131850dc03e65efed02 Mon Sep 17 00:00:00 2001 From: HaveAGitGat <43864057+HaveAGitGat@users.noreply.github.com> Date: Tue, 7 May 2024 08:14:17 +0100 Subject: [PATCH 07/13] Remove unused eslint rule --- .../file/checkFileNameIncludes/1.0.0/index.ts | 2 -- .../file/checkFileNameIncludes/2.0.0/index.ts | 6 ------ 2 files changed, 8 deletions(-) diff --git a/FlowPluginsTs/CommunityFlowPlugins/file/checkFileNameIncludes/1.0.0/index.ts b/FlowPluginsTs/CommunityFlowPlugins/file/checkFileNameIncludes/1.0.0/index.ts index f54ac41..6d512b6 100644 --- a/FlowPluginsTs/CommunityFlowPlugins/file/checkFileNameIncludes/1.0.0/index.ts +++ b/FlowPluginsTs/CommunityFlowPlugins/file/checkFileNameIncludes/1.0.0/index.ts @@ -23,12 +23,10 @@ const details = (): IpluginDetails => ({ label: 'Terms', name: 'terms', type: 'string', - // eslint-disable-next-line no-template-curly-in-string defaultValue: '_720p,_1080p', inputUI: { type: 'text', }, - // eslint-disable-next-line no-template-curly-in-string tooltip: 'Specify terms to check for in file name using comma seperated list e.g. _720p,_1080p', }, ], diff --git a/FlowPluginsTs/CommunityFlowPlugins/file/checkFileNameIncludes/2.0.0/index.ts b/FlowPluginsTs/CommunityFlowPlugins/file/checkFileNameIncludes/2.0.0/index.ts index 3cbda14..cea52e6 100644 --- a/FlowPluginsTs/CommunityFlowPlugins/file/checkFileNameIncludes/2.0.0/index.ts +++ b/FlowPluginsTs/CommunityFlowPlugins/file/checkFileNameIncludes/2.0.0/index.ts @@ -23,36 +23,30 @@ const details = (): IpluginDetails => ({ label: 'Terms', name: 'terms', type: 'string', - // eslint-disable-next-line no-template-curly-in-string defaultValue: '_720p,_1080p', inputUI: { type: 'text', }, - // eslint-disable-next-line no-template-curly-in-string tooltip: 'Specify terms to check for in file name using comma seperated list e.g. _720p,_1080p', }, { label: 'Pattern (regular expression)', name: 'pattern', type: 'string', - // eslint-disable-next-line no-template-curly-in-string defaultValue: '', inputUI: { type: 'text', }, - // eslint-disable-next-line no-template-curly-in-string tooltip: 'Specify the pattern (regex) to check for in file name e.g. ^Pattern.*mkv$', }, { label: 'Include file directory in check', name: 'includeFileDirectory', type: 'boolean', - // eslint-disable-next-line no-template-curly-in-string defaultValue: 'false', inputUI: { type: 'switch', }, - // eslint-disable-next-line no-template-curly-in-string tooltip: 'Should the terms and patterns be evaluated against the file directory e.g. false, true', }, ], From bb78f24135364b28543fd0d032e5ff1d8553d3bd Mon Sep 17 00:00:00 2001 From: HaveAGitGat <43864057+HaveAGitGat@users.noreply.github.com> Date: Tue, 7 May 2024 08:40:01 +0100 Subject: [PATCH 08/13] Simplify logic and readability --- .../file/checkFileNameIncludes/2.0.0/index.ts | 27 +++++++++++++------ 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/FlowPluginsTs/CommunityFlowPlugins/file/checkFileNameIncludes/2.0.0/index.ts b/FlowPluginsTs/CommunityFlowPlugins/file/checkFileNameIncludes/2.0.0/index.ts index cea52e6..aba3ae0 100644 --- a/FlowPluginsTs/CommunityFlowPlugins/file/checkFileNameIncludes/2.0.0/index.ts +++ b/FlowPluginsTs/CommunityFlowPlugins/file/checkFileNameIncludes/2.0.0/index.ts @@ -1,4 +1,4 @@ -import { getContainer, getFileAbosluteDir, getFileName } from '../../../../FlowHelpers/1.0.0/fileUtils'; +import { getContainer, getFileName } from '../../../../FlowHelpers/1.0.0/fileUtils'; import { IpluginDetails, IpluginInputArgs, @@ -68,19 +68,30 @@ const plugin = (args: IpluginInputArgs): IpluginOutputArgs => { // eslint-disable-next-line @typescript-eslint/no-unused-vars,no-param-reassign args.inputs = lib.loadDefaultValues(args.inputs, details); - const buildArrayInput = (arrayInput: unknown): string[] => String(arrayInput)?.trim().split(',') ?? []; + const terms = String(args.inputs.terms); + const pattern = String(args.inputs.pattern); + const { includeFileDirectory } = args.inputs; - const fileName = `${(args.inputs.includeFileDirectory ? `${getFileAbosluteDir(args.inputFileObj._id)}/` : '') - + getFileName(args.inputFileObj._id) - }.${getContainer(args.inputFileObj._id)}`; - const searchCriteriasArray = buildArrayInput(args.inputs.terms) + const fileName = includeFileDirectory + ? args.inputFileObj._id + : `${getFileName(args.inputFileObj._id)}.${getContainer(args.inputFileObj._id)}`; + + const searchCriteriasArray = terms.trim().split(',') .map((term) => term.replace(/[\\^$*+?.()|[\]{}]/g, '\\$&')); // https://github.com/tc39/proposal-regex-escaping - if (args.inputs.pattern) searchCriteriasArray.push(String(args.inputs.pattern)); + + if (pattern) { + searchCriteriasArray.push(pattern); + } const searchCriteriaMatched = searchCriteriasArray .find((searchCriteria) => new RegExp(searchCriteria).test(fileName)); const isAMatch = searchCriteriaMatched !== undefined; - if (isAMatch) args.jobLog(`'${fileName}' includes '${searchCriteriaMatched}'`); + + if (isAMatch) { + args.jobLog(`'${fileName}' includes '${searchCriteriaMatched}'`); + } else { + args.jobLog(`'${fileName}' does not include any of the terms or patterns`); + } return { outputFileObj: args.inputFileObj, From 0d3f2454df1fed0448622301a5466bedabd6c33e Mon Sep 17 00:00:00 2001 From: HaveAGitGat <43864057+HaveAGitGat@users.noreply.github.com> Date: Wed, 8 May 2024 04:49:11 +0100 Subject: [PATCH 09/13] github.head_ref --- .github/workflows/lint_and_test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/lint_and_test.yml b/.github/workflows/lint_and_test.yml index 65ddb85..9afd283 100644 --- a/.github/workflows/lint_and_test.yml +++ b/.github/workflows/lint_and_test.yml @@ -51,7 +51,7 @@ jobs: steps: - uses: actions/checkout@v3 with: - ref: ${{ github.event.pull_request.head.sha }} + ref: ${{ github.head_ref }} - uses: actions/setup-node@v3 with: From 6d5955a5172d8dddf5e0eca1793d7e6a739c30f8 Mon Sep 17 00:00:00 2001 From: HaveAGitGat <43864057+HaveAGitGat@users.noreply.github.com> Date: Wed, 8 May 2024 05:20:44 +0100 Subject: [PATCH 10/13] Don't auto build on fork PR --- .github/workflows/lint_and_test.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/lint_and_test.yml b/.github/workflows/lint_and_test.yml index 9afd283..fdecb55 100644 --- a/.github/workflows/lint_and_test.yml +++ b/.github/workflows/lint_and_test.yml @@ -60,5 +60,8 @@ jobs: - run: npm i && npm i -g typescript && rm -rdf ./FlowPlugins && tsc -v && tsc - uses: stefanzweifel/git-auto-commit-action@v5 + if: ${{ github.event.pull_request.head.repo.full_name == 'org/repo' }} with: - commit_message: Apply auto-build changes \ No newline at end of file + commit_message: Apply auto-build changes + + - run: (git diff --quiet HEAD -- 2>/dev/null && echo "No uncommitted changes" || (echo "Error: Uncommitted changes found." && exit 1)) \ No newline at end of file From 9439b9102c455613b9e3cd9b01b787c07885fe31 Mon Sep 17 00:00:00 2001 From: HaveAGitGat <43864057+HaveAGitGat@users.noreply.github.com> Date: Wed, 8 May 2024 05:32:16 +0100 Subject: [PATCH 11/13] Don't autobuild on fork PR --- .github/workflows/lint_and_test.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/lint_and_test.yml b/.github/workflows/lint_and_test.yml index fdecb55..6303744 100644 --- a/.github/workflows/lint_and_test.yml +++ b/.github/workflows/lint_and_test.yml @@ -64,4 +64,6 @@ jobs: with: commit_message: Apply auto-build changes - - run: (git diff --quiet HEAD -- 2>/dev/null && echo "No uncommitted changes" || (echo "Error: Uncommitted changes found." && exit 1)) \ No newline at end of file + - run: | + (git diff --quiet HEAD -- 2>/dev/null && echo "No uncommitted changes" \ + || (echo "Error - Uncommitted changes found." && git --no-pager diff HEAD && exit 1)) \ No newline at end of file From dea6ec25a061f6b889471a9fe734d68886960411 Mon Sep 17 00:00:00 2001 From: HaveAGitGat <43864057+HaveAGitGat@users.noreply.github.com> Date: Wed, 8 May 2024 05:36:39 +0100 Subject: [PATCH 12/13] Use github.event.pull_request.head.sha --- .github/workflows/lint_and_test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/lint_and_test.yml b/.github/workflows/lint_and_test.yml index 6303744..293202d 100644 --- a/.github/workflows/lint_and_test.yml +++ b/.github/workflows/lint_and_test.yml @@ -51,7 +51,7 @@ jobs: steps: - uses: actions/checkout@v3 with: - ref: ${{ github.head_ref }} + ref: ${{ github.event.pull_request.head.sha }} - uses: actions/setup-node@v3 with: From 1a9a45e5edce7566abc5ab4981e2391fb7401adb Mon Sep 17 00:00:00 2001 From: HaveAGitGat <43864057+HaveAGitGat@users.noreply.github.com> Date: Wed, 8 May 2024 05:42:51 +0100 Subject: [PATCH 13/13] Add compiled changes --- .../file/checkFileNameIncludes/1.0.0/index.js | 2 -- .../file/checkFileNameIncludes/2.0.0/index.js | 28 ++++++++++--------- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/FlowPlugins/CommunityFlowPlugins/file/checkFileNameIncludes/1.0.0/index.js b/FlowPlugins/CommunityFlowPlugins/file/checkFileNameIncludes/1.0.0/index.js index 87f44da..271ef8b 100644 --- a/FlowPlugins/CommunityFlowPlugins/file/checkFileNameIncludes/1.0.0/index.js +++ b/FlowPlugins/CommunityFlowPlugins/file/checkFileNameIncludes/1.0.0/index.js @@ -20,12 +20,10 @@ var details = function () { return ({ label: 'Terms', name: 'terms', type: 'string', - // eslint-disable-next-line no-template-curly-in-string defaultValue: '_720p,_1080p', inputUI: { type: 'text', }, - // eslint-disable-next-line no-template-curly-in-string tooltip: 'Specify terms to check for in file name using comma seperated list e.g. _720p,_1080p', }, ], diff --git a/FlowPlugins/CommunityFlowPlugins/file/checkFileNameIncludes/2.0.0/index.js b/FlowPlugins/CommunityFlowPlugins/file/checkFileNameIncludes/2.0.0/index.js index 5a1b11c..8bad238 100644 --- a/FlowPlugins/CommunityFlowPlugins/file/checkFileNameIncludes/2.0.0/index.js +++ b/FlowPlugins/CommunityFlowPlugins/file/checkFileNameIncludes/2.0.0/index.js @@ -20,36 +20,30 @@ var details = function () { return ({ label: 'Terms', name: 'terms', type: 'string', - // eslint-disable-next-line no-template-curly-in-string defaultValue: '_720p,_1080p', inputUI: { type: 'text', }, - // eslint-disable-next-line no-template-curly-in-string tooltip: 'Specify terms to check for in file name using comma seperated list e.g. _720p,_1080p', }, { label: 'Pattern (regular expression)', name: 'pattern', type: 'string', - // eslint-disable-next-line no-template-curly-in-string defaultValue: '', inputUI: { type: 'text', }, - // eslint-disable-next-line no-template-curly-in-string tooltip: 'Specify the pattern (regex) to check for in file name e.g. ^Pattern.*mkv$', }, { label: 'Include file directory in check', name: 'includeFileDirectory', type: 'boolean', - // eslint-disable-next-line no-template-curly-in-string defaultValue: 'false', inputUI: { type: 'switch', }, - // eslint-disable-next-line no-template-curly-in-string tooltip: 'Should the terms and patterns be evaluated against the file directory e.g. false, true', }, ], @@ -70,18 +64,26 @@ var plugin = function (args) { var lib = require('../../../../../methods/lib')(); // 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 : []; }; - var fileName = "".concat((args.inputs.includeFileDirectory ? "".concat((0, fileUtils_1.getFileAbosluteDir)(args.inputFileObj._id), "/") : '') - + (0, fileUtils_1.getFileName)(args.inputFileObj._id), ".").concat((0, fileUtils_1.getContainer)(args.inputFileObj._id)); - var searchCriteriasArray = buildArrayInput(args.inputs.terms) + var terms = String(args.inputs.terms); + var pattern = String(args.inputs.pattern); + var includeFileDirectory = args.inputs.includeFileDirectory; + var fileName = includeFileDirectory + ? args.inputFileObj._id + : "".concat((0, fileUtils_1.getFileName)(args.inputFileObj._id), ".").concat((0, fileUtils_1.getContainer)(args.inputFileObj._id)); + var searchCriteriasArray = terms.trim().split(',') .map(function (term) { return term.replace(/[\\^$*+?.()|[\]{}]/g, '\\$&'); }); // https://github.com/tc39/proposal-regex-escaping - if (args.inputs.pattern) - searchCriteriasArray.push(String(args.inputs.pattern)); + if (pattern) { + searchCriteriasArray.push(pattern); + } var searchCriteriaMatched = searchCriteriasArray .find(function (searchCriteria) { return new RegExp(searchCriteria).test(fileName); }); var isAMatch = searchCriteriaMatched !== undefined; - if (isAMatch) + if (isAMatch) { args.jobLog("'".concat(fileName, "' includes '").concat(searchCriteriaMatched, "'")); + } + else { + args.jobLog("'".concat(fileName, "' does not include any of the terms or patterns")); + } return { outputFileObj: args.inputFileObj, outputNumber: isAMatch ? 1 : 2,