From 152c38e76d60275dc1f917050b7edaec44a293ac Mon Sep 17 00:00:00 2001 From: simatec Date: Tue, 3 Dec 2024 09:09:24 +0100 Subject: [PATCH] (simatec) Code fix --- lib/list/cifs.js | 2 +- lib/list/dropbox.js | 18 +++++++++--------- lib/list/ftp.js | 20 ++++++++++---------- lib/oneDriveLib.js | 10 +++++----- lib/scripts/01-mount.js | 4 ++-- lib/scripts/75-googledrive.js | 2 +- lib/scripts/94-umount.js | 2 +- 7 files changed, 29 insertions(+), 29 deletions(-) diff --git a/lib/list/cifs.js b/lib/list/cifs.js index e81e8be5..317966c0 100644 --- a/lib/list/cifs.js +++ b/lib/list/cifs.js @@ -168,7 +168,7 @@ function mount(options, log, callback) { log.debug(`cifs-mount command: "${options.sudo ? 'sudo mount' : 'mount'} -t cifs -o ${options.user ? `username=${options.user},password=****` : ''}${options.cifsDomain ? `,domain=${options.cifsDomain}` : ''}${options.clientInodes ? ',noserverino' : ''}${options.cacheLoose ? ',cache=loose' : ''},rw,forceuid,uid=iobroker,forcegid,gid=iobroker,file_mode=0777,dir_mode=0777 ${options.mount}${dir} ${backupDir}"`); child_process.exec(`${options.sudo ? 'sudo mount' : 'mount'} -t cifs -o ${options.user ? `username=${options.user},password=${options.pass}` : ''}${options.cifsDomain ? `,domain=${options.cifsDomain}` : ''}${options.clientInodes ? ',noserverino' : ''}${options.cacheLoose ? ',cache=loose' : ''},rw,forceuid,uid=iobroker,forcegid,gid=iobroker,file_mode=0777,dir_mode=0777 ${options.mount}${dir} ${backupDir}`, (error, stdout, stderr) => { if (error) { - let errLog = '' + error; + let errLog = `${error}`; try { const formatPass = options.pass.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&'); errLog = errLog.replace(new RegExp(formatPass, 'g'), "****"); diff --git a/lib/list/dropbox.js b/lib/list/dropbox.js index d2bb8d13..7c1a2407 100644 --- a/lib/list/dropbox.js +++ b/lib/list/dropbox.js @@ -19,7 +19,7 @@ async function list(restoreSource, options, types, log, callback) { db_dropboxAccessJson = options.dropboxAccessJson !== undefined ? options.dropboxAccessJson : options.dropbox && options.dropbox.dropboxAccessJson !== undefined ? options.dropbox.dropboxAccessJson : ''; const dropbox = new Dropbox(); - db_accessToken = await dropbox.getToken(db_dropboxAccessJson, log).catch(err => log.warn('Dropbox Token: ' + err)); + db_accessToken = await dropbox.getToken(db_dropboxAccessJson, log).catch(err => log.warn(`Dropbox Token: ${err}`)); } else if (db_dropboxTokenType == 'custom') { db_accessToken = options.accessToken !== undefined ? options.accessToken : options.dropbox && options.dropbox.accessToken !== undefined ? options.dropbox.accessToken : ''; } @@ -35,7 +35,7 @@ async function list(restoreSource, options, types, log, callback) { } if (!dir || dir[0] !== '/') { - dir = '/' + (dir || ''); + dir = `/${dir || ''}`; } try { @@ -45,7 +45,7 @@ async function list(restoreSource, options, types, log, callback) { path: dir.replace(/^\/$/, '') }, }, (err, result) => { - err && err.error_summary && log.error('Dropbox: ' + JSON.stringify(err.error_summary)); + err && err.error_summary && log.error(`Dropbox: ${JSON.stringify(err.error_summary)}`); if (result && result.entries) { result = result.entries.map(file => { @@ -86,7 +86,7 @@ async function getFile(options, fileName, toStoreName, log, callback) { db_dropboxAccessJson = options.dropboxAccessJson !== undefined ? options.dropboxAccessJson : options.dropbox && options.dropbox.dropboxAccessJson !== undefined ? options.dropbox.dropboxAccessJson : ''; const dropbox = new Dropbox(); - db_accessToken = await dropbox.getToken(db_dropboxAccessJson, log).catch(err => log.warn('Dropbox Token: ' + err)); + db_accessToken = await dropbox.getToken(db_dropboxAccessJson, log).catch(err => log.warn(`Dropbox Token: ${err}`)); } else if (db_dropboxTokenType == 'custom') { db_accessToken = options.accessToken !== undefined ? options.accessToken : options.dropbox && options.dropbox.accessToken !== undefined ? options.dropbox.accessToken : ''; } @@ -103,15 +103,15 @@ async function getFile(options, fileName, toStoreName, log, callback) { } if (!dir || dir[0] !== '/') { - dir = '/' + (dir || ''); + dir = `/${dir || ''}`; } try { - log.debug('Dropbox: Download of "' + fileName + '" started'); + log.debug(`Dropbox: Download of "${fileName}" started`); const writeStream = fs.createWriteStream(toStoreName); writeStream.on('error', err => { - err && log.error('Dropbox: ' + err); + err && log.error(`Dropbox: ${err}`); callback && callback(err); callback = null; }); @@ -122,8 +122,8 @@ async function getFile(options, fileName, toStoreName, log, callback) { path: path.join(dir.replace(/^\/$/, ''), onlyFileName).replace(/\\/g, '/') }, }, (err, result, response) => { - err && log.error('Dropbox: ' + err); - !err && log.debug('Dropbox: Download of "' + fileName + '" done'); + err && log.error(`Dropbox: ${err}`); + !err && log.debug(`Dropbox: Download of "${fileName}" done`); callback && callback(err); callback = null; }) diff --git a/lib/list/ftp.js b/lib/list/ftp.js index 9dbbb044..c9684a86 100644 --- a/lib/list/ftp.js +++ b/lib/list/ftp.js @@ -24,14 +24,14 @@ function list(restoreSource, options, types, log, callback) { } if (!dir || dir[0] !== '/') { - dir = '/' + (dir || ''); + dir = `/${dir || ''}`; } client.on('ready', () => { log.debug('FTP: connected.'); client.list(dir, (err, result) => { if (err) { - log.error('FTP: ' + err); + log.error(`FTP: ${err}`); } client.end(); if (result && result.length) { @@ -40,7 +40,7 @@ function list(restoreSource, options, types, log, callback) { return { path: file.name, name: file.name.replace(/\\/g, '/').split('/').pop(), size: file.size } }).filter(file => (types.indexOf(file.name.split('_')[0]) !== -1 || types.indexOf(file.name.split('.')[0]) !== -1) && file.name.split('.').pop() == 'gz'); } catch (e) { - log.error('FTP: error on ftp list: ' + e + ' please check the ftp config!!'); + log.error(`FTP: error on ftp list: ${e} please check the ftp config!!`); } const files = {}; @@ -51,7 +51,7 @@ function list(restoreSource, options, types, log, callback) { files[type].push(file); }); } catch (e) { - log.error('FTP: Files error: ' + e + ' please check the ftp config and try again!!'); + log.error(`FTP: Files error: ${e} please check the ftp config and try again!!`); } callback && callback(null, files, 'ftp'); @@ -106,19 +106,19 @@ function getFile(options, fileName, toStoreName, log, callback) { } if (!dir || dir[0] !== '/') { - dir = '/' + (dir || ''); + dir = `/${dir || ''}`; } client.on('ready', () => { log.debug('FTP: connected.'); - log.debug('FTP: Get file: ' + dir + '/' + fileName); - client.get(dir + '/' + fileName, (err, stream) => { + log.debug(`FTP: Get file: ${dir}/${fileName}`); + client.get(`${dir}/${fileName}`, (err, stream) => { if (err) { try { client.end(); } catch (e) { // ignore } - log.error('FTP: ' + err); + log.error(`FTP: ${err}`); if (callback) { callback(err); callback = null; @@ -135,7 +135,7 @@ function getFile(options, fileName, toStoreName, log, callback) { }); const writeStream = fs.createWriteStream(toStoreName); writeStream.on('error', err => { - log.error('FTP: ' + err); + log.error(`FTP: ${err}`); if (callback) { callback(); callback = null; @@ -144,7 +144,7 @@ function getFile(options, fileName, toStoreName, log, callback) { stream.pipe(writeStream); } catch (err) { - log.error('FTP: ' + err); + log.error(`FTP: ${err}`); if (callback) { callback(err); callback = null; diff --git a/lib/oneDriveLib.js b/lib/oneDriveLib.js index c4844999..2b65ff97 100644 --- a/lib/oneDriveLib.js +++ b/lib/oneDriveLib.js @@ -32,7 +32,7 @@ class onedrive { reject(); } } catch (e) { - log.warn('getAuthorizeUrl Onedrive: ' + e); + log.warn(`getAuthorizeUrl Onedrive: ${e}`); reject(); } }); @@ -56,7 +56,7 @@ class onedrive { reject(); } } catch (e) { - log.warn('getClientID Onedrive: ' + e); + log.warn(`getClientID Onedrive: ${e}`); reject(); } }); @@ -78,7 +78,7 @@ class onedrive { reject(); } } catch (e) { - log.warn('getRefreshToken Onedrive: ' + e); + log.warn(`getRefreshToken Onedrive: ${e}`); reject(); } }); @@ -100,7 +100,7 @@ class onedrive { reject(); } } catch (e) { - log.warn('getToken Onedrive: ' + e); + log.warn(`getToken Onedrive: ${e}`); reject(); } }); @@ -122,7 +122,7 @@ class onedrive { reject(); } } catch (e) { - log.warn('refresh_token Onedrive: ' + e); + log.warn(`refresh_token Onedrive: ${e}`); reject(); } }); diff --git a/lib/scripts/01-mount.js b/lib/scripts/01-mount.js index 67fdf1fd..b31a3be1 100644 --- a/lib/scripts/01-mount.js +++ b/lib/scripts/01-mount.js @@ -90,7 +90,7 @@ function command(options, log, callback) { log.debug(`cifs-mount command: "${options.sudo ? 'sudo mount' : 'mount'} -t cifs -o ${options.user ? `username=${options.user},password=****` : ''}${options.cifsDomain ? `,domain=${options.cifsDomain}` : ''}${options.clientInodes ? ',noserverino' : ''}${options.cacheLoose ? ',cache=loose' : ''},rw,forceuid,uid=iobroker,forcegid,gid=iobroker,file_mode=0777,dir_mode=0777 ${options.mount}${options.dir} ${options.backupDir}"`); child_process.exec(`${options.sudo ? 'sudo mount' : 'mount'} -t cifs -o ${options.user ? `username=${options.user},password=${options.pass}` : ''}${options.cifsDomain ? `,domain=${options.cifsDomain}` : ''}${options.clientInodes ? ',noserverino' : ''}${options.cacheLoose ? ',cache=loose' : ''},rw,forceuid,uid=iobroker,forcegid,gid=iobroker,file_mode=0777,dir_mode=0777 ${options.mount}${options.dir} ${options.backupDir}`, (error, stdout, stderr) => { if (error) { - let errLog = '' + error; + let errLog = `${error}`; try { const formatPass = options.pass.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&'); errLog = errLog.replace(new RegExp(formatPass, 'g'), "****"); @@ -114,7 +114,7 @@ function command(options, log, callback) { } else { log.debug('mount successfully completed'); options.context.done.push('mount'); - fs.writeFileSync(options.fileDir + '/.mount', options.mountType); + fs.writeFileSync(`${options.fileDir}/.mount`, options.mountType); callback && callback(null, stdout); } }); diff --git a/lib/scripts/75-googledrive.js b/lib/scripts/75-googledrive.js index 8d05d86b..29078a20 100644 --- a/lib/scripts/75-googledrive.js +++ b/lib/scripts/75-googledrive.js @@ -98,7 +98,7 @@ function cleanFiles(gDrive, options, dir, names, num, log, errors, callback) { } }) .catch(err => { - log.error('Google Drive: ' + err); + log.error(`Google Drive: ${err}`); callback && callback(err); }); } diff --git a/lib/scripts/94-umount.js b/lib/scripts/94-umount.js index 9caafd2a..dfbec240 100644 --- a/lib/scripts/94-umount.js +++ b/lib/scripts/94-umount.js @@ -8,7 +8,7 @@ function command(options, log, callback) { if (options.mountType === 'CIFS' || options.mountType === 'NFS' || options.mountType === 'Expert') { const child_process = require('node:child_process'); - if (fs.existsSync(options.fileDir + '/.mount')) { + if (fs.existsSync(`${options.fileDir}/.mount`)) { child_process.exec(`mount | grep -o "${options.backupDir}"`, (error, stdout, stderr) => { if (stdout.includes(options.backupDir)) { log.debug('mount active, umount is started ...');