api/api-keys: log message to confirm successful file load

This commit is contained in:
jj 2024-10-27 18:00:05 +00:00
parent 5ea23bee13
commit af50852815
No known key found for this signature in database

View file

@ -1,6 +1,6 @@
import { env } from "../config.js";
import { readFile } from "node:fs/promises";
import { Yellow } from "../misc/console-text.js";
import { Green, Yellow } from "../misc/console-text.js";
import ip from "ipaddr.js";
// this function is a modified variation of code
@ -134,9 +134,13 @@ const loadKeys = async (source) => {
keys = formatKeys(updated);
}
const wrapLoad = (url) => {
const wrapLoad = (url, initial = false) => {
loadKeys(url)
.then(() => {})
.then(() => {
if (initial) {
console.log(`${Green('[✓]')} api keys loaded successfully!`)
}
})
.catch((e) => {
console.error(`${Yellow('[!]')} Failed loading API keys at ${new Date().toISOString()}.`);
console.error('Error:', e);
@ -200,7 +204,7 @@ export const validateAuthorization = (req) => {
}
export const setup = (url) => {
wrapLoad(url);
wrapLoad(url, true);
if (env.keyReloadInterval > 0) {
setInterval(() => wrapLoad(url), env.keyReloadInterval * 1000);
}