mirror of
https://github.com/LLOneBot/LLOneBot.git
synced 2024-11-22 01:56:33 +00:00
29 lines
722 B
TypeScript
29 lines
722 B
TypeScript
import {Config} from "../common/types";
|
|
|
|
const fs = require("fs")
|
|
|
|
export class ConfigUtil{
|
|
configPath: string;
|
|
|
|
constructor(configPath: string) {
|
|
this.configPath = configPath;
|
|
}
|
|
|
|
getConfig(): Config{
|
|
if (!fs.existsSync(this.configPath)) {
|
|
return {port:3000, hosts: ["http://192.168.1.2:5000/"]}
|
|
} else {
|
|
const data = fs.readFileSync(this.configPath, "utf-8");
|
|
let jsonData =JSON.parse(data);
|
|
if (!jsonData.hosts){
|
|
jsonData.hosts = []
|
|
}
|
|
return jsonData;
|
|
}
|
|
}
|
|
|
|
setConfig(config: Config){
|
|
fs.writeFileSync(this.configPath, JSON.stringify(config, null, 2), "utf-8")
|
|
}
|
|
}
|