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

View File

@ -21,7 +21,6 @@
* @license GNU-GPLv3 * @license GNU-GPLv3
*/ */
const pkg = require('../package.json'); const pkg = require('../package.json');
const fs = require('fs'); const fs = require('fs');
const semver = require('semver'); const semver = require('semver');
@ -42,7 +41,7 @@ if (!semver.satisfies(process.versions.node, pkg.engines.node)) {
} }
if (process.env.ENCRYPTION_KEY === undefined) { 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); process.exit(1);
} }

View File

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