代码拉取完成,页面将自动刷新
const fs = require("fs");
class Config {
constructor(path) {
this.path = path;
this.uname = null;
this.password = null;
this.speed = null;
this.pick = null;
this.test = null;
this.pickinfos = null;
}
async write() {
const c = {
"uname": this.uname,
"password": this.password,
"speed": this.speed,
"test": this.test,
"pick": this.pick,
"pickinfos": this.pickinfos
}
const config = JSON.stringify(c, null,"\t")
return await fs.promises.writeFile(this.path,config,{
encoding: "utf8"
})
}
async read(path) {
const config = {
speed: 2,
pick: false,
test: true
}
return await fs.promises.readFile(this.path,{
encoding: "utf8"
}).then(c=>{
try {
Object.assign(config, JSON.parse(c));
for(const key in config)
this[key] = config[key]
return this;
} catch(e) {
console.error(e);
process.exit(0);
}
}).catch(e=>{
// console.error(e);
console.log("读取失败或者目录下不存在配置文件")
return this;
})
}
}
module.exports = Config;
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。