mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-21 03:36:01 +00:00
settings optimalization
This commit is contained in:
@@ -9,6 +9,16 @@ const currentVersion = require('../currentVersion');
|
|||||||
const platformInfo = require('../utility/platformInfo');
|
const platformInfo = require('../utility/platformInfo');
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
|
settingsValue: {},
|
||||||
|
|
||||||
|
async _init() {
|
||||||
|
try {
|
||||||
|
this.settingsValue = JSON.parse(await fs.readFile(path.join(datadir(), 'settings.json'), { encoding: 'utf-8' }));
|
||||||
|
} catch (err) {
|
||||||
|
this.settingsValue = {};
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
get_meta: 'get',
|
get_meta: 'get',
|
||||||
async get() {
|
async get() {
|
||||||
// const toolbarButtons = process.env.TOOLBAR;
|
// const toolbarButtons = process.env.TOOLBAR;
|
||||||
@@ -47,23 +57,19 @@ module.exports = {
|
|||||||
|
|
||||||
getSettings_meta: 'get',
|
getSettings_meta: 'get',
|
||||||
async getSettings() {
|
async getSettings() {
|
||||||
try {
|
return this.settingsValue;
|
||||||
return JSON.parse(await fs.readFile(path.join(datadir(), 'settings.json'), { encoding: 'utf-8' }));
|
|
||||||
} catch (err) {
|
|
||||||
return {};
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
|
|
||||||
updateSettings_meta: 'post',
|
updateSettings_meta: 'post',
|
||||||
async updateSettings(values) {
|
async updateSettings(values) {
|
||||||
if (!hasPermission(`settings/change`)) return false;
|
if (!hasPermission(`settings/change`)) return false;
|
||||||
const oldSettings = await this.getSettings();
|
|
||||||
try {
|
try {
|
||||||
const updated = {
|
const updated = {
|
||||||
...oldSettings,
|
...this.settingsValue,
|
||||||
...values,
|
...values,
|
||||||
};
|
};
|
||||||
await fs.writeFile(path.join(datadir(), 'settings.json'), JSON.stringify(updated, undefined, 2));
|
await fs.writeFile(path.join(datadir(), 'settings.json'), JSON.stringify(updated, undefined, 2));
|
||||||
|
this.settingsValue = updated;
|
||||||
socket.emitChanged(`settings-changed`);
|
socket.emitChanged(`settings-changed`);
|
||||||
return updated;
|
return updated;
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
|||||||
@@ -80,7 +80,7 @@ module.exports = {
|
|||||||
msgtype: 'connect',
|
msgtype: 'connect',
|
||||||
connection: { ...connection, database },
|
connection: { ...connection, database },
|
||||||
structure: lastClosed ? lastClosed.structure : null,
|
structure: lastClosed ? lastClosed.structure : null,
|
||||||
globalSettings: await config.getSettings()
|
globalSettings: config.settingsValue
|
||||||
});
|
});
|
||||||
return newOpened;
|
return newOpened;
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -66,7 +66,7 @@ module.exports = {
|
|||||||
if (newOpened.disconnected) return;
|
if (newOpened.disconnected) return;
|
||||||
this.close(conid, false);
|
this.close(conid, false);
|
||||||
});
|
});
|
||||||
subprocess.send({ msgtype: 'connect', ...connection, globalSettings: await config.getSettings() });
|
subprocess.send({ msgtype: 'connect', ...connection, globalSettings: config.settingsValue });
|
||||||
return newOpened;
|
return newOpened;
|
||||||
});
|
});
|
||||||
return res;
|
return res;
|
||||||
|
|||||||
Reference in New Issue
Block a user