check if fredy config exists and is accessible

This commit is contained in:
orangecoding
2025-10-03 17:23:46 +02:00
parent ebc57702dc
commit 9f1e27d011
2 changed files with 25 additions and 1 deletions

View File

@@ -180,6 +180,23 @@ function buildHash(...inputs) {
*/
let config = {};
/**
* If the config exists, but cannot be accessed, we quit Fredy as something is fishy here.
* @returns {Promise<boolean>}
*/
export async function checkIfConfigIsAccessible() {
const path = new URL('../conf/config.json', import.meta.url);
try {
if (!fs.existsSync(path)) {
return true;
}
fs.accessSync(path, fs.constants.R_OK);
return true;
} catch {
return false;
}
}
/**
* Read config JSON from disk (conf/config.json) and parse it.
* @returns {Promise<any>} Parsed configuration object.