From ba55c8e40f208c9a632d8c3ac9d8dd4535ca7f1c Mon Sep 17 00:00:00 2001 From: HaveAGitGat <43864057+HaveAGitGat@users.noreply.github.com> Date: Thu, 21 Sep 2023 08:40:46 +0100 Subject: [PATCH 1/2] Add Compare File Size Ratio --- .../file/compareFileSizeRatio/1.0.0/index.js | 82 ++++++++++++++++ .../file/compareFileSizeRatio/1.0.0/index.ts | 94 +++++++++++++++++++ 2 files changed, 176 insertions(+) create mode 100644 FlowPlugins/CommunityFlowPlugins/file/compareFileSizeRatio/1.0.0/index.js create mode 100644 FlowPluginsTs/CommunityFlowPlugins/file/compareFileSizeRatio/1.0.0/index.ts diff --git a/FlowPlugins/CommunityFlowPlugins/file/compareFileSizeRatio/1.0.0/index.js b/FlowPlugins/CommunityFlowPlugins/file/compareFileSizeRatio/1.0.0/index.js new file mode 100644 index 000000000..52951c1ec --- /dev/null +++ b/FlowPlugins/CommunityFlowPlugins/file/compareFileSizeRatio/1.0.0/index.js @@ -0,0 +1,82 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.plugin = exports.details = void 0; +/* eslint no-plusplus: ["error", { "allowForLoopAfterthoughts": true }] */ +var details = function () { return ({ + name: 'Compare File Size Ratio', + description: 'Compare file size ratio of working file compared to original file using percentage.', + style: { + borderColor: 'orange', + }, + tags: '', + isStartPlugin: false, + pType: '', + requiresVersion: '2.11.01', + sidebarPosition: -1, + icon: 'faQuestion', + inputs: [ + { + name: 'greaterThan', + type: 'number', + defaultValue: '40', + inputUI: { + type: 'text', + }, + tooltip: 'Specify lower bound. Default value is 40% so new file size must be at least 40% of original file size.', + }, + { + name: 'lessThan', + type: 'number', + defaultValue: '110', + inputUI: { + type: 'text', + }, + tooltip: 'Specify upper bound. Default value is 110% so new file size must be at most 110% of original file size.', + }, + ], + outputs: [ + { + number: 1, + tooltip: 'Working file size % is within range', + }, + { + number: 2, + tooltip: 'Working file size % is not within range', + }, + ], +}); }; +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 isWithinRange = false; + var newFileSizeBytes = args.inputFileObj.file_size; + var origFileSizeBytes = args.originalLibraryFile.file_size; + var greaterThanPerc = Number(args.inputs.greaterThan); + var lessThanPerc = Number(args.inputs.lessThan); + var ratio = (newFileSizeBytes / origFileSizeBytes) * 100; + var sizeText = "New file has size ".concat(newFileSizeBytes.toFixed(3), " MB which is ").concat(ratio, "% ") + + "of original file size: ".concat(origFileSizeBytes.toFixed(3), " MB"); + var getBound = function (bound) { return (bound / 100) * origFileSizeBytes; }; + var errText = 'New file size not within limits.'; + if (newFileSizeBytes > getBound(lessThanPerc)) { + // Item will be errored in UI + args.jobLog("".concat(errText, " ").concat(sizeText, ". upperBound is ").concat(lessThanPerc, "%")); + } + else if (newFileSizeBytes < getBound(greaterThanPerc)) { + // // Item will be errored in UI + args.jobLog("".concat(errText, " ").concat(sizeText, ". lowerBound is ").concat(greaterThanPerc, "%")); + } + else { + args.jobLog(sizeText); + isWithinRange = true; + } + return { + outputFileObj: args.inputFileObj, + outputNumber: isWithinRange ? 1 : 2, + variables: args.variables, + }; +}; +exports.plugin = plugin; diff --git a/FlowPluginsTs/CommunityFlowPlugins/file/compareFileSizeRatio/1.0.0/index.ts b/FlowPluginsTs/CommunityFlowPlugins/file/compareFileSizeRatio/1.0.0/index.ts new file mode 100644 index 000000000..4c94a7a9c --- /dev/null +++ b/FlowPluginsTs/CommunityFlowPlugins/file/compareFileSizeRatio/1.0.0/index.ts @@ -0,0 +1,94 @@ +import { + IpluginDetails, + IpluginInputArgs, + IpluginOutputArgs, +} from '../../../../FlowHelpers/1.0.0/interfaces/interfaces'; + +/* eslint no-plusplus: ["error", { "allowForLoopAfterthoughts": true }] */ +const details = (): IpluginDetails => ({ + name: 'Compare File Size Ratio', + description: 'Compare file size ratio of working file compared to original file using percentage.', + style: { + borderColor: 'orange', + }, + tags: '', + + isStartPlugin: false, + pType: '', + requiresVersion: '2.11.01', + sidebarPosition: -1, + icon: 'faQuestion', + inputs: [ + { + name: 'greaterThan', + type: 'number', + defaultValue: '40', + inputUI: { + type: 'text', + }, + tooltip: 'Specify lower bound. Default value is 40% so new file size must be at least 40% of original file size.', + }, + { + name: 'lessThan', + type: 'number', + defaultValue: '110', + inputUI: { + type: 'text', + }, + tooltip: 'Specify upper bound. Default value is 110% so new file size must be at most 110% of original file size.', + }, + ], + outputs: [ + { + number: 1, + tooltip: 'Working file size % is within range', + }, + { + number: 2, + tooltip: 'Working file size % is not within range', + }, + ], +}); + +// 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); + + let isWithinRange = false; + const newFileSizeBytes = args.inputFileObj.file_size; + const origFileSizeBytes = args.originalLibraryFile.file_size; + + const greaterThanPerc = Number(args.inputs.greaterThan); + const lessThanPerc = Number(args.inputs.lessThan); + + const ratio = (newFileSizeBytes / origFileSizeBytes) * 100; + + const sizeText = `New file has size ${newFileSizeBytes.toFixed(3)} MB which is ${ratio}% ` + + `of original file size: ${origFileSizeBytes.toFixed(3)} MB`; + + const getBound = (bound:number) => (bound / 100) * origFileSizeBytes; + + const errText = 'New file size not within limits.'; + if (newFileSizeBytes > getBound(lessThanPerc)) { + // Item will be errored in UI + args.jobLog(`${errText} ${sizeText}. upperBound is ${lessThanPerc}%`); + } else if (newFileSizeBytes < getBound(greaterThanPerc)) { + // // Item will be errored in UI + args.jobLog(`${errText} ${sizeText}. lowerBound is ${greaterThanPerc}%`); + } else { + args.jobLog(sizeText); + isWithinRange = true; + } + + return { + outputFileObj: args.inputFileObj, + outputNumber: isWithinRange ? 1 : 2, + variables: args.variables, + }; +}; +export { + details, + plugin, +}; From b71bd5ea3e5e2f19dd80b5f5b145504529676a9f Mon Sep 17 00:00:00 2001 From: HaveAGitGat <43864057+HaveAGitGat@users.noreply.github.com> Date: Thu, 21 Sep 2023 08:42:22 +0100 Subject: [PATCH 2/2] Fix lint --- .../file/compareFileSizeRatio/1.0.0/index.js | 6 ++++-- .../file/compareFileSizeRatio/1.0.0/index.ts | 6 ++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/FlowPlugins/CommunityFlowPlugins/file/compareFileSizeRatio/1.0.0/index.js b/FlowPlugins/CommunityFlowPlugins/file/compareFileSizeRatio/1.0.0/index.js index 52951c1ec..ea8b567ec 100644 --- a/FlowPlugins/CommunityFlowPlugins/file/compareFileSizeRatio/1.0.0/index.js +++ b/FlowPlugins/CommunityFlowPlugins/file/compareFileSizeRatio/1.0.0/index.js @@ -22,7 +22,8 @@ var details = function () { return ({ inputUI: { type: 'text', }, - tooltip: 'Specify lower bound. Default value is 40% so new file size must be at least 40% of original file size.', + tooltip: 'Specify lower bound. ' + + 'Default value is 40% so new file size must be at least 40% of original file size.', }, { name: 'lessThan', @@ -31,7 +32,8 @@ var details = function () { return ({ inputUI: { type: 'text', }, - tooltip: 'Specify upper bound. Default value is 110% so new file size must be at most 110% of original file size.', + tooltip: 'Specify upper bound.' + + ' Default value is 110% so new file size must be at most 110% of original file size.', }, ], outputs: [ diff --git a/FlowPluginsTs/CommunityFlowPlugins/file/compareFileSizeRatio/1.0.0/index.ts b/FlowPluginsTs/CommunityFlowPlugins/file/compareFileSizeRatio/1.0.0/index.ts index 4c94a7a9c..dfcd7148f 100644 --- a/FlowPluginsTs/CommunityFlowPlugins/file/compareFileSizeRatio/1.0.0/index.ts +++ b/FlowPluginsTs/CommunityFlowPlugins/file/compareFileSizeRatio/1.0.0/index.ts @@ -26,7 +26,8 @@ const details = (): IpluginDetails => ({ inputUI: { type: 'text', }, - tooltip: 'Specify lower bound. Default value is 40% so new file size must be at least 40% of original file size.', + tooltip: 'Specify lower bound. ' + + 'Default value is 40% so new file size must be at least 40% of original file size.', }, { name: 'lessThan', @@ -35,7 +36,8 @@ const details = (): IpluginDetails => ({ inputUI: { type: 'text', }, - tooltip: 'Specify upper bound. Default value is 110% so new file size must be at most 110% of original file size.', + tooltip: 'Specify upper bound.' + + ' Default value is 110% so new file size must be at most 110% of original file size.', }, ], outputs: [