29 lines
636 B
JavaScript
29 lines
636 B
JavaScript
import fs from 'fs';
|
|
import path from 'path';
|
|
import service from '../core/BaseService.js';
|
|
const __dirname = path.dirname(decodeURIComponent(new URL(import.meta.url).pathname.replace(/^\//, '')));
|
|
const configPath = path.join(__dirname, '../config.json');
|
|
|
|
class ConfigService extends service {
|
|
constructor() {
|
|
super();
|
|
}
|
|
|
|
read() {
|
|
try {
|
|
return JSON.parse(fs.readFileSync(configPath, 'utf-8'));
|
|
} catch {
|
|
return {};
|
|
}
|
|
}
|
|
|
|
write(newConfig) {
|
|
try {
|
|
fs.writeFileSync(configPath, JSON.stringify(newConfig, null, 2), 'utf-8');
|
|
return true;
|
|
} catch {
|
|
return false;
|
|
}
|
|
}
|
|
};
|