NodeJS: Custom Module if File Exists (Custom Module for files outside root)

For my custom synchronization module I created several custom modules to be able to upload files from our local Windows Server to Ionos S3.

Everything works quite well. I have recreated the custom “File/Folder Statistic Module” and an “Upload Module to S3”. What I still need is the “if file exists module” for files outside website root.

I know that all I need is to delete the “const { toSystemPath } = require(’…/…/…/lib/core/path’);” and change the path settings in the function.

The recreation of a custom “if file exists” Module is more complicated. Any hints how to accomplish this? I need the then else steps :slight_smile:

This is what I have:

hjson:

{
  type: 'ifExtFileExists',
  module : 'ifExtFileExists',
  action : 'ifExtFileExists',
  groupTitle : 'My Modules',
  groupIcon : 'fas fa-lg fa-project-diagram comp-images',
  title : 'If ext. file exists',
  icon : 'fas fa-lg fa-question comp-images',
  dataPickObject: true,
  properties : [
    {
      group: 'If ext. file exists',
      variables: [
        { name: 'name', optionName: 'name', title: 'Name', type: 'text', required: true, defaultValue: 'fileExists'},
        { name: 'path', optionName: 'path', title: 'File Path', type: 'file', required: true, defaultValue: '', serverDataBindings: true,
          help: 'Please enter your File Path'},
        { name: 'output', optionName: 'output', title: 'Output', type: 'boolean', defaultValue: false }
      ]
    }
  ]
}

js:

const fs = require('fs-extra');

exports.ifExtFileExists = async function (options) {
    let path = this.parseRequired(options.path, 'string', 'fs.exists: path is required.');

    if (fs.existsSync(path)) {
        if (options.then) this.exec(options.then, true);
        return true;
    } else {
        if (options.else) this.exec(options.else, true);
        return false;
    }
}

This is what I get:

image

This is what I need:

image

Community Page
Last updated: