2018-06-03 01:02:20 +08:00
|
|
|
import server from "./server.js";
|
|
|
|
|
2019-05-13 03:45:30 +08:00
|
|
|
const loadListeners = [];
|
|
|
|
|
2019-08-23 05:31:02 +08:00
|
|
|
class Options {
|
2020-02-06 05:08:45 +08:00
|
|
|
load(arr) {
|
2019-08-23 05:31:02 +08:00
|
|
|
this.arr = arr;
|
|
|
|
}
|
|
|
|
|
|
|
|
get(key) {
|
|
|
|
return this.arr[key];
|
|
|
|
}
|
|
|
|
|
2019-11-20 03:53:04 +08:00
|
|
|
getNames() {
|
|
|
|
return Object.keys(this.arr);
|
|
|
|
}
|
|
|
|
|
2019-08-23 05:31:02 +08:00
|
|
|
getJson(key) {
|
|
|
|
try {
|
|
|
|
return JSON.parse(this.arr[key]);
|
|
|
|
}
|
|
|
|
catch (e) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
getInt(key) {
|
|
|
|
return parseInt(this.arr[key]);
|
|
|
|
}
|
|
|
|
|
|
|
|
getFloat(key) {
|
|
|
|
return parseFloat(this.arr[key]);
|
|
|
|
}
|
|
|
|
|
|
|
|
is(key) {
|
|
|
|
return this.arr[key] === 'true';
|
|
|
|
}
|
|
|
|
|
2020-02-06 05:08:45 +08:00
|
|
|
set(key, value) {
|
|
|
|
this.arr[key] = value;
|
|
|
|
}
|
2019-05-13 03:45:30 +08:00
|
|
|
|
2020-02-06 05:08:45 +08:00
|
|
|
async save(key, value) {
|
|
|
|
this.set(key, value);
|
2019-08-23 05:31:02 +08:00
|
|
|
|
2020-02-06 05:08:45 +08:00
|
|
|
const payload = {};
|
|
|
|
payload[key] = value;
|
2019-08-23 05:31:02 +08:00
|
|
|
|
2020-02-06 05:08:45 +08:00
|
|
|
await server.put(`options`, payload);
|
|
|
|
}
|
2019-05-13 03:45:30 +08:00
|
|
|
}
|
|
|
|
|
2020-02-06 05:08:45 +08:00
|
|
|
const options = new Options();
|
2018-06-03 01:02:20 +08:00
|
|
|
|
2020-02-06 05:08:45 +08:00
|
|
|
export default options;
|