From 72e28ce23ae485c8126592ea19d814a62c78c40e Mon Sep 17 00:00:00 2001 From: HaveAGitGat <43864057+HaveAGitGat@users.noreply.github.com> Date: Tue, 14 May 2024 08:14:14 +0100 Subject: [PATCH] Add Apprise --- .../tools/apprise/1.0.0/index.ts | 90 +++++++++++++++++++ FlowPluginsTs/FlowHelpers/1.0.0/cliUtils.ts | 9 +- 2 files changed, 96 insertions(+), 3 deletions(-) create mode 100644 FlowPluginsTs/CommunityFlowPlugins/tools/apprise/1.0.0/index.ts diff --git a/FlowPluginsTs/CommunityFlowPlugins/tools/apprise/1.0.0/index.ts b/FlowPluginsTs/CommunityFlowPlugins/tools/apprise/1.0.0/index.ts new file mode 100644 index 0000000..cfd8a82 --- /dev/null +++ b/FlowPluginsTs/CommunityFlowPlugins/tools/apprise/1.0.0/index.ts @@ -0,0 +1,90 @@ +import { CLI } from '../../../../FlowHelpers/1.0.0/cliUtils'; +import { + IpluginDetails, + IpluginInputArgs, + IpluginOutputArgs, +} from '../../../../FlowHelpers/1.0.0/interfaces/interfaces'; + +/* eslint no-plusplus: ["error", { "allowForLoopAfterthoughts": true }] */ +const details = ():IpluginDetails => ({ + name: 'Apprise', + description: 'Use Apprise to send notifications.', + style: { + borderColor: 'green', + }, + tags: '', + isStartPlugin: false, + pType: '', + requiresVersion: '2.11.01', + sidebarPosition: -1, + icon: 'faBell', + inputs: [ + { + label: 'Command', + name: 'command', + type: 'string', + defaultValue: '-vv -t "Success" -b "File {{{args.inputFileObj._id}}}" "discord://xxx/xxxx"', + inputUI: { + type: 'textarea', + style: { + height: '100px', + }, + }, + tooltip: `Visit the following for more information on Apprise: https://github.com/caronc/apprise + \\nExample\\n + -vv -t "Success" -b "File {{{args.inputFileObj._id}}}" "discord://xxx/xxxx" + + + \\nExample\\n + -vv -t "Processing" -b "File {{{args.inputFileObj._id}}}" "discord://{{{args.userVariables.global.discord_webhook}}}" + `, + }, + ], + outputs: [ + { + number: 1, + tooltip: 'Continue to next plugin', + }, + ], +}); + +// eslint-disable-next-line @typescript-eslint/no-unused-vars +const plugin = async (args:IpluginInputArgs):Promise => { + 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 { command } = args.inputs; + + const cliArgs = [ + ...args.deps.parseArgsStringToArgv(command, '', ''), + ]; + + const cli = new CLI({ + cli: 'apprise', + spawnArgs: cliArgs, + spawnOpts: {}, + jobLog: args.jobLog, + outputFilePath: '', + inputFileObj: args.inputFileObj, + logFullCliOutput: args.logFullCliOutput, + updateWorker: args.updateWorker, + }); + + const res = await cli.runCli(); + + if (res.cliExitCode !== 0) { + args.jobLog('Running Apprise failed'); + throw new Error('Running Apprise failed'); + } + + return { + outputFileObj: args.inputFileObj, + outputNumber: 1, + variables: args.variables, + }; +}; +export { + details, + plugin, +}; diff --git a/FlowPluginsTs/FlowHelpers/1.0.0/cliUtils.ts b/FlowPluginsTs/FlowHelpers/1.0.0/cliUtils.ts index fcd074a..6da999c 100644 --- a/FlowPluginsTs/FlowHelpers/1.0.0/cliUtils.ts +++ b/FlowPluginsTs/FlowHelpers/1.0.0/cliUtils.ts @@ -315,7 +315,8 @@ class CLI { thread.on('error', () => { // catches execution error (bad file) // eslint-disable-next-line no-console - console.log(1, `Error executing binary: ${this.config.cli}`); + console.log(`Error executing binary: ${this.config.cli}`); + this.config.jobLog(`Error executing binary: ${this.config.cli}`); resolve(1); }); @@ -324,14 +325,16 @@ class CLI { thread.on('close', (code: number) => { if (code !== 0) { // eslint-disable-next-line no-console - console.log(code, 'CLI error'); + console.log(`CLI error code: ${code}`); + this.config.jobLog(`CLI error code: ${code}`); } resolve(code); }); } catch (err) { // catches execution error (no file) // eslint-disable-next-line no-console - console.log(1, `Error executing binary: ${this.config.cli}`); + console.log(`Error executing binary: ${this.config.cli}: ${err}`); + this.config.jobLog(`Error executing binary: ${this.config.cli}: ${err}`); resolve(1); } });