fix: Added a check for missing config files. Added FileHandler class.

This commit is contained in:
2025-06-06 16:43:48 +02:00
parent 93183799af
commit aac85e3679
12 changed files with 119 additions and 48 deletions

View File

@@ -20,11 +20,22 @@ class VapidKeysSettings {
}
reload() {
this._keys = JSON.parse(readFileSync("./config/keys.json", {encoding: "utf-8"}))
if (!(this._keys.privateKey && this._keys.publicKey)) {
this.keys = generateVAPIDKeys()
try {
this._keys = JSON.parse(readFileSync("./config/keys.json", {encoding: "utf-8"}))
} catch (error) {
if (error instanceof Error) {
if ('code' in error) {
if (error.code === "ENOENT") {
this.keys = generateVAPIDKeys();
}
}
}
} finally {
if (!(this.keys.privateKey && this.keys.publicKey)) {
this.keys = generateVAPIDKeys()
}
console.log("Reloaded VAPID keys");
}
console.log("Reloaded VAPID keys");
}
}