mirror of
https://github.com/pawelmalak/flame.git
synced 2025-07-23 05:19:37 +02:00
Server: Reimplemented config system
This commit is contained in:
parent
85ee5da025
commit
b7de1e3d27
6 changed files with 107 additions and 114 deletions
41
db/migrations/01_new-config.js
Normal file
41
db/migrations/01_new-config.js
Normal file
|
@ -0,0 +1,41 @@
|
|||
const { DataTypes } = require('sequelize');
|
||||
const { INTEGER, DATE, STRING, TINYINT, FLOAT, TEXT } = DataTypes;
|
||||
const { readFile, writeFile, copyFile } = require('fs/promises');
|
||||
const Config = require('../../models/Config');
|
||||
|
||||
const up = async (query) => {
|
||||
await copyFile('utils/init/initialConfig.json', 'data/config.json');
|
||||
|
||||
const initConfigFile = await readFile('data/config.json', 'utf-8');
|
||||
const parsedNewConfig = JSON.parse(initConfigFile);
|
||||
|
||||
const existingConfig = await Config.findAll({ raw: true });
|
||||
|
||||
for (let pair of existingConfig) {
|
||||
const { key, value, valueType } = pair;
|
||||
|
||||
let newValue = value;
|
||||
|
||||
if (valueType == 'number') {
|
||||
newValue = parseFloat(value);
|
||||
} else if (valueType == 'boolean') {
|
||||
newValue = value == 1;
|
||||
}
|
||||
|
||||
parsedNewConfig[key] = newValue;
|
||||
}
|
||||
|
||||
const newConfig = JSON.stringify(parsedNewConfig);
|
||||
await writeFile('data/config.json', newConfig);
|
||||
|
||||
// await query.dropTable('config');
|
||||
};
|
||||
|
||||
const down = async (query) => {
|
||||
// await query.dropTable('config');
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
up,
|
||||
down,
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue