Skip to content

Commit

Permalink
(simatec) Code Fix
Browse files Browse the repository at this point in the history
  • Loading branch information
simatec committed Dec 2, 2024
1 parent 4fecbf0 commit d3b8336
Show file tree
Hide file tree
Showing 33 changed files with 218 additions and 190 deletions.
6 changes: 3 additions & 3 deletions admin/asset-manifest.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
{
"files": {
"main.css": "./static/css/main.bd1167d4.css",
"main.js": "./static/js/main.db6c6622.js",
"main.js": "./static/js/main.b32c1377.js",
"static/js/245.30dc845d.chunk.js": "./static/js/245.30dc845d.chunk.js",
"static/media/history.png": "./static/media/history.d21dcfa508bd8a624c85.png",
"index.html": "./index.html",
"main.bd1167d4.css.map": "./static/css/main.bd1167d4.css.map",
"main.db6c6622.js.map": "./static/js/main.db6c6622.js.map",
"main.b32c1377.js.map": "./static/js/main.b32c1377.js.map",
"245.30dc845d.chunk.js.map": "./static/js/245.30dc845d.chunk.js.map"
},
"entrypoints": [
"static/css/main.bd1167d4.css",
"static/js/main.db6c6622.js"
"static/js/main.b32c1377.js"
]
}

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion admin/tab_m.html
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<!doctype html><html lang="en"><head><meta charset="utf-8"/><link rel="shortcut icon" href="./favicon.ico"/><meta name="viewport" content="width=device-width,initial-scale=1,shrink-to-fit=no"/><meta name="theme-color" content="#000000"/><link rel="manifest" href="./manifest.json" crossorigin="use-credentials"/><script type="text/javascript" src="./../../lib/js/socket.io.js"></script><title>backitup Settings</title><script defer="defer" src="./static/js/main.db6c6622.js"></script><link href="./static/css/main.bd1167d4.css" rel="stylesheet"></head><body><noscript>You need to enable JavaScript to run this app.</noscript><div id="root"></div></body></html>
<!doctype html><html lang="en"><head><meta charset="utf-8"/><link rel="shortcut icon" href="./favicon.ico"/><meta name="viewport" content="width=device-width,initial-scale=1,shrink-to-fit=no"/><meta name="theme-color" content="#000000"/><link rel="manifest" href="./manifest.json" crossorigin="use-credentials"/><script type="text/javascript" src="./../../lib/js/socket.io.js"></script><title>backitup Settings</title><script defer="defer" src="./static/js/main.b32c1377.js"></script><link href="./static/css/main.bd1167d4.css" rel="stylesheet"></head><body><noscript>You need to enable JavaScript to run this app.</noscript><div id="root"></div></body></html>
65 changes: 33 additions & 32 deletions docs/oAuthService.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,21 @@ This file is used to hide client ID and client secret.
It does not store any tokens or user related information.
*/

const {OAuth2Client} = require('google-auth-library');
const { OAuth2Client } = require('google-auth-library');

const CLIENT_ID = process.env.CLIENT_ID; // Google oAuth2 APP client ID
const CLIENT_SECRET = process.env.CLIENT_SECRET; // Google oAuth2 APP client secret
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) => {
if (event.httpMethod === 'GET') {
if (event.queryStringParameters && event.queryStringParameters.code) {
try {
const {tokens} = await oAuth2Client.getToken(event.queryStringParameters.code);
const { tokens } = await oAuth2Client.getToken(event.queryStringParameters.code);

return {
statusCode: 200,
Expand All @@ -51,41 +52,41 @@ exports.handler = async (event) => {
};
}
} else
if (event.httpMethod === 'POST') {
let accessJson;
try {
accessJson = JSON.parse(event.body);
} catch (e) {
return {
statusCode: 501,
body: JSON.stringify({error: 'Cannot parse JSON'}),
};
}

oAuth2Client.setCredentials(accessJson);

try {
const result = await oAuth2Client.getAccessToken();
console.log('TOken: ' + JSON.stringify(result));
if (result.res) {
return {
statusCode: 200,
body: JSON.stringify(result.res.data),
};
} else {
accessJson.access_token = result.token;
if (event.httpMethod === 'POST') {
let accessJson;
try {
accessJson = JSON.parse(event.body);
} catch (e) {
return {
statusCode: 200,
body: JSON.stringify(accessJson),
statusCode: 501,
body: JSON.stringify({ error: 'Cannot parse JSON' }),
};
}
} catch (e) {
return {
statusCode: 501,
body: JSON.stringify({error: `Cannot get access token: ${e}`}),

oAuth2Client.setCredentials(accessJson);

try {
const result = await oAuth2Client.getAccessToken();
console.log(`TOken: ${JSON.stringify(result)}`);
if (result.res) {
return {
statusCode: 200,
body: JSON.stringify(result.res.data),
};
} else {
accessJson.access_token = result.token;
return {
statusCode: 200,
body: JSON.stringify(accessJson),
};
}
} catch (e) {
return {
statusCode: 501,
body: JSON.stringify({ error: `Cannot get access token: ${e}` }),
}
}
}
}

return {
statusCode: 501,
Expand Down
46 changes: 31 additions & 15 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -1,19 +1,12 @@
// ioBroker eslint template configuration file for js and ts files
// Please note that esm or react based modules need additional modules loaded.
import config from '@iobroker/eslint-config';

export default [
...config,

{
languageOptions: {
parserOptions: {
projectService: {
allowDefaultProject: ['*.mjs'],
},
tsconfigRootDir: import.meta.dirname,
project: './tsconfig.json',
},
},
},
{
// specify files to exclude from linting here
ignores: [
'src-admin/**/*',
'src/**/*',
Expand All @@ -24,15 +17,38 @@ export default [
'tasks.js',
'tmp/**/*',
'.**/*',
],
'.dev-server/',
'.vscode/',
'*.test.js',
'test/**/*.js',
'*.config.mjs',
'build',
'admin/build',
'admin/words.js',
'admin/admin.d.ts',
'**/adapter-config.d.ts',
]
},

{
// disable temporary the rule 'jsdoc/require-param' and enable 'jsdoc/require-jsdoc'
// you may disable some 'jsdoc' warnings - but using jsdoc is highly recommended
// 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',
'no-prototype-builtins': 'off',
'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',
},
},
];
];
26 changes: 14 additions & 12 deletions lib/dropboxLib.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class dropbox {
'User-Agent': 'axios/1.6.5'
},
responseType: 'json'
}).catch(err => log.warn('getAuthorizeUrl Dropbox: ' + err));
}).catch(err => log.warn(`getAuthorizeUrl Dropbox: ${err}`));

if (urlRequest && urlRequest.data) {
const url = `${urlRequest.data.authURL}&client_id=${urlRequest.data.client_id}`;
Expand All @@ -24,7 +24,7 @@ class dropbox {
reject();
}
} catch (e) {
console.log('error getAuthorizeUrl Dropbox: ' + e);
console.log(`error getAuthorizeUrl Dropbox: ${e}`);
reject();
}
});
Expand All @@ -50,7 +50,7 @@ class dropbox {
reject();
}
} catch (e) {
console.log('error getCodeChallage Dropbox: ' + e);
console.log(`error getCodeChallage Dropbox: ${e}`);
reject();
}
}
Expand All @@ -68,15 +68,15 @@ class dropbox {
code_verifier: code_verifier,
client_id: await this.getClientID(log)
}
}).catch(err => log.warn('getRefreshToken Dropbox: ' + err));
}).catch(err => log.warn(`getRefreshToken Dropbox: ${err}`));

if (refreshToken && refreshToken.data && refreshToken.data.refresh_token) {
resolve(refreshToken.data.refresh_token);
} else {
reject();
}
} catch (e) {
console.log('error getRefreshToken Dropbox: ' + e);
console.log(`error getRefreshToken Dropbox: ${e}`);
reject();
}
});
Expand All @@ -92,15 +92,15 @@ class dropbox {
'User-Agent': 'axios/1.6.5'
},
responseType: 'json'
}).catch(err => log.warn('getClientID Dropbox: ' + err));
}).catch(err => log.warn(`getClientID Dropbox: ${err}`));

if (urlRequest && urlRequest.data && urlRequest.data.client_id) {
resolve(urlRequest.data.client_id)
} else {
reject();
}
} catch (e) {
console.log('error getClientID Dropbox: ' + e);
console.log(`error getClientID Dropbox: ${e}`);
reject();
}
});
Expand All @@ -116,15 +116,15 @@ class dropbox {
grant_type: 'refresh_token',
client_id: await this.getClientID(log)
}
}).catch(err => log.warn('getToken Dropbox: ' + err));
}).catch(err => log.warn(`getToken Dropbox: ${err}`));

if (accessToken && accessToken.data && accessToken.data.access_token) {
resolve(accessToken.data.access_token);
} else {
reject();
}
} catch (e) {
console.log('error getToken Dropbox: ' + e);
console.log(`error getToken Dropbox: ${e}`);
reject();
}
});
Expand Down Expand Up @@ -192,7 +192,7 @@ class dropbox {
},
}, async (err, result) => {
if (err) {
log.error('sessionStart error: ' + JSON.stringify(err));
log.error(`sessionStart error: ${JSON.stringify(err)}`);
reject(err);
}
if (result && result.session_id) {
Expand All @@ -218,9 +218,10 @@ class dropbox {
readStream: getNextChunkStream(start, end)
}, async (err) => {
if (err) {
log.error(); ('sessionAppend error: ' + JSON.stringify(err));
log.error(); (`sessionAppend error: ${JSON.stringify(err)}`);
reject(err);
}
// @ts-ignore
resolve();
});
});
Expand All @@ -244,10 +245,11 @@ class dropbox {
}
}, (err) => {
if (err) {
log.error('sessionFinish error: ' + JSON.stringify(err));
log.error(`sessionFinish error: ${JSON.stringify(err)}`);
reject(err);
}
});
// @ts-ignore
resolve();
});
}
Expand Down
5 changes: 3 additions & 2 deletions lib/execute.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ function writeIntoFile(fileName, text) {
if (text) {
console.log(text);
try {
fs.appendFileSync(fileName, text + '\n');
fs.appendFileSync(fileName, `${text}\n`);
} catch (e) {

// ignore
}
}
}
Expand Down Expand Up @@ -561,6 +561,7 @@ function executeScripts(adapter, config, callback, scripts, code) {
callback && callback();
}

// @ts-ignore
if (typeof module !== 'undefined' && module.parent) {
module.exports = executeScripts;
}
13 changes: 10 additions & 3 deletions lib/googleDriveLib.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,14 @@ 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) {
url = OAUTH_URL.replace('googleDriveOAuth', '');
}

return axios.post(url, this.oAuth2Client.credentials, {headers: {'content-type': 'application/json'}})
return axios.post(url, this.oAuth2Client.credentials, { headers: { 'content-type': 'application/json' } })
.then(response => {
if (response.data) {
// BF: TODO - this token should be saved in the state variable and used by the next token request
Expand All @@ -51,11 +52,12 @@ class GoogleDrive {
return response.data.authURL;
}
throw new Error('Cannot get authorize URL');
});
});
}

_getDrive() {
this.drive = this.drive || new google.drive_v3.Drive({
// @ts-ignore
version: 'v3',
auth: this.oAuth2Client,
});
Expand All @@ -77,7 +79,9 @@ class GoogleDrive {
this._getFileOrFolderId([dir], folderId, (err, _folderId) => {
if (!_folderId) {
const fileMetadata = {
// eslint-disable-next-line quote-props
'name': dir,
// eslint-disable-next-line quote-props
'mimeType': 'application/vnd.google-apps.folder'
};

Expand Down Expand Up @@ -233,7 +237,7 @@ class GoogleDrive {
}
})).catch(() => console.log('Error Google Drive getFileOrFolderId'));
} catch (e) {
console.log('error get File or FolderId on GoogleDrive: ' + e);
console.log(`error get File or FolderId on GoogleDrive: ${e}`);
}
}

Expand Down Expand Up @@ -299,6 +303,7 @@ class GoogleDrive {
return reject(err);
}
res.data
// @ts-ignore
.on('end', () => resolve())
.on('error', err => reject(err))
.pipe(dest);
Expand All @@ -310,9 +315,11 @@ class GoogleDrive {
}
}

// @ts-ignore
if (module.parent) {
module.exports = GoogleDrive;
} else {
// @ts-ignore
const token = require('./test');
const gDrive = new GoogleDrive(token);

Expand Down
Loading

0 comments on commit d3b8336

Please sign in to comment.