mirror of
https://github.com/pawelmalak/flame.git
synced 2025-07-25 05:49:36 +02:00
Server: Reimplemented config system
This commit is contained in:
parent
85ee5da025
commit
b7de1e3d27
6 changed files with 107 additions and 114 deletions
|
@ -2,8 +2,8 @@ const initConfig = require('./initConfig');
|
|||
const initFiles = require('./initFiles');
|
||||
|
||||
const initApp = async () => {
|
||||
await initConfig();
|
||||
await initFiles();
|
||||
await initConfig();
|
||||
};
|
||||
|
||||
module.exports = initApp;
|
||||
|
|
|
@ -1,39 +1,25 @@
|
|||
const { Op } = require('sequelize');
|
||||
const Config = require('../../models/Config');
|
||||
const { config } = require('./initialConfig.json');
|
||||
|
||||
const Logger = require('../Logger');
|
||||
const logger = new Logger();
|
||||
const { copyFile, readFile, writeFile } = require('fs/promises');
|
||||
const checkFileExists = require('../checkFileExists');
|
||||
const initialConfig = require('./initialConfig.json');
|
||||
|
||||
const initConfig = async () => {
|
||||
// Get config values
|
||||
const configPairs = await Config.findAll({
|
||||
where: {
|
||||
key: {
|
||||
[Op.or]: config.map((pair) => pair.key),
|
||||
},
|
||||
},
|
||||
});
|
||||
const configExists = await checkFileExists('data/config.json');
|
||||
|
||||
// Get key from each pair
|
||||
const configKeys = configPairs.map((pair) => pair.key);
|
||||
|
||||
// Create missing pairs
|
||||
config.forEach(async ({ key, value }) => {
|
||||
if (!configKeys.includes(key)) {
|
||||
await Config.create({
|
||||
key,
|
||||
value,
|
||||
valueType: typeof value,
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
if (process.env.NODE_ENV == 'development') {
|
||||
logger.log('Initial config created');
|
||||
if (!configExists) {
|
||||
await copyFile('utils/init/initialConfig.json', 'data/config.json');
|
||||
}
|
||||
|
||||
return;
|
||||
const existingConfig = await readFile('data/config.json', 'utf-8');
|
||||
const parsedConfig = JSON.parse(existingConfig);
|
||||
|
||||
// Add new config pairs if necessary
|
||||
for (let key in initialConfig) {
|
||||
if (!Object.keys(parsedConfig).includes(key)) {
|
||||
parsedConfig[key] = initialConfig[key];
|
||||
}
|
||||
}
|
||||
|
||||
await writeFile('data/config.json', JSON.stringify(parsedConfig));
|
||||
};
|
||||
|
||||
module.exports = initConfig;
|
||||
|
|
|
@ -1,84 +1,22 @@
|
|||
{
|
||||
"config": [
|
||||
{
|
||||
"key": "WEATHER_API_KEY",
|
||||
"value": ""
|
||||
},
|
||||
{
|
||||
"key": "lat",
|
||||
"value": 0
|
||||
},
|
||||
{
|
||||
"key": "long",
|
||||
"value": 0
|
||||
},
|
||||
{
|
||||
"key": "isCelsius",
|
||||
"value": true
|
||||
},
|
||||
{
|
||||
"key": "customTitle",
|
||||
"value": "Flame"
|
||||
},
|
||||
{
|
||||
"key": "pinAppsByDefault",
|
||||
"value": true
|
||||
},
|
||||
{
|
||||
"key": "pinCategoriesByDefault",
|
||||
"value": true
|
||||
},
|
||||
{
|
||||
"key": "hideHeader",
|
||||
"value": false
|
||||
},
|
||||
{
|
||||
"key": "useOrdering",
|
||||
"value": "createdAt"
|
||||
},
|
||||
{
|
||||
"key": "appsSameTab",
|
||||
"value": false
|
||||
},
|
||||
{
|
||||
"key": "bookmarksSameTab",
|
||||
"value": false
|
||||
},
|
||||
{
|
||||
"key": "searchSameTab",
|
||||
"value": false
|
||||
},
|
||||
{
|
||||
"key": "hideApps",
|
||||
"value": false
|
||||
},
|
||||
{
|
||||
"key": "hideCategories",
|
||||
"value": false
|
||||
},
|
||||
{
|
||||
"key": "hideSearch",
|
||||
"value": false
|
||||
},
|
||||
{
|
||||
"key": "defaultSearchProvider",
|
||||
"value": "l"
|
||||
},
|
||||
{
|
||||
"key": "dockerApps",
|
||||
"value": false
|
||||
},
|
||||
{
|
||||
"key": "dockerHost",
|
||||
"value": "localhost"
|
||||
},
|
||||
{
|
||||
"key": "kubernetesApps",
|
||||
"value": false
|
||||
},
|
||||
{
|
||||
"key": "unpinStoppedApps",
|
||||
"value": false
|
||||
}
|
||||
]
|
||||
"WEATHER_API_KEY": "",
|
||||
"lat": 0,
|
||||
"long": 0,
|
||||
"isCelsius": true,
|
||||
"customTitle": "Flame",
|
||||
"pinAppsByDefault": true,
|
||||
"pinCategoriesByDefault": true,
|
||||
"hideHeader": false,
|
||||
"useOrdering": "createdAt",
|
||||
"appsSameTab": false,
|
||||
"bookmarksSameTab": false,
|
||||
"searchSameTab": false,
|
||||
"hideApps": false,
|
||||
"hideCategories": false,
|
||||
"hideSearch": false,
|
||||
"defaultSearchProvider": "l",
|
||||
"dockerApps": false,
|
||||
"dockerHost": "localhost",
|
||||
"kubernetesApps": false,
|
||||
"unpinStoppedApps": false
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue