From 74cf834699084844577d61276d384114494edf00 Mon Sep 17 00:00:00 2001 From: Enstrayed <48845980+Enstrayed@users.noreply.github.com> Date: Sun, 20 Apr 2025 13:52:49 -0700 Subject: [PATCH] fix problem with logging & add misc functions --- liberals/logging.js | 2 +- liberals/misc.js | 23 +++++++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 liberals/misc.js diff --git a/liberals/logging.js b/liberals/logging.js index ecdb8e2..ebbe529 100644 --- a/liberals/logging.js +++ b/liberals/logging.js @@ -7,7 +7,7 @@ * @param {object} authresponse Optionally include result of auth response to include owner information for a token */ function logRequest(response,request,code,extra,authresponse) { - console.log(`${request.get("cf-connecting-ip") ?? request.ip} ${authresponse.owner ?? ""}/${request.get("Authorization") ?? ""} ${request.method} ${request.path} returned ${code} ${extra ?? ""}`) + console.log(`${request.get("cf-connecting-ip") ?? request.ip} ${authresponse?.owner ?? ""}/${request.get("Authorization") ?? ""} ${request.method} ${request.path} returned ${code} ${extra ?? ""}`) } export { logRequest } \ No newline at end of file diff --git a/liberals/misc.js b/liberals/misc.js new file mode 100644 index 0000000..b12a8f6 --- /dev/null +++ b/liberals/misc.js @@ -0,0 +1,23 @@ +function randomStringBase16(length) { + let characters = "0123456789abcdef" + let remaining = length + let returnstring = "" + while (remaining > 0) { + returnstring = returnstring + characters.charAt(Math.floor(Math.random() * characters.length)) + remaining = remaining - 1 + } + return returnstring +} + +function randomStringBase62(length) { + let characters = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHJIJKLMNOPQRSTUVWXYZ" + let remaining = length + let returnstring = "" + while (remaining > 0) { + returnstring = returnstring + characters.charAt(Math.floor(Math.random() * characters.length)) + remaining = remaining - 1 + } + return returnstring +} + +export { randomStringBase16, randomStringBase62 } \ No newline at end of file