ESLint fixes
Signed-off-by: Fred Boniface <fred@fjla.uk>
This commit is contained in:
parent
c0c50d0e5b
commit
7580ff8175
@ -13,7 +13,7 @@ module.exports = {
|
||||
'rules': {
|
||||
'indent': [
|
||||
'error',
|
||||
4
|
||||
2
|
||||
],
|
||||
'linebreak-style': [
|
||||
'error',
|
||||
|
@ -1,6 +1,6 @@
|
||||
const version = {
|
||||
api: ["/api/v1/",],
|
||||
app: "2.0.0-dev"
|
||||
};
|
||||
api: ['/api/v1/',],
|
||||
app: '2.0.0-dev'
|
||||
}
|
||||
|
||||
module.exports = version;
|
||||
module.exports = version
|
@ -1,43 +1,48 @@
|
||||
const log = require('../utils/log.utils'); // Log Helper
|
||||
const log = require('../utils/log.utils') // Log Helper
|
||||
|
||||
const dbUser = process.env.OWL_DB_USER || "owl"
|
||||
const dbPass = process.env.OWL_DB_PASS || "twittwoo"
|
||||
const dbName = process.env.OWL_DB_NAME || "owlboard"
|
||||
// eslint-disable-next-line no-undef
|
||||
const dbUser = process.env.OWL_DB_USER || 'owl'
|
||||
// eslint-disable-next-line no-undef
|
||||
const dbPass = process.env.OWL_DB_PASS || 'twittwoo'
|
||||
// eslint-disable-next-line no-undef
|
||||
const dbName = process.env.OWL_DB_NAME || 'owlboard'
|
||||
// eslint-disable-next-line no-undef
|
||||
const dbPort = process.env.OWL_DB_PORT || 27017
|
||||
const dbHost = process.env.OWL_DB_HOST || "localhost"
|
||||
const uri = `mongodb://${dbUser}:${dbPass}@${dbHost}:${dbPort}`;
|
||||
// eslint-disable-next-line no-undef
|
||||
const dbHost = process.env.OWL_DB_HOST || 'localhost'
|
||||
const uri = `mongodb://${dbUser}:${dbPass}@${dbHost}:${dbPort}`
|
||||
|
||||
const { MongoClient } = require('mongodb');
|
||||
const { MongoClient } = require('mongodb')
|
||||
|
||||
const client = new MongoClient(uri);
|
||||
const db = client.db(dbName);
|
||||
const client = new MongoClient(uri)
|
||||
const db = client.db(dbName)
|
||||
|
||||
async function query(collection, query){
|
||||
await client.connect();
|
||||
log.out(`dbAccess.query: Connecting to collection: '${collection}'`, "info")
|
||||
var qcoll = db.collection(collection);
|
||||
await client.connect()
|
||||
log.out(`dbAccess.query: Connecting to collection: '${collection}'`, 'info')
|
||||
var qcoll = db.collection(collection)
|
||||
var qcursor = qcoll.find(query)
|
||||
qcursor.project({_id: 0})
|
||||
log.out(`dbAccess.query: Running Query: ${JSON.stringify(query)}`, "info")
|
||||
log.out(`dbAccess.query: Running Query: ${JSON.stringify(query)}`, 'info')
|
||||
increment(collection)
|
||||
return (await qcursor.toArray());
|
||||
return (await qcursor.toArray())
|
||||
}
|
||||
|
||||
async function increment(target) {
|
||||
log.out(`dbAccess.increment: Incrementing counter for: ${target}`, "info")
|
||||
await client.connect();
|
||||
let col = db.collection("meta");
|
||||
log.out(`dbAccess.increment: Incrementing counter for: ${target}`, 'info')
|
||||
await client.connect()
|
||||
let col = db.collection('meta')
|
||||
let update = {}
|
||||
update[target] = 1
|
||||
col.updateOne({target: "counters"}, {$inc:update})
|
||||
col.updateOne({target: 'counters'}, {$inc:update})
|
||||
}
|
||||
|
||||
async function addUser(uuid, domain) { // Needs testing
|
||||
log.out(`dbAccess.addUser: Adding user to database`)
|
||||
log.out('dbAccess.addUser: Adding user to database')
|
||||
let doc = {uuid: uuid, domain: domain, atime: new Date}
|
||||
await client.connect();
|
||||
let col = db.collection("users");
|
||||
res = await col.insertOne(doc);
|
||||
await client.connect()
|
||||
let col = db.collection('users')
|
||||
let res = await col.insertOne(doc)
|
||||
if (res.insertedId) {
|
||||
return true
|
||||
}
|
||||
@ -45,28 +50,28 @@ async function addUser(uuid, domain) { // Needs testing
|
||||
}
|
||||
|
||||
async function addRegReq(uuid, domain) { // Needs testing
|
||||
log.out(`dbAccess.addRegReq: Adding registration request`)
|
||||
log.out('dbAccess.addRegReq: Adding registration request')
|
||||
let doc = {uuid: uuid, time: new Date, domain: domain}
|
||||
await client.connect();
|
||||
let col = db.collection("registrations");
|
||||
res = col.insertOne(doc);
|
||||
return res;
|
||||
await client.connect()
|
||||
let col = db.collection('registrations')
|
||||
let res = col.insertOne(doc)
|
||||
return res
|
||||
}
|
||||
|
||||
async function userAtime(uuid) { // Needs testing
|
||||
log.out(`dbAccess.userAtime: Updating access time for user`);
|
||||
let q = {uuid: uuid};
|
||||
let n = {$set: {uuid: uuid, atime: new Date}};
|
||||
await client.connect();
|
||||
let col = db.collection("users");
|
||||
res = col.updateOne(q, n, {upsert: true})
|
||||
return res;
|
||||
log.out('dbAccess.userAtime: Updating access time for user')
|
||||
let q = {uuid: uuid}
|
||||
let n = {$set: {uuid: uuid, atime: new Date}}
|
||||
await client.connect()
|
||||
let col = db.collection('users')
|
||||
let res = col.updateOne(q, n, {upsert: true})
|
||||
return res
|
||||
}
|
||||
|
||||
// Deletes one single registration request entry from the DB
|
||||
async function delRegReq(uuid) {
|
||||
log.out(`dbAccess.delRegReq: Deleting a Registration Request`)
|
||||
collection = "registrations"
|
||||
log.out('dbAccess.delRegReq: Deleting a Registration Request')
|
||||
let collection = 'registrations'
|
||||
await client.connect()
|
||||
let col = db.collection(collection)
|
||||
col.deleteOne({uuid: uuid})
|
||||
|
@ -1,22 +1,23 @@
|
||||
const log = require('../utils/log.utils'); // Log Helper
|
||||
const log = require('../utils/log.utils') // Log Helper
|
||||
const db = require('../services/dbAccess.services')
|
||||
const os = require('os')
|
||||
const vers = require('../configs/version.configs')
|
||||
|
||||
async function hits(){
|
||||
log.out("statsServices.hits: Statistics Requested", "info")
|
||||
var dat = db.query("meta", {target: "counters"});
|
||||
var ver = db.query("meta", {target: "versions"});
|
||||
log.out(`statsServices.hits: fetched server meta`, "info")
|
||||
let out = {};
|
||||
out.host = os.hostname();
|
||||
out.mode = process.env.NODE_ENV;
|
||||
out.verBkend = vers.app;
|
||||
out.verApi = vers.api;
|
||||
out.dat = await dat;
|
||||
out.ver = await ver;
|
||||
log.out(`statsServices.hits: Sending Data: ${JSON.stringify(out)}`, "info")
|
||||
return out;
|
||||
log.out('statsServices.hits: Statistics Requested', 'info')
|
||||
var dat = db.query('meta', {target: 'counters'})
|
||||
var ver = db.query('meta', {target: 'versions'})
|
||||
log.out('statsServices.hits: fetched server meta', 'info')
|
||||
let out = {}
|
||||
out.host = os.hostname()
|
||||
// eslint-disable-next-line no-undef
|
||||
out.mode = process.env.NODE_ENV
|
||||
out.verBkend = vers.app
|
||||
out.verApi = vers.api
|
||||
out.dat = await dat
|
||||
out.ver = await ver
|
||||
log.out(`statsServices.hits: Sending Data: ${JSON.stringify(out)}`, 'info')
|
||||
return out
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
|
@ -1,54 +1,54 @@
|
||||
const log = require('../utils/log.utils');
|
||||
const log = require('../utils/log.utils')
|
||||
const crypto = require('crypto')
|
||||
const db = require('../services/dbAccess.services');
|
||||
const db = require('../services/dbAccess.services')
|
||||
const fs = require('fs/promises')
|
||||
const minify = require('html-minifier').minify;
|
||||
const minify = require('html-minifier').minify
|
||||
|
||||
// Checks users registration key against issued keys
|
||||
async function isAuthed(uuid) { // Needs testing
|
||||
const q = {uuid: uuid}
|
||||
const res = await db.query("users", q)
|
||||
log.out(`authUtils.checkUser: DB Query answer: ${JSON.stringify(res[0])}`, "dbug")
|
||||
const authorized = res && res[0] && res[0].domain;
|
||||
const res = await db.query('users', q)
|
||||
log.out(`authUtils.checkUser: DB Query answer: ${JSON.stringify(res[0])}`, 'dbug')
|
||||
const authorized = res && res[0] && res[0].domain
|
||||
if (authorized) db.userAtime(uuid)
|
||||
return authorized
|
||||
}
|
||||
|
||||
// Checks whether a registration request key is valid
|
||||
async function checkRequest(key) {
|
||||
const collection = "registrations"
|
||||
const collection = 'registrations'
|
||||
const query = {uuid: key}
|
||||
const res = await db.query(collection, query)
|
||||
log.out(`authUtils.checkRequest: DB Query result: ${JSON.stringify(res)}`, "dbug")
|
||||
log.out(`authUtils.checkRequest: DB Query result: ${JSON.stringify(res)}`, 'dbug')
|
||||
const result = res.length > 0 && res[0].time
|
||||
? { result: true, domain: res[0].domain }
|
||||
: { result: false };
|
||||
return result;
|
||||
: { result: false }
|
||||
return result
|
||||
}
|
||||
|
||||
// Creates an API key for a user
|
||||
async function generateKey() { // Needs testing & moving to 'register.utils'
|
||||
return crypto.randomUUID()
|
||||
};
|
||||
}
|
||||
|
||||
async function generateConfirmationEmail(eml, uuid) {
|
||||
try {
|
||||
let htmlTpl = await fs.readFile('mail-templates/register.html', 'utf-8');
|
||||
let htmlTpl = await fs.readFile('mail-templates/register.html', 'utf-8')
|
||||
let mini = minify(((htmlTpl).replace(/>>ACCESSCODE<</g, uuid)), { // Add collapse whitespace here
|
||||
removeComments: true,
|
||||
collapseWhitespace: true,
|
||||
minifyCSS: true
|
||||
});
|
||||
let txtTpl = fs.readFile('mail-templates/register.txt', 'utf-8');
|
||||
return msg = { // CSS Needs to be inlined. See css-inline, or css-inliner
|
||||
})
|
||||
let txtTpl = fs.readFile('mail-templates/register.txt', 'utf-8')
|
||||
return { // CSS Needs to be inlined. See css-inline, or css-inliner
|
||||
to: eml,
|
||||
subject: "OwlBoard Registration",
|
||||
subject: 'OwlBoard Registration',
|
||||
text: (await txtTpl).replace(/>>ACCESSCODE<</g, uuid),
|
||||
html: mini
|
||||
}
|
||||
} catch(err) {
|
||||
log.out(`mailServices.generateConfirmationEmail: Error reading templates, $(err)`, "err");
|
||||
return false;
|
||||
log.out('mailServices.generateConfirmationEmail: Error reading templates, $(err)', 'err')
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user