clean up code a bit

This commit is contained in:
Mystikfluu 2022-11-30 22:43:36 +01:00
parent a4206ec1a7
commit 77ae066e46

View File

@ -82,21 +82,14 @@ const con = mysql.createPool({
password: readFileSync(config.mysql.password_file).toString() password: readFileSync(config.mysql.password_file).toString()
}); });
const cookiesecret = readFileSync("cookiesecret.txt").toString(); const cookiesecret = readFileSync("cookiesecret.txt").toString();
/**
* quick function to convert data to base64
* @param {any} data data to encode in base64
* @return {string} base64 encoded data
*/
function b64(data) {
let buff = Buffer.from(data);
return buff.toString('base64');
}
/** /**
* custom, bad random number generator * custom, bad random number generator
* @param {number} seed seed for the number generator, defaults to current timestamp * @param {number} seed seed for the number generator, defaults to current timestamp
* @constructor * @constructor
*/ */
function RNG(seed) { class RNG {
constructor(seed) {
if (!seed) if (!seed)
seed = Date.now(); seed = Date.now();
this.seed = seed; this.seed = seed;
@ -114,13 +107,6 @@ function RNG(seed) {
return Math.floor(this.random(min, max)); return Math.floor(this.random(min, max));
}; };
} }
/**
* waits x ms
* @param {number} ms amount of ms to sleep for
* @return {promise} promise that gets resolved after x ms
*/
function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
} }
const rand = new RNG(); const rand = new RNG();
const genstring_characters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_"; const genstring_characters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_";
@ -137,15 +123,7 @@ function genstring(length) {
} }
return result; return result;
} }
/**
* utility function to get a key by its value in an object
* @param {object} object object to get key from
* @param {any} value value to get key from
* @return {any} key to the given value inside the object
*/
function getKeyByValue(object, value) {
return Object.keys(object).find(key => object[key] === value);
}
var API_CALLS = {}; var API_CALLS = {};
var API_CALLS_ACCOUNT = {}; var API_CALLS_ACCOUNT = {};
var USER_CALLS = {}; var USER_CALLS = {};