24
src/services/redis.services.ts
Normal file
24
src/services/redis.services.ts
Normal file
@@ -0,0 +1,24 @@
|
||||
import { createClient } from "redis";
|
||||
|
||||
import zlib from 'zlib';
|
||||
|
||||
const client = createClient({
|
||||
url: "redis:PORT"
|
||||
});
|
||||
|
||||
client.on('error', err => console.log('Redis Client Error', err));
|
||||
|
||||
async function addToCache(key: string, value: Object): Promise<boolean> {
|
||||
throw new Error("Unable to post to cache")
|
||||
}
|
||||
|
||||
async function getFromCache(key: string): Promise<Object> {
|
||||
throw new Error("Unable to retreive")
|
||||
}
|
||||
/*
|
||||
await client.connect();
|
||||
|
||||
await client.set('key', 'value');
|
||||
const value = await client.get('key');
|
||||
await client.disconnect();
|
||||
*/
|
||||
@@ -1,5 +1,5 @@
|
||||
const log = require('../utils/log.utils');
|
||||
const crypto = require('crypto');
|
||||
const logs = require('../utils/logs.utils');
|
||||
const crypt = require('crypt');
|
||||
const db = require('../services/dbAccess.services');
|
||||
const fs = require('fs/promises');
|
||||
const minify = require('../utils/minify.utils');
|
||||
@@ -8,7 +8,7 @@ const minify = require('../utils/minify.utils');
|
||||
async function isAuthed(uuid: string) { // Needs testing
|
||||
const q = {uuid: uuid};
|
||||
const res = await db.query('users', q);
|
||||
log.out('authUtils.checkUser: DB Query answer: ' +
|
||||
logs.out('authUtils.checkUser: DB Query answer: ' +
|
||||
JSON.stringify(res[0]), 'dbug');
|
||||
const authorized = res && res[0] && res[0].domain;
|
||||
if (authorized) db.userAtime(uuid);
|
||||
@@ -20,7 +20,7 @@ async function checkRequest(key: string) {
|
||||
const collection = 'registrations';
|
||||
const query = {uuid: key};
|
||||
const res = await db.query(collection, query);
|
||||
log.out('authUtils.checkRequest: DB Query result: ' +
|
||||
logs.out('authUtils.checkRequest: DB Query result: ' +
|
||||
JSON.stringify(res), 'dbug');
|
||||
const result = res.length > 0 && res[0].time
|
||||
? { result: true, domain: res[0].domain }
|
||||
@@ -30,7 +30,7 @@ async function checkRequest(key: string) {
|
||||
|
||||
// Creates an API key for a user
|
||||
async function generateKey() { // Needs testing & moving to 'register.utils'
|
||||
return crypto.randomUUID();
|
||||
return crypt.randomUUID();
|
||||
}
|
||||
|
||||
async function generateConfirmationEmail(eml: string, uuid: string) {
|
||||
@@ -46,7 +46,7 @@ async function generateConfirmationEmail(eml: string, uuid: string) {
|
||||
html: htmlMin
|
||||
};
|
||||
} catch(err) {
|
||||
log.out('mailServices.generateConfirmationEmail: Error reading template, ' +
|
||||
logs.out('mailServices.generateConfirmationEmail: Error reading template, ' +
|
||||
err, 'err');
|
||||
return false;
|
||||
}
|
||||
@@ -57,4 +57,11 @@ module.exports = {
|
||||
generateKey,
|
||||
generateConfirmationEmail,
|
||||
checkRequest
|
||||
};
|
||||
};
|
||||
|
||||
export {
|
||||
isAuthed,
|
||||
generateKey,
|
||||
generateConfirmationEmail,
|
||||
checkRequest
|
||||
}
|
||||
@@ -1,8 +1,10 @@
|
||||
const log = require('../utils/log.utils'); // Log Helper
|
||||
const db = require('../services/dbAccess.services'); // DB Access
|
||||
const san = require('../utils/sanitizer.utils'); // Sanitiser
|
||||
//const san = require('../utils/sanitizer.utils'); // Sanitiser
|
||||
|
||||
async function checkCrs(input){
|
||||
import * as san from '../utils/sanitizer.utils'
|
||||
|
||||
async function checkCrs(input = ""){
|
||||
var INPUT = input.toUpperCase();
|
||||
var query = {
|
||||
'$or':[
|
||||
@@ -22,10 +24,10 @@ async function cleanMessages(input){
|
||||
log.out('ldbUtils.cleanMessages: Deprecated function has been called', 'err');
|
||||
var out = [];
|
||||
if (typeof input.message == 'string') {
|
||||
out.push(await san.cleanNrcc(input.message));
|
||||
out.push(san.cleanNrcc(input.message));
|
||||
} else if (typeof input.message == 'object') {
|
||||
for(var i = 0; i < input.message.length; i++) {
|
||||
out.push(await san.cleanNrcc(input.message[i]));
|
||||
out.push(san.cleanNrcc(input.message[i]));
|
||||
}
|
||||
}
|
||||
return out;
|
||||
|
||||
@@ -14,4 +14,6 @@ async function out(msg: string, level = 'othr') {
|
||||
|
||||
module.exports = {
|
||||
out
|
||||
};
|
||||
};
|
||||
|
||||
export { out }
|
||||
@@ -1,10 +1,13 @@
|
||||
const htmlShrink = require('html-minifier').minify;
|
||||
const juice = require('juice');
|
||||
|
||||
module.exports = async function minifyMail(input: string): Promise<string> {
|
||||
async function minifyMail(input: string): Promise<string> {
|
||||
const inlined: string = juice(input);
|
||||
return htmlShrink(inlined, {
|
||||
removeComments: true,
|
||||
collapseWhitespace: true
|
||||
});
|
||||
};
|
||||
};
|
||||
|
||||
module.exports = {minifyMail}
|
||||
export {minifyMail}
|
||||
@@ -33,4 +33,14 @@ module.exports = {
|
||||
removeNonNumeric,
|
||||
cleanNrcc,
|
||||
getDomainFromEmail,
|
||||
};
|
||||
};
|
||||
|
||||
export {
|
||||
cleanApiEndpointTxt,
|
||||
cleanApiEndpointNum,
|
||||
removeNonAlpha,
|
||||
removeNonAlphanumeric,
|
||||
removeNonNumeric,
|
||||
cleanNrcc,
|
||||
getDomainFromEmail,
|
||||
}
|
||||
Reference in New Issue
Block a user