Skip to content

Commit

Permalink
Code tidy based on DeepScan results
Browse files Browse the repository at this point in the history
  • Loading branch information
TotallyInformation committed Jan 1, 2024
1 parent 88543da commit 9021245
Show file tree
Hide file tree
Showing 5 changed files with 113 additions and 127 deletions.
212 changes: 106 additions & 106 deletions nodes/libs/user-apis.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ const express = require('express')

const UserRouter = express.Router({ mergeParams: true }) // eslint-disable-line new-cap

const errUibRootFldr = new Error('uib.rootFolder is null')
// const errUibRootFldr = new Error('uib.rootFolder is null')

const config = {}

Expand All @@ -47,123 +47,123 @@ const config = {}
* @param {string} params.url The uibuilder url to check
* @returns {{statusMessage: string, status: number}} Status message
*/
function chkParamUrl(params) {
const res = { 'statusMessage': '', 'status': 0 }

// We have to have a url to work with - the url defines the start folder
if ( params.url === undefined ) {
res.statusMessage = 'url parameter not provided'
res.status = 500
return res
}

// Trim the url
params.url = params.url.trim()

// URL must not exceed 20 characters
if ( params.url.length > 20 ) {
res.statusMessage = `url parameter is too long. Max 20 characters: ${params.url}`
res.status = 500
return res
}

// URL must be more than 0 characters
if ( params.url.length < 1 ) {
res.statusMessage = 'url parameter is empty, please provide a value'
res.status = 500
return res
}

// URL cannot contain .. to prevent escaping sub-folder structure
if ( params.url.includes('..') ) {
res.statusMessage = `url parameter may not contain "..": ${params.url}`
res.status = 500
return res
}

// Actually, since uib auto-creates folder if not exists, this just gets in the way - // Does this url have a matching instance root folder?
// if ( ! fs.existsSync(path.join(uib.rootFolder, params.url)) ) {
// res.statusMessage = `url does not have a matching instance root folder. url='${params.url}', Master root folder='${uib.rootFolder}'`
// res.status = 500
// return res
// }

return res
} // ---- End of fn chkParamUrl ---- //
// function chkParamUrl(params) {
// const res = { 'statusMessage': '', 'status': 0 }

// // We have to have a url to work with - the url defines the start folder
// if ( params.url === undefined ) {
// res.statusMessage = 'url parameter not provided'
// res.status = 500
// return res
// }

// // Trim the url
// params.url = params.url.trim()

// // URL must not exceed 20 characters
// if ( params.url.length > 20 ) {
// res.statusMessage = `url parameter is too long. Max 20 characters: ${params.url}`
// res.status = 500
// return res
// }

// // URL must be more than 0 characters
// if ( params.url.length < 1 ) {
// res.statusMessage = 'url parameter is empty, please provide a value'
// res.status = 500
// return res
// }

// // URL cannot contain .. to prevent escaping sub-folder structure
// if ( params.url.includes('..') ) {
// res.statusMessage = `url parameter may not contain "..": ${params.url}`
// res.status = 500
// return res
// }

// // Actually, since uib auto-creates folder if not exists, this just gets in the way - // Does this url have a matching instance root folder?
// // if ( ! fs.existsSync(path.join(uib.rootFolder, params.url)) ) {
// // res.statusMessage = `url does not have a matching instance root folder. url='${params.url}', Master root folder='${uib.rootFolder}'`
// // res.status = 500
// // return res
// // }

// return res
// } // ---- End of fn chkParamUrl ---- //

/** Validate fname (filename) query parameter
* @param {object} params The GET (res.query) or POST (res.body) parameters
* @param {string} params.fname The uibuilder url to check
* @returns {{statusMessage: string, status: number}} Status message
*/
function chkParamFname(params) {
const res = { 'statusMessage': '', 'status': 0 }
const fname = params.fname

// We have to have an fname (file name) to work with
if ( fname === undefined ) {
res.statusMessage = 'file name not provided'
res.status = 500
return res
}
// Blank file name probably means no files available so we will ignore
if ( fname === '' ) {
res.statusMessage = 'file name cannot be blank'
res.status = 500
return res
}
// fname must not exceed 255 characters
if ( fname.length > 255 ) {
res.statusMessage = `file name is too long. Max 255 characters: ${params.fname}`
res.status = 500
return res
}
// fname cannot contain .. to prevent escaping sub-folder structure
if ( fname.includes('..') ) {
res.statusMessage = `file name may not contain "..": ${params.fname}`
res.status = 500
return res
}

return res
} // ---- End of fn chkParamFname ---- //
// function chkParamFname(params) {
// const res = { 'statusMessage': '', 'status': 0 }
// const fname = params.fname

// // We have to have an fname (file name) to work with
// if ( fname === undefined ) {
// res.statusMessage = 'file name not provided'
// res.status = 500
// return res
// }
// // Blank file name probably means no files available so we will ignore
// if ( fname === '' ) {
// res.statusMessage = 'file name cannot be blank'
// res.status = 500
// return res
// }
// // fname must not exceed 255 characters
// if ( fname.length > 255 ) {
// res.statusMessage = `file name is too long. Max 255 characters: ${params.fname}`
// res.status = 500
// return res
// }
// // fname cannot contain .. to prevent escaping sub-folder structure
// if ( fname.includes('..') ) {
// res.statusMessage = `file name may not contain "..": ${params.fname}`
// res.status = 500
// return res
// }

// return res
// } // ---- End of fn chkParamFname ---- //

/** Validate folder query parameter
* @param {object} params The GET (res.query) or POST (res.body) parameters
* @param {string} params.folder The uibuilder url to check
* @returns {{statusMessage: string, status: number}} Status message
*/
function chkParamFldr(params) {
const res = { 'statusMessage': '', 'status': 0 }
const folder = params.folder

// we have to have a folder name
if ( folder === undefined ) {
res.statusMessage = 'folder name not provided'
res.status = 500
return res
}
// folder name must be >0 in length
if ( folder === '' ) {
res.statusMessage = 'folder name cannot be blank'
res.status = 500
return res
}
// folder name must not exceed 255 characters
if ( folder.length > 255 ) {
res.statusMessage = `folder name is too long. Max 255 characters: ${folder}`
res.status = 500
return res
}
// folder name cannot contain .. to prevent escaping sub-folder structure
if ( folder.includes('..') ) {
res.statusMessage = `folder name may not contain "..": ${folder}`
res.status = 500
return res
}

return res
} // ---- End of fn chkParamFldr ---- //
// function chkParamFldr(params) {
// const res = { 'statusMessage': '', 'status': 0 }
// const folder = params.folder

// // we have to have a folder name
// if ( folder === undefined ) {
// res.statusMessage = 'folder name not provided'
// res.status = 500
// return res
// }
// // folder name must be >0 in length
// if ( folder === '' ) {
// res.statusMessage = 'folder name cannot be blank'
// res.status = 500
// return res
// }
// // folder name must not exceed 255 characters
// if ( folder.length > 255 ) {
// res.statusMessage = `folder name is too long. Max 255 characters: ${folder}`
// res.status = 500
// return res
// }
// // folder name cannot contain .. to prevent escaping sub-folder structure
// if ( folder.includes('..') ) {
// res.statusMessage = `folder name may not contain "..": ${folder}`
// res.status = 500
// return res
// }

// return res
// } // ---- End of fn chkParamFldr ---- //

//#endregion === End of API validation functions === //

Expand Down
2 changes: 1 addition & 1 deletion resources/uib-cache.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
// RED._debug({topic: 'RED.settings', payload:RED.settings})

const uibuilder = window['uibuilder']
const log = uibuilder.log
// const log = uibuilder.log

/** Module name must match this nodes html file @constant {string} moduleName */
const moduleName = 'uib-cache'
Expand Down
15 changes: 4 additions & 11 deletions resources/uib-element.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,11 @@
// RED._debug({topic: 'RED.settings', payload:RED.settings})

const uibuilder = window['uibuilder']
const log = uibuilder.log
// const log = uibuilder.log

/** Module name must match this nodes html file @constant {string} moduleName */
const moduleName = 'uib-element'

/** Node's label @constant {string} paletteCategory */
const nodeLabel = moduleName
/** Node's palette category @constant {string} paletteCategory */
const paletteCategory = window['uibuilder'].paletteCategory
/** Node's background color @constant {string} paletteColor */
const paletteColor = 'var(--uib-node-colour)' // '#E6E0F8'

/** Element Types definitions */
const elTypes = {
table: {
Expand Down Expand Up @@ -268,8 +261,8 @@
function onEditPrepare(node) {
// Initial config data
if (!node.confData) node.confData = {}
if (!node.parent || node.parent === '') $('#node-input-parent').val('body')
if (!node.position || node.position === '') {
if (node.parent === '' || !node.parent) $('#node-input-parent').val('body')
if (node.position === '' || !node.position ) {
$('#node-input-position').val('last')
node.position = 'last'
}
Expand Down Expand Up @@ -414,7 +407,7 @@
docFrag = templ.content.cloneNode(true)
$('#el-tab-conf').append(docFrag)
// Get any required functions for this type from the template (append runs the script tags immediately)
const confFns = window['uibElementConfigFns']
// const confFns = window['uibElementConfigFns']
// console.log('confFns', confFns.type, confFns)
// Re-constitute node.conf properties and values to the conf tab
// TODO Deal with select tags
Expand Down
2 changes: 1 addition & 1 deletion resources/uib-save.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
// RED._debug({topic: 'RED.settings', payload:RED.settings})

const uibuilder = window['uibuilder']
const log = uibuilder.log
// const log = uibuilder.log

/** Module name must match this nodes html file @constant {string} moduleName */
const moduleName = 'uib-save'
Expand Down
9 changes: 1 addition & 8 deletions resources/uib-update.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,11 @@
// RED._debug({topic: 'RED.settings', payload:RED.settings})

const uibuilder = window['uibuilder']
const log = uibuilder.log
// const log = uibuilder.log

/** Module name must match this nodes html file @constant {string} moduleName */
const moduleName = 'uib-update'

/** Node's label @constant {string} paletteCategory */
const nodeLabel = moduleName
/** Node's palette category @constant {string} paletteCategory */
const paletteCategory = window['uibuilder'].paletteCategory
/** Node's background color @constant {string} paletteColor */
const paletteColor = 'var(--uib-node-colour)' // '#E6E0F8'

const inputTypes = [
'msg', 'flow', 'global',
'str', 'num', 'bool', 'date',
Expand Down

0 comments on commit 9021245

Please sign in to comment.