nodejs: dot notation whenever possible

This commit is contained in:
rivexe
2023-03-29 15:43:55 +03:00
parent 3ed13f3975
commit 5999b070dc
4 changed files with 19 additions and 19 deletions

View File

@ -88,7 +88,7 @@ if (config.has('server.static')) { // check if there are static files such as .
const staticContent = config.get('server.static');
for (let i = 0; i < staticContent.length; ++i) {
const staticContentElem = staticContent[i];
app.use(staticContentElem['name'], express.static(staticContentElem['path'], staticContentElem['options']));
app.use(staticContentElem.name, express.static(staticContentElem.path, staticContentElem.options));
}
}
app.use(favicon(`${__dirname }/public/images/favicon.ico`)); // use favicon
@ -337,13 +337,13 @@ app.post('/convert', (req, res) => { // define a handler for converting files
// write file name, step and error values to the result object if they are defined
if (filename != null)
result['filename'] = filename;
result.filename = filename;
if (step != null)
result['step'] = step;
result.step = step;
if (error != null)
result['error'] = error;
result.error = error;
response.setHeader('Content-Type', 'application/json');
response.write(JSON.stringify(result));

View File

@ -99,9 +99,9 @@ docManager.prototype.getCorrectName = function (fileName, userAddress) {
// processes a request editnew
docManager.prototype.RequestEditnew = function (req, fileName, user) {
let correctName = fileName;
if (req.params['id'] != fileName) { // processes a repeated request editnew
this.fileRemove(req.params['id']);
correctName = this.getCorrectName(req.params['id']);
if (req.params.id != fileName) { // processes a repeated request editnew
this.fileRemove(req.params.id);
correctName = this.getCorrectName(req.params.id);
}
this.fileSizeZero(correctName);
this.saveFileData(correctName, user.id, user.name);
@ -180,7 +180,7 @@ docManager.prototype.getServerPath = function () {
// get host address from the request
docManager.prototype.getServerHost = function () {
return `${this.getProtocol() }://${ this.req.headers['x-forwarded-host'] || this.req.headers['host']}`;
return `${this.getProtocol() }://${ this.req.headers['x-forwarded-host'] || this.req.headers.host}`;
};
// get protocol from the request

View File

@ -287,8 +287,8 @@ const returnLockMismatch = function (res, lock, reason) {
const parseWopiRequest = function (req) {
const wopiData = {
requestType: reqConsts.requestType.None,
accessToken: req.query['access_token'],
id: req.params['id']
accessToken: req.query.access_token,
id: req.params.id
}
// get the request path
@ -362,9 +362,9 @@ actionMapping[reqConsts.requestType.Unlock] = unlock;
exports.fileRequestHandler = (req, res) => {
let userAddress = null;
req.docManager = new docManager(req, res);
if (req.params['id'].includes('@')) { // if there is the "@" sign in the id parameter
const split = req.params['id'].split('@'); // split this parameter by "@"
[req.params['id']] = split; // rewrite id with the first part of the split parameter
if (req.params.id.includes('@')) { // if there is the "@" sign in the id parameter
const split = req.params.id.split('@'); // split this parameter by "@"
[req.params.id] = split; // rewrite id with the first part of the split parameter
[,userAddress] = split; // save the second part as the user address
}
@ -372,14 +372,14 @@ exports.fileRequestHandler = (req, res) => {
// an error of the unknown request type
if (wopiData.requestType == reqConsts.requestType.None) {
res.status(500).send({ title: 'fileHandler', method: req.method, id: req.params['id'], error: 'unknown' });
res.status(500).send({ title: 'fileHandler', method: req.method, id: req.params.id, error: 'unknown' });
return;
}
// an error of the unsupported request type
const action = actionMapping[wopiData.requestType];
if (!action) {
res.status(501).send({ title: 'fileHandler', method: req.method, id: req.params['id'], error: 'unsupported' });
res.status(501).send({ title: 'fileHandler', method: req.method, id: req.params.id, error: 'unsupported' });
return;
}

View File

@ -112,20 +112,20 @@ exports.registerRoutes = function (app) {
await utils.initWopi(req.docManager);
let fileName = req.docManager.getCorrectName(req.params['id'])
let fileName = req.docManager.getCorrectName(req.params.id)
let fileExt = fileUtility.getFileExtension(fileName, true); // get the file extension from the request
let user = users.getUser(req.query.userid); // get a user by the id
// get an action for the specified extension and name
const action = await utils.getAction(fileExt, req.query['action']);
const action = await utils.getAction(fileExt, req.query.action);
if (action != null && req.query['action'] == 'editnew') {
if (action != null && req.query.action == 'editnew') {
fileName = req.docManager.RequestEditnew(req, fileName, user);
}
// render wopiAction template with the parameters specified
res.render('wopiAction', {
actionUrl: utils.getActionUrl(req.docManager.getServerUrl(true), req.docManager.curUserHostAddress(), action, req.params['id']),
actionUrl: utils.getActionUrl(req.docManager.getServerUrl(true), req.docManager.curUserHostAddress(), action, req.params.id),
token: 'test',
tokenTtl: Date.now() + 1000 * 60 * 60 * 10,
params: getCustomWopiParams(req.query),