mirror of
https://github.com/pawelmalak/flame.git
synced 2025-08-04 18:35:17 +02:00
Changed config api. Split config controllers into separate files. Split bookmarks controllers into separate files
This commit is contained in:
parent
76e50624e7
commit
cfb471e578
23 changed files with 579 additions and 602 deletions
18
controllers/config/getCSS.js
Normal file
18
controllers/config/getCSS.js
Normal file
|
@ -0,0 +1,18 @@
|
|||
const asyncWrapper = require('../../middleware/asyncWrapper');
|
||||
const File = require('../../utils/File');
|
||||
const { join } = require('path');
|
||||
|
||||
// @desc Get custom CSS file
|
||||
// @route GET /api/config/0/css
|
||||
// @access Public
|
||||
const getCSS = asyncWrapper(async (req, res, next) => {
|
||||
const file = new File(join(__dirname, '../../public/flame.css'));
|
||||
const content = file.read();
|
||||
|
||||
res.status(200).json({
|
||||
success: true,
|
||||
data: content,
|
||||
});
|
||||
});
|
||||
|
||||
module.exports = getCSS;
|
16
controllers/config/getConfig.js
Normal file
16
controllers/config/getConfig.js
Normal file
|
@ -0,0 +1,16 @@
|
|||
const asyncWrapper = require('../../middleware/asyncWrapper');
|
||||
const loadConfig = require('../../utils/loadConfig');
|
||||
|
||||
// @desc Get config
|
||||
// @route GET /api/config
|
||||
// @access Public
|
||||
const getConfig = asyncWrapper(async (req, res, next) => {
|
||||
const config = await loadConfig();
|
||||
|
||||
res.status(200).json({
|
||||
success: true,
|
||||
data: config,
|
||||
});
|
||||
});
|
||||
|
||||
module.exports = getConfig;
|
6
controllers/config/index.js
Normal file
6
controllers/config/index.js
Normal file
|
@ -0,0 +1,6 @@
|
|||
module.exports = {
|
||||
getCSS: require('./getCSS'),
|
||||
updateCSS: require('./updateCSS'),
|
||||
getConfig: require('./getConfig'),
|
||||
updateConfig: require('./updateConfig'),
|
||||
};
|
24
controllers/config/updateCSS.js
Normal file
24
controllers/config/updateCSS.js
Normal file
|
@ -0,0 +1,24 @@
|
|||
const asyncWrapper = require('../../middleware/asyncWrapper');
|
||||
const File = require('../../utils/File');
|
||||
const { join } = require('path');
|
||||
|
||||
// @desc Update custom CSS file
|
||||
// @route PUT /api/config/0/css
|
||||
// @access Public
|
||||
const updateCSS = asyncWrapper(async (req, res, next) => {
|
||||
const file = new File(join(__dirname, '../../public/flame.css'));
|
||||
file.write(req.body.styles, false);
|
||||
|
||||
// Copy file to docker volume
|
||||
fs.copyFileSync(
|
||||
join(__dirname, '../../public/flame.css'),
|
||||
join(__dirname, '../../data/flame.css')
|
||||
);
|
||||
|
||||
res.status(200).json({
|
||||
success: true,
|
||||
data: {},
|
||||
});
|
||||
});
|
||||
|
||||
module.exports = updateCSS;
|
24
controllers/config/updateConfig.js
Normal file
24
controllers/config/updateConfig.js
Normal file
|
@ -0,0 +1,24 @@
|
|||
const asyncWrapper = require('../../middleware/asyncWrapper');
|
||||
const loadConfig = require('../../utils/loadConfig');
|
||||
const { writeFile } = require('fs/promises');
|
||||
|
||||
// @desc Update config
|
||||
// @route PUT /api/config/
|
||||
// @access Public
|
||||
const updateConfig = asyncWrapper(async (req, res, next) => {
|
||||
const existingConfig = await loadConfig();
|
||||
|
||||
const newConfig = {
|
||||
...existingConfig,
|
||||
...req.body,
|
||||
};
|
||||
|
||||
await writeFile('data/config.json', JSON.stringify(newConfig));
|
||||
|
||||
res.status(200).send({
|
||||
success: true,
|
||||
data: newConfig,
|
||||
});
|
||||
});
|
||||
|
||||
module.exports = updateConfig;
|
Loading…
Add table
Add a link
Reference in a new issue