api/util: make JSON file loading platform independent

This commit is contained in:
dumbmoron 2024-04-22 20:41:44 +00:00
parent 877933a17f
commit 2a7a0df8a1
No known key found for this signature in database

View file

@ -3,13 +3,11 @@ import * as fs from "fs";
import path from 'path';
import { fileURLToPath } from 'url';
const splitDir = path.dirname(fileURLToPath(import.meta.url)).split('/');
splitDir.splice(-2);
const dir = splitDir.join('/');
const dir = path.join(path.dirname(fileURLToPath(import.meta.url)), '../../');
export function loadJSON(filePath) {
try {
return JSON.parse(fs.readFileSync(`${dir}/${filePath}`, 'utf-8'))
return JSON.parse(fs.readFileSync(path.join(dir, filePath), 'utf-8'))
} catch(e) {
return false
}