Added new codebook page
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
import dotenv from 'dotenv';
|
||||
import * as fs from 'node:fs';
|
||||
import { fileURLToPath } from 'url';
|
||||
import { dirname } from 'path';
|
||||
import { execSync } from "child_process";
|
||||
|
||||
dotenv.config();
|
||||
|
||||
export const environment = {
|
||||
config: process.env.CONFIG || 'config.json',
|
||||
hostname: process.env.HOSTNAME || execSync('hostname', { encoding: "utf-8" }) || 'localhost',
|
||||
gpsd: process.env.GPSD || 2947,
|
||||
port: process.env.PORT || 80,
|
||||
root: dirname(dirname(fileURLToPath(import.meta.url))),
|
||||
settings: {},
|
||||
}
|
||||
|
||||
if(!environment.config.startsWith('/')) environment.config = `${environment.root}/${environment.config}`;
|
||||
|
||||
export function loadSettings() {
|
||||
if(!fs.existsSync(environment.config)) fs.writeFileSync(environment.config, '', { flag: 'a' });
|
||||
const value = fs.readFileSync(environment.config, 'utf-8');
|
||||
try { return JSON.parse(value); }
|
||||
catch (e) {
|
||||
return {
|
||||
lora: {
|
||||
mode: 'MESH',
|
||||
telemetry: true,
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
export function saveSettings() {
|
||||
fs.writeFileSync(environment.config, JSON.stringify(environment.settings, null, 4));
|
||||
}
|
||||
|
||||
loadSettings();
|
||||
Reference in New Issue
Block a user