mirror of
https://github.com/pawelmalak/flame.git
synced 2025-07-25 05:49:36 +02:00
API routes to edit and delete custom themes. Added ThemeEditor table
This commit is contained in:
parent
bd96f6ca50
commit
ad92de141b
5 changed files with 107 additions and 3 deletions
22
controllers/themes/deleteTheme.js
Normal file
22
controllers/themes/deleteTheme.js
Normal file
|
@ -0,0 +1,22 @@
|
|||
const asyncWrapper = require('../../middleware/asyncWrapper');
|
||||
const File = require('../../utils/File');
|
||||
|
||||
// @desc Delete theme
|
||||
// @route DELETE /api/themes/:name
|
||||
// @access Public
|
||||
const deleteTheme = asyncWrapper(async (req, res, next) => {
|
||||
const file = new File('data/themes.json');
|
||||
let content = JSON.parse(file.read());
|
||||
|
||||
content.themes = content.themes.filter((t) => t.name != req.params.name);
|
||||
file.write(content, true);
|
||||
|
||||
const userThemes = content.themes.filter((t) => t.isCustom);
|
||||
|
||||
res.status(200).json({
|
||||
success: true,
|
||||
data: userThemes,
|
||||
});
|
||||
});
|
||||
|
||||
module.exports = deleteTheme;
|
|
@ -1,4 +1,6 @@
|
|||
module.exports = {
|
||||
getThemes: require('./getThemes'),
|
||||
addTheme: require('./addTheme'),
|
||||
deleteTheme: require('./deleteTheme'),
|
||||
updateTheme: require('./updateTheme'),
|
||||
};
|
||||
|
|
32
controllers/themes/updateTheme.js
Normal file
32
controllers/themes/updateTheme.js
Normal file
|
@ -0,0 +1,32 @@
|
|||
const asyncWrapper = require('../../middleware/asyncWrapper');
|
||||
const File = require('../../utils/File');
|
||||
|
||||
// @desc Update theme
|
||||
// @route PUT /api/themes/:name
|
||||
// @access Public
|
||||
const updateTheme = asyncWrapper(async (req, res, next) => {
|
||||
const file = new File('data/themes.json');
|
||||
let content = JSON.parse(file.read());
|
||||
|
||||
let themeIdx = content.themes.findIndex((t) => t.name == req.params.name);
|
||||
|
||||
// theme found
|
||||
if (themeIdx > -1) {
|
||||
content.themes = [
|
||||
...content.themes.slice(0, themeIdx),
|
||||
req.body,
|
||||
...content.themes.slice(themeIdx + 1),
|
||||
];
|
||||
}
|
||||
|
||||
file.write(content, true);
|
||||
|
||||
const userThemes = content.themes.filter((t) => t.isCustom);
|
||||
|
||||
res.status(200).json({
|
||||
success: true,
|
||||
data: userThemes,
|
||||
});
|
||||
});
|
||||
|
||||
module.exports = updateTheme;
|
Loading…
Add table
Add a link
Reference in a new issue