add option into setting
This commit is contained in:
parent
15b6d0c2c2
commit
f70cfd041a
@ -1,11 +1,38 @@
|
||||
import { readFileSync } from 'fs';
|
||||
import { Settings } from '@material-ui/icons';
|
||||
import { readFileSync, writeFileSync } from 'fs';
|
||||
|
||||
export type Setting = {
|
||||
path: string[]
|
||||
path: string[],
|
||||
initial_admin_password:string,
|
||||
localmode: boolean,
|
||||
guest: boolean,
|
||||
}
|
||||
const default_setting:Setting = {
|
||||
path:[],
|
||||
initial_admin_password:"admin",
|
||||
localmode: true,
|
||||
guest:false,
|
||||
}
|
||||
let setting: null|Setting = null;
|
||||
const setEmptyToDefault = (target:any,default_table:any)=>{
|
||||
let diff_occur = false;
|
||||
for(const key in default_table){
|
||||
if(key === undefined || key in target){
|
||||
continue;
|
||||
}
|
||||
target[key] = default_table[key];
|
||||
diff_occur = true;
|
||||
}
|
||||
return diff_occur;
|
||||
}
|
||||
|
||||
export const read_setting_from_file = ()=>{
|
||||
return JSON.parse(readFileSync("settings.json",{encoding:"utf8"})) as Setting;
|
||||
let ret = JSON.parse(readFileSync("settings.json",{encoding:"utf8"})) as Setting;
|
||||
const diff_occur = setEmptyToDefault(ret,default_setting);
|
||||
if(diff_occur){
|
||||
writeFileSync("settings.json",JSON.stringify(ret));
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
export function get_setting():Setting{
|
||||
if(setting === null){
|
||||
|
Loading…
Reference in New Issue
Block a user