Fix sqlite middleware

This commit is contained in:
Isaac 2022-09-04 19:55:32 +01:00
parent f74069deb6
commit 3697423fda
No known key found for this signature in database
GPG Key ID: 0DE40AE37BBA5C33
3 changed files with 17 additions and 11 deletions

View File

@ -6,8 +6,7 @@ const { join } = require('path');
const { files } = require('node-dir');
module.exports = client => {
// cors plugins
// cors plugin
fastify.register(require('@fastify/cors'), {
credentials: true,
methods: ['DELETE', 'GET', 'PATCH', 'PUT', 'POST'],
@ -112,13 +111,13 @@ module.exports = client => {
: res.statusCode >= 200
? '&2'
: '&f') + res.statusCode;
let response_time = res.getResponseTime().toFixed(2);
response_time = (response_time >= 20
let responseTime = res.getResponseTime().toFixed(2);
responseTime = (responseTime >= 20
? '&c'
: response_time >= 5
: responseTime >= 5
? '&e'
: '&a') + response_time + 'ms';
client.log.info.http(short(`${req.ip} ${req.method} ${req.routerPath ?? '*'} &m-+>&r ${status}&b in ${response_time}`));
: '&a') + responseTime + 'ms';
client.log.info.http(short(`${req.ip} ${req.method} ${req.routerPath ?? '*'} &m-+>&r ${status}&b in ${responseTime}`));
done();
});

View File

@ -21,7 +21,6 @@
* @license GNU-GPLv3
*/
const pkg = require('../package.json');
const fs = require('fs');
const semver = require('semver');
@ -42,7 +41,7 @@ if (!semver.satisfies(process.versions.node, pkg.engines.node)) {
}
if (process.env.ENCRYPTION_KEY === undefined) {
console.log('\x07' + colours.redBright('Error: The "ENCRYPTION_KEY" environment variable is not set.\nRun "npm run keygen" to generate a key, or set it to "false" to disable encryption (not recommended).'));
console.log('\x07' + colours.redBright('Error: The "ENCRYPTION_KEY" environment variable is not set.\nRun "npm run keygen" to generate a key.'));
process.exit(1);
}

View File

@ -17,8 +17,16 @@ const traverse = (obj, action) => {
prop = 'create';
traverse(obj[prop], action);
} else if (jsonFields.includes(prop) && obj[prop] !== null && obj[prop] !== undefined) {
if (action === 'SERIALISE' && typeof obj[prop] !== 'string') {
if (action === 'SERIALISE') {
if (typeof obj[prop] === 'string') {
try {
JSON.parse(obj[prop]);
} catch {
obj[prop] = JSON.stringify(obj[prop]);
}
} else {
obj[prop] = JSON.stringify(obj[prop]);
}
} else if (action === 'PARSE' && typeof obj[prop] === 'string') {
obj[prop] = JSON.parse(obj[prop]);
}