fix problem with logging & add misc functions

This commit is contained in:
Enstrayed
2025-04-20 13:52:49 -07:00
parent 9f96d82e53
commit 74cf834699
2 changed files with 24 additions and 1 deletions

View File

@@ -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 }

23
liberals/misc.js Normal file
View File

@@ -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 }