update nginx/dep updates/fix eslint/change line endings

Signed-off-by: Zoey <zoey@z0ey.de>
This commit is contained in:
Zoey
2024-03-25 18:24:21 +01:00
parent ef5ac4cbd8
commit 906d7ce04a
96 changed files with 2579 additions and 2859 deletions

View File

@@ -3,16 +3,15 @@
and then has abilities after that.
*/
const _ = require('lodash');
const jwt = require('jsonwebtoken');
const _ = require('lodash');
const jwt = require('jsonwebtoken');
const crypto = require('crypto');
const config = require('../lib/config');
const error = require('../lib/error');
const error = require('../lib/error');
const logger = require('../logger').global;
const ALGO = 'RS256';
const ALGO = 'RS256';
module.exports = function () {
let token_data = {};
const self = {
@@ -27,12 +26,10 @@ module.exports = function () {
// sign with RSA SHA256
const options = {
algorithm: ALGO,
expiresIn: payload.expiresIn || '1d'
expiresIn: payload.expiresIn || '1d',
};
payload.jti = crypto.randomBytes(12)
.toString('base64')
.substring(-8);
payload.jti = crypto.randomBytes(12).toString('base64').substring(-8);
return new Promise((resolve, reject) => {
jwt.sign(payload, config.getPrivateKey(), options, (err, token) => {
@@ -41,8 +38,8 @@ module.exports = function () {
} else {
token_data = payload;
resolve({
token: token,
payload: payload
token,
payload,
});
}
});
@@ -62,15 +59,13 @@ module.exports = function () {
if (!token || token === null || token === 'null') {
reject(new error.AuthError('Empty token'));
} else {
jwt.verify(token, config.getPublicKey(), {ignoreExpiration: false, algorithms: [ALGO]}, (err, result) => {
jwt.verify(token, config.getPublicKey(), { ignoreExpiration: false, algorithms: [ALGO] }, (err, result) => {
if (err) {
if (err.name === 'TokenExpiredError') {
reject(new error.AuthError('Token has expired', err));
} else {
reject(err);
}
} else {
token_data = result;
resolve(token_data);
@@ -81,7 +76,6 @@ module.exports = function () {
reject(err);
}
});
},
/**
@@ -125,7 +119,7 @@ module.exports = function () {
}
return default_value || 0;
}
},
};
return self;