From bcd1357a18ead6c7bb7c9f4868a99ded0adb54ea Mon Sep 17 00:00:00 2001 From: simatec Date: Tue, 3 Dec 2024 09:42:15 +0100 Subject: [PATCH] (simatec) Code Fix --- docs/oAuthService.js | 1 - eslint.config.mjs | 10 ++++---- lib/dropboxLib.js | 2 -- lib/execute.js | 1 - lib/googleDriveLib.js | 5 ---- lib/list/onedrive.js | 5 ---- lib/list/webdav.js | 4 --- lib/scripts/42-javascripts.js | 1 - lib/scripts/55-onedrive.js | 4 --- lib/scripts/65-webdav.js | 4 --- lib/scripts/78-clean.js | 1 - lib/tools.js | 2 +- main.js | 46 +++++++++++++++++------------------ 13 files changed, 29 insertions(+), 57 deletions(-) diff --git a/docs/oAuthService.js b/docs/oAuthService.js index f1f9879e..e9e100d5 100644 --- a/docs/oAuthService.js +++ b/docs/oAuthService.js @@ -20,7 +20,6 @@ const CLIENT_SECRET = process.env.CLIENT_SECRET; // Google oAuth2 APP client sec const REDIRECT_URL = ['urn:ietf:wg:oauth:2.0:oob']; const SCOPES = ['https://www.googleapis.com/auth/drive.file']; -// @ts-ignore const oAuth2Client = new OAuth2Client(CLIENT_ID, CLIENT_SECRET, REDIRECT_URL); exports.handler = async (event) => { diff --git a/eslint.config.mjs b/eslint.config.mjs index 60e5fc2e..92e9c2bd 100644 --- a/eslint.config.mjs +++ b/eslint.config.mjs @@ -35,9 +35,6 @@ export default [ // as this improves maintainability. jsdoc warnings will not block buiuld process. rules: { 'jsdoc/require-jsdoc': 'off', - 'jsdoc/require-param': 'off', - '@typescript-eslint/ban-ts-comment': 'off', - '@typescript-eslint/no-require-imports': 'off', 'no-async-promise-executor': 'off', 'prettier/prettier': 'off', '@typescript-eslint/no-unused-vars': 'off', @@ -45,10 +42,13 @@ export default [ 'curly': 'off', 'jsdoc/require-returns-description': 'off', 'no-else-return': 'off', - 'jsdoc/no-types': 'off', 'no-case-declarations': 'off', - 'jsdoc/tag-lines': 'off', 'no-useless-escape': 'off', + //'jsdoc/require-param': 'off', + //'@typescript-eslint/ban-ts-comment': 'off', + //'@typescript-eslint/no-require-imports': 'off', + //'jsdoc/no-types': 'off', + //'jsdoc/tag-lines': 'off', }, }, ]; diff --git a/lib/dropboxLib.js b/lib/dropboxLib.js index e32926c1..d3e1414a 100644 --- a/lib/dropboxLib.js +++ b/lib/dropboxLib.js @@ -221,7 +221,6 @@ class dropbox { log.error(); (`sessionAppend error: ${JSON.stringify(err)}`); reject(err); } - // @ts-ignore resolve(); }); }); @@ -249,7 +248,6 @@ class dropbox { reject(err); } }); - // @ts-ignore resolve(); }); } diff --git a/lib/execute.js b/lib/execute.js index f1e46478..b942189e 100644 --- a/lib/execute.js +++ b/lib/execute.js @@ -561,7 +561,6 @@ function executeScripts(adapter, config, callback, scripts, code) { callback && callback(); } -// @ts-ignore if (typeof module !== 'undefined' && module.parent) { module.exports = executeScripts; } \ No newline at end of file diff --git a/lib/googleDriveLib.js b/lib/googleDriveLib.js index 905f65c3..ed2cbe06 100644 --- a/lib/googleDriveLib.js +++ b/lib/googleDriveLib.js @@ -25,7 +25,6 @@ class GoogleDrive { } _authorize() { - // @ts-ignore if (this.oAuth2Client.credentials.access_token && Date.now() > this.oAuth2Client.credentials.expiry_date) { let url = OAUTH_URL; if (!this.newToken) { @@ -57,7 +56,6 @@ class GoogleDrive { _getDrive() { this.drive = this.drive || new google.drive_v3.Drive({ - // @ts-ignore version: 'v3', auth: this.oAuth2Client, }); @@ -303,7 +301,6 @@ class GoogleDrive { return reject(err); } res.data - // @ts-ignore .on('end', () => resolve()) .on('error', err => reject(err)) .pipe(dest); @@ -315,11 +312,9 @@ class GoogleDrive { } } -// @ts-ignore if (module.parent) { module.exports = GoogleDrive; } else { - // @ts-ignore const token = require('./test'); const gDrive = new GoogleDrive(token); diff --git a/lib/list/onedrive.js b/lib/list/onedrive.js index baed9252..2962fab9 100644 --- a/lib/list/onedrive.js +++ b/lib/list/onedrive.js @@ -37,7 +37,6 @@ async function list(restoreSource, options, types, log, callback) { dir = dir.substring(1); } - // @ts-ignore oneDriveAPI.items .getMetadata({ accessToken: od_accessToken, @@ -45,7 +44,6 @@ async function list(restoreSource, options, types, log, callback) { }) .then((res) => { if (res && res.id) { - // @ts-ignore oneDriveAPI.items .listChildren({ accessToken: od_accessToken, @@ -120,7 +118,6 @@ async function getFile(options, fileName, toStoreName, log, callback) { dir = dir.substring(1); } - // @ts-ignore oneDriveAPI.items .getMetadata({ accessToken: od_accessToken, @@ -128,7 +125,6 @@ async function getFile(options, fileName, toStoreName, log, callback) { }) .then((res) => { if (res && res.id) { - // @ts-ignore oneDriveAPI.items .listChildren({ accessToken: od_accessToken, @@ -152,7 +148,6 @@ async function getFile(options, fileName, toStoreName, log, callback) { callback && callback(result); }); - // @ts-ignore const promise = oneDriveAPI.items.download({ accessToken: od_accessToken, itemId: result[0].id, diff --git a/lib/list/webdav.js b/lib/list/webdav.js index d1b73444..3a6b3211 100644 --- a/lib/list/webdav.js +++ b/lib/list/webdav.js @@ -44,18 +44,15 @@ async function list(restoreSource, options, types, log, callback) { } try { - // @ts-ignore client .getDirectoryContents(dir) .then(contents => { if (contents) { - // @ts-ignore contents = contents.map(file => { return { path: file.filename, name: file.filename.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'); const files = {}; - // @ts-ignore contents.forEach(file => { const type = file.name.split('_')[0]; files[type] = files[type] || []; @@ -138,7 +135,6 @@ async function getFile(options, fileName, toStoreName, log, callback) { log.debug(`WebDAV: Download of "${fileName}" finish`); callback && callback(); }); - // @ts-ignore client .createReadStream(fileName) .pipe(writeStream); diff --git a/lib/scripts/42-javascripts.js b/lib/scripts/42-javascripts.js index 783307bb..8802c24a 100644 --- a/lib/scripts/42-javascripts.js +++ b/lib/scripts/42-javascripts.js @@ -9,7 +9,6 @@ let timerLog; async function sleep(ms) { return new Promise(async (resolve) => { - // @ts-ignore timerLog = setTimeout(async () => resolve(), ms); }); } diff --git a/lib/scripts/55-onedrive.js b/lib/scripts/55-onedrive.js index 2ae12e53..2b6a972d 100644 --- a/lib/scripts/55-onedrive.js +++ b/lib/scripts/55-onedrive.js @@ -24,7 +24,6 @@ function copyFiles(od_accessToken, dir, fileNames, log, errors, callback) { err && log.error(`readStream Onedrive: ${err}`); }); - // @ts-ignore oneDriveAPI.items .uploadSession({ accessToken: od_accessToken, @@ -64,7 +63,6 @@ function deleteFiles(od_accessToken, fileIds, fileNames, log, errors, callback) log.debug(`Onedrive: delete ${fileName} with Id: ${fileId}`); - // @ts-ignore oneDriveAPI.items .delete({ accessToken: od_accessToken, @@ -85,7 +83,6 @@ function cleanFiles(od_accessToken, options, dir, names, num, log, errors, callb return callback && callback(); } - // @ts-ignore oneDriveAPI.items .getMetadata({ accessToken: od_accessToken, @@ -93,7 +90,6 @@ function cleanFiles(od_accessToken, options, dir, names, num, log, errors, callb }) .then((res) => { if (res && res.id) { - // @ts-ignore oneDriveAPI.items .listChildren({ accessToken: od_accessToken, diff --git a/lib/scripts/65-webdav.js b/lib/scripts/65-webdav.js index 9b559dab..b0976f55 100644 --- a/lib/scripts/65-webdav.js +++ b/lib/scripts/65-webdav.js @@ -28,7 +28,6 @@ async function copyFiles(client, dir, fileNames, log, errors, callback) { contentLength: fileContent.length, }) .then(() => { - // @ts-ignore fileContent = null; setImmediate(copyFiles, client, dir, fileNames, log, errors, callback); }); @@ -137,9 +136,7 @@ async function command(options, log, callback) { callback && callback(); } try { - // @ts-ignore if (await client.exists(dir) === false) { - // @ts-ignore await client.createDirectory(dir); } } catch (e) { @@ -149,7 +146,6 @@ async function command(options, log, callback) { } try { - // @ts-ignore client .getDirectoryContents(dir) .then(contents => { diff --git a/lib/scripts/78-clean.js b/lib/scripts/78-clean.js index 829f313d..9b0ee526 100644 --- a/lib/scripts/78-clean.js +++ b/lib/scripts/78-clean.js @@ -86,7 +86,6 @@ function command(options, log, callback) { log.warn('No older backup files are deleted, because this backup was started manually'); } - // @ts-ignore cleanFiles(dir, options, options.context.types, options.deleteBackupAfter, log, options.context.errors, err => { if (err) { log.error(err); diff --git a/lib/tools.js b/lib/tools.js index af2665cc..7205a117 100644 --- a/lib/tools.js +++ b/lib/tools.js @@ -35,7 +35,7 @@ function copyFile(source, target, cb) { /** * looks for iobroker home folder * - * @returns {string} + * @returns */ function getIobDir() { const utils = require('@iobroker/adapter-core'); diff --git a/main.js b/main.js index 23f16793..bc9e9ebf 100644 --- a/main.js +++ b/main.js @@ -33,14 +33,15 @@ const backupConfig = {}; const backupTimeSchedules = []; // Array for Backup Times let taskRunning = false; -// @ts-ignore + const bashDir = path.join(utils.getAbsoluteDefaultDataDir(), adapterName).replace(/\\/g, '/'); /** * Decrypt the password/value with given key - * @param {string} key - Secret key - * @param {string} value - value to decrypt - * @returns {string} + * + * @param key - Secret key + * @param value - value to decrypt + * @returns */ function decrypt(key, value) { let result = ''; @@ -266,7 +267,7 @@ function startAdapter(options) { res => obj.callback && adapter.sendTo(obj.from, obj.command, res, obj.callback), ); } else if (obj.callback) { - // @ts-ignore + obj.callback({ error: 'Invalid parameters' }); } break; @@ -293,7 +294,7 @@ function startAdapter(options) { adapter.sendTo(obj.from, obj.command, { e }, obj.callback); } } else if (obj.callback) { - // @ts-ignore + obj.callback({ error: 'Invalid parameters' }); } break; @@ -340,7 +341,7 @@ function startAdapter(options) { } } } else if (obj.callback) { - // @ts-ignore + obj.callback({ error: 'Invalid parameters' }); } break; @@ -353,7 +354,7 @@ function startAdapter(options) { adapter.log.debug('Upload finished...'); adapter.sendTo(obj.from, obj.command, { serverClose: true }, obj.callback); } else if (obj.callback) { - // @ts-ignore + obj.callback({ error: 'Invalid parameters' }); } break; @@ -381,7 +382,7 @@ function startAdapter(options) { let dbInfo = false; if (fs.existsSync('/opt/scripts/.docker_config/.thisisdocker')) { // Docker Image Support >= 5.2.0 - // @ts-ignore + systemInfo = 'docker'; if (fs.existsSync('/opt/scripts/.docker_config/.backitup')) { @@ -391,7 +392,7 @@ function startAdapter(options) { const isWin = process.platform.startsWith('win'); if (isWin) { - // @ts-ignore + systemInfo = 'win'; } } @@ -1510,7 +1511,7 @@ function detectLatestBackupFile(adapter) { .forEach(f => { filenumbers++; const date = getName(f.name, filenumbers, storage); - // @ts-ignore + if (!file || file.date < date) { file = f; file.date = date; @@ -1529,17 +1530,17 @@ function detectLatestBackupFile(adapter) { // find the newest file between storages - // @ts-ignore + Promise.all(promises) .then(results => { results = results.filter(f => f); let file; if (results.length) { results.sort((a, b) => { - // @ts-ignore + if (a.date > b.date) { return 1; - // @ts-ignore + } else if (a.date < b.date) { return -1; } else { @@ -1547,10 +1548,10 @@ function detectLatestBackupFile(adapter) { } }); file = results[0]; - // @ts-ignore + if (file.date !== undefined) { try { - // @ts-ignore + file.date = file.date.toISOString(); } catch (e) { adapter.log.warn(`No backup file date was found: ${e}`); @@ -1561,14 +1562,14 @@ function detectLatestBackupFile(adapter) { } // this information will be used by admin at the first start if some backup was detected and we can restore from it instead of new configuration adapter.setState('info.latestBackup', file ? JSON.stringify(file) : '', true); - // @ts-ignore + adapter.log.debug(file ? `detect last backup file: ${file.name}` : 'No backup file was found'); - // @ts-ignore + results = null; }); promises = null; - // @ts-ignore + stores = null; } catch (e) { @@ -1899,11 +1900,11 @@ async function renewOnedriveToken() { if (adapter.config.onedriveLastTokenRenew != '') { const lastRenew = new Date(adapter.config.onedriveLastTokenRenew); - // @ts-ignore + diffDays = parseInt((currentDay - lastRenew) / (1000 * 60 * 60 * 24)); //day difference } - // @ts-ignore + if (diffDays >= 30 || adapter.config.onedriveLastTokenRenew == '') { adapter.log.debug('Renew Onedrive Refresh-Token'); @@ -1921,7 +1922,7 @@ async function renewOnedriveToken() { adapter.registerNotification('backitup', 'onedriveWarn', err ? JSON.stringify(err) : 'An update of the Onedrive refresh token has failed. Please check your system!'); }); } else { - // @ts-ignore + adapter.log.debug(`Renew Onedrive Refresh-Token in ${30 - diffDays} days`); } } @@ -1964,7 +1965,6 @@ async function main(adapter) { adapter.subscribeStates('oneClick.*'); } // If started as allInOne/compact mode => return function to create instance -// @ts-ignore if (module && module.parent) { module.exports = startAdapter; } else {