Pushed version 1.6.7

This commit is contained in:
unknown 2021-10-04 12:11:41 +02:00
parent 4252457871
commit 6a6f1750b1
7 changed files with 217 additions and 162 deletions

View File

@ -1,3 +1,7 @@
### v1.6.7 (2021-10-04)
- Add multiple labels to Docker Compose ([#90](https://github.com/pawelmalak/flame/issues/90))
- Custom icons via Docker Compose labels ([#91](https://github.com/pawelmalak/flame/issues/91))
### v1.6.6 (2021-09-06) ### v1.6.6 (2021-09-06)
- Added local search (filter) for apps and bookmarks ([#47](https://github.com/pawelmalak/flame/issues/47)) - Added local search (filter) for apps and bookmarks ([#47](https://github.com/pawelmalak/flame/issues/47))

View File

@ -1 +1 @@
REACT_APP_VERSION=1.6.6 REACT_APP_VERSION=1.6.7

View File

@ -14,7 +14,7 @@ const k8s = require('@kubernetes/client-node');
exports.createApp = asyncWrapper(async (req, res, next) => { exports.createApp = asyncWrapper(async (req, res, next) => {
// Get config from database // Get config from database
const pinApps = await Config.findOne({ const pinApps = await Config.findOne({
where: { key: 'pinAppsByDefault' } where: { key: 'pinAppsByDefault' },
}); });
let app; let app;
@ -28,7 +28,7 @@ exports.createApp = asyncWrapper(async (req, res, next) => {
if (parseInt(pinApps.value)) { if (parseInt(pinApps.value)) {
app = await App.create({ app = await App.create({
..._body, ..._body,
isPinned: true isPinned: true,
}); });
} else { } else {
app = await App.create(req.body); app = await App.create(req.body);
@ -37,7 +37,7 @@ exports.createApp = asyncWrapper(async (req, res, next) => {
res.status(201).json({ res.status(201).json({
success: true, success: true,
data: app data: app,
}); });
}); });
@ -47,16 +47,16 @@ exports.createApp = asyncWrapper(async (req, res, next) => {
exports.getApps = asyncWrapper(async (req, res, next) => { exports.getApps = asyncWrapper(async (req, res, next) => {
// Get config from database // Get config from database
const useOrdering = await Config.findOne({ const useOrdering = await Config.findOne({
where: { key: 'useOrdering' } where: { key: 'useOrdering' },
}); });
const useDockerApi = await Config.findOne({ const useDockerApi = await Config.findOne({
where: { key: 'dockerApps' } where: { key: 'dockerApps' },
}); });
const useKubernetesApi = await Config.findOne({ const useKubernetesApi = await Config.findOne({
where: { key: 'kubernetesApps' } where: { key: 'kubernetesApps' },
}); });
const unpinStoppedApps = await Config.findOne({ const unpinStoppedApps = await Config.findOne({
where: { key: 'unpinStoppedApps' } where: { key: 'unpinStoppedApps' },
}); });
const orderType = useOrdering ? useOrdering.value : 'createdAt'; const orderType = useOrdering ? useOrdering.value : 'createdAt';
@ -69,7 +69,7 @@ exports.getApps = asyncWrapper(async (req, res, next) => {
let { data } = await axios.get( let { data } = await axios.get(
'http://localhost/containers/json?{"status":["running"]}', 'http://localhost/containers/json?{"status":["running"]}',
{ {
socketPath: '/var/run/docker.sock' socketPath: '/var/run/docker.sock',
} }
); );
containers = data; containers = data;
@ -79,10 +79,10 @@ exports.getApps = asyncWrapper(async (req, res, next) => {
if (containers) { if (containers) {
apps = await App.findAll({ apps = await App.findAll({
order: [[orderType, 'ASC']] order: [[orderType, 'ASC']],
}); });
containers = containers.filter(e => Object.keys(e.Labels).length !== 0); containers = containers.filter((e) => Object.keys(e.Labels).length !== 0);
const dockerApps = []; const dockerApps = [];
for (const container of containers) { for (const container of containers) {
const labels = container.Labels; const labels = container.Labels;
@ -92,17 +92,16 @@ exports.getApps = asyncWrapper(async (req, res, next) => {
'flame.url' in labels && 'flame.url' in labels &&
/^app/.test(labels['flame.type']) /^app/.test(labels['flame.type'])
) { ) {
for (let i = 0; i < labels['flame.name'].split(';').length; i++) {
for (let i=0; i < labels['flame.name'].split(';').length; i++) {
const names = labels['flame.name'].split(';'); const names = labels['flame.name'].split(';');
const urls = labels['flame.url'].split(';'); const urls = labels['flame.url'].split(';');
const icons = labels['flame.icon'].split(';'); const icons = labels['flame.icon'].split(';');
dockerApps.push({ dockerApps.push({
name: names[i] || names[0], name: names[i] || names[0],
url: urls[i] || urls[0], url: urls[i] || urls[0],
icon: icons[i] || 'docker' icon: icons[i] || 'docker',
}); });
} }
} }
} }
@ -116,7 +115,7 @@ exports.getApps = asyncWrapper(async (req, res, next) => {
if (apps.some((app) => app.name === item.name)) { if (apps.some((app) => app.name === item.name)) {
const app = apps.filter((e) => e.name === item.name)[0]; const app = apps.filter((e) => e.name === item.name)[0];
if(item.icon === 'custom') { if (item.icon === 'custom') {
await app.update({ await app.update({
name: item.name, name: item.name,
url: item.url, url: item.url,
@ -149,9 +148,8 @@ exports.getApps = asyncWrapper(async (req, res, next) => {
const kc = new k8s.KubeConfig(); const kc = new k8s.KubeConfig();
kc.loadFromCluster(); kc.loadFromCluster();
const k8sNetworkingV1Api = kc.makeApiClient(k8s.NetworkingV1Api); const k8sNetworkingV1Api = kc.makeApiClient(k8s.NetworkingV1Api);
await k8sNetworkingV1Api.listIngressForAllNamespaces() await k8sNetworkingV1Api.listIngressForAllNamespaces().then((res) => {
.then((res) => { ingresses = res.body.items;
ingresses = res.body.items;
}); });
} catch { } catch {
logger.log("Can't connect to the kubernetes api", 'ERROR'); logger.log("Can't connect to the kubernetes api", 'ERROR');
@ -159,10 +157,12 @@ exports.getApps = asyncWrapper(async (req, res, next) => {
if (ingresses) { if (ingresses) {
apps = await App.findAll({ apps = await App.findAll({
order: [[orderType, 'ASC']] order: [[orderType, 'ASC']],
}); });
ingresses = ingresses.filter(e => Object.keys(e.metadata.annotations).length !== 0); ingresses = ingresses.filter(
(e) => Object.keys(e.metadata.annotations).length !== 0
);
const kubernetesApps = []; const kubernetesApps = [];
for (const ingress of ingresses) { for (const ingress of ingresses) {
const annotations = ingress.metadata.annotations; const annotations = ingress.metadata.annotations;
@ -175,7 +175,7 @@ exports.getApps = asyncWrapper(async (req, res, next) => {
kubernetesApps.push({ kubernetesApps.push({
name: annotations['flame.pawelmalak/name'], name: annotations['flame.pawelmalak/name'],
url: annotations['flame.pawelmalak/url'], url: annotations['flame.pawelmalak/url'],
icon: annotations['flame.pawelmalak/icon'] || 'kubernetes' icon: annotations['flame.pawelmalak/icon'] || 'kubernetes',
}); });
} }
} }
@ -187,13 +187,13 @@ exports.getApps = asyncWrapper(async (req, res, next) => {
} }
for (const item of kubernetesApps) { for (const item of kubernetesApps) {
if (apps.some(app => app.name === item.name)) { if (apps.some((app) => app.name === item.name)) {
const app = apps.filter(e => e.name === item.name)[0]; const app = apps.filter((e) => e.name === item.name)[0];
await app.update({ ...item, isPinned: true }); await app.update({ ...item, isPinned: true });
} else { } else {
await App.create({ await App.create({
...item, ...item,
isPinned: true isPinned: true,
}); });
} }
} }
@ -202,11 +202,11 @@ exports.getApps = asyncWrapper(async (req, res, next) => {
if (orderType == 'name') { if (orderType == 'name') {
apps = await App.findAll({ apps = await App.findAll({
order: [[Sequelize.fn('lower', Sequelize.col('name')), 'ASC']] order: [[Sequelize.fn('lower', Sequelize.col('name')), 'ASC']],
}); });
} else { } else {
apps = await App.findAll({ apps = await App.findAll({
order: [[orderType, 'ASC']] order: [[orderType, 'ASC']],
}); });
} }
@ -214,14 +214,14 @@ exports.getApps = asyncWrapper(async (req, res, next) => {
// Set header to fetch containers info every time // Set header to fetch containers info every time
res.status(200).setHeader('Cache-Control', 'no-store').json({ res.status(200).setHeader('Cache-Control', 'no-store').json({
success: true, success: true,
data: apps data: apps,
}); });
return; return;
} }
res.status(200).json({ res.status(200).json({
success: true, success: true,
data: apps data: apps,
}); });
}); });
@ -230,7 +230,7 @@ exports.getApps = asyncWrapper(async (req, res, next) => {
// @access Public // @access Public
exports.getApp = asyncWrapper(async (req, res, next) => { exports.getApp = asyncWrapper(async (req, res, next) => {
const app = await App.findOne({ const app = await App.findOne({
where: { id: req.params.id } where: { id: req.params.id },
}); });
if (!app) { if (!app) {
@ -241,7 +241,7 @@ exports.getApp = asyncWrapper(async (req, res, next) => {
res.status(200).json({ res.status(200).json({
success: true, success: true,
data: app data: app,
}); });
}); });
@ -250,7 +250,7 @@ exports.getApp = asyncWrapper(async (req, res, next) => {
// @access Public // @access Public
exports.updateApp = asyncWrapper(async (req, res, next) => { exports.updateApp = asyncWrapper(async (req, res, next) => {
let app = await App.findOne({ let app = await App.findOne({
where: { id: req.params.id } where: { id: req.params.id },
}); });
if (!app) { if (!app) {
@ -269,7 +269,7 @@ exports.updateApp = asyncWrapper(async (req, res, next) => {
res.status(200).json({ res.status(200).json({
success: true, success: true,
data: app data: app,
}); });
}); });
@ -278,12 +278,12 @@ exports.updateApp = asyncWrapper(async (req, res, next) => {
// @access Public // @access Public
exports.deleteApp = asyncWrapper(async (req, res, next) => { exports.deleteApp = asyncWrapper(async (req, res, next) => {
await App.destroy({ await App.destroy({
where: { id: req.params.id } where: { id: req.params.id },
}); });
res.status(200).json({ res.status(200).json({
success: true, success: true,
data: {} data: {},
}); });
}); });
@ -295,13 +295,13 @@ exports.reorderApps = asyncWrapper(async (req, res, next) => {
await App.update( await App.update(
{ orderId }, { orderId },
{ {
where: { id } where: { id },
} }
); );
}); });
res.status(200).json({ res.status(200).json({
success: true, success: true,
data: {} data: {},
}); });
}); });

View File

@ -11,7 +11,7 @@ exports.createBookmark = asyncWrapper(async (req, res, next) => {
let _body = { let _body = {
...req.body, ...req.body,
categoryId: parseInt(req.body.categoryId) categoryId: parseInt(req.body.categoryId),
}; };
if (req.file) { if (req.file) {
@ -22,57 +22,67 @@ exports.createBookmark = asyncWrapper(async (req, res, next) => {
res.status(201).json({ res.status(201).json({
success: true, success: true,
data: bookmark data: bookmark,
}) });
}) });
// @desc Get all bookmarks // @desc Get all bookmarks
// @route GET /api/bookmarks // @route GET /api/bookmarks
// @access Public // @access Public
exports.getBookmarks = asyncWrapper(async (req, res, next) => { exports.getBookmarks = asyncWrapper(async (req, res, next) => {
const bookmarks = await Bookmark.findAll({ const bookmarks = await Bookmark.findAll({
order: [[ Sequelize.fn('lower', Sequelize.col('name')), 'ASC' ]] order: [[Sequelize.fn('lower', Sequelize.col('name')), 'ASC']],
}); });
res.status(200).json({ res.status(200).json({
success: true, success: true,
data: bookmarks data: bookmarks,
}) });
}) });
// @desc Get single bookmark // @desc Get single bookmark
// @route GET /api/bookmarks/:id // @route GET /api/bookmarks/:id
// @access Public // @access Public
exports.getBookmark = asyncWrapper(async (req, res, next) => { exports.getBookmark = asyncWrapper(async (req, res, next) => {
const bookmark = await Bookmark.findOne({ const bookmark = await Bookmark.findOne({
where: { id: req.params.id } where: { id: req.params.id },
}); });
if (!bookmark) { if (!bookmark) {
return next(new ErrorResponse(`Bookmark with id of ${req.params.id} was not found`, 404)); return next(
new ErrorResponse(
`Bookmark with id of ${req.params.id} was not found`,
404
)
);
} }
res.status(200).json({ res.status(200).json({
success: true, success: true,
data: bookmark data: bookmark,
}) });
}) });
// @desc Update bookmark // @desc Update bookmark
// @route PUT /api/bookmarks/:id // @route PUT /api/bookmarks/:id
// @access Public // @access Public
exports.updateBookmark = asyncWrapper(async (req, res, next) => { exports.updateBookmark = asyncWrapper(async (req, res, next) => {
let bookmark = await Bookmark.findOne({ let bookmark = await Bookmark.findOne({
where: { id: req.params.id } where: { id: req.params.id },
}); });
if (!bookmark) { if (!bookmark) {
return next(new ErrorResponse(`Bookmark with id of ${req.params.id} was not found`, 404)); return next(
new ErrorResponse(
`Bookmark with id of ${req.params.id} was not found`,
404
)
);
} }
let _body = { let _body = {
...req.body, ...req.body,
categoryId: parseInt(req.body.categoryId) categoryId: parseInt(req.body.categoryId),
}; };
if (req.file) { if (req.file) {
@ -83,20 +93,20 @@ exports.updateBookmark = asyncWrapper(async (req, res, next) => {
res.status(200).json({ res.status(200).json({
success: true, success: true,
data: bookmark data: bookmark,
}) });
}) });
// @desc Delete bookmark // @desc Delete bookmark
// @route DELETE /api/bookmarks/:id // @route DELETE /api/bookmarks/:id
// @access Public // @access Public
exports.deleteBookmark = asyncWrapper(async (req, res, next) => { exports.deleteBookmark = asyncWrapper(async (req, res, next) => {
await Bookmark.destroy({ await Bookmark.destroy({
where: { id: req.params.id } where: { id: req.params.id },
}); });
res.status(200).json({ res.status(200).json({
success: true, success: true,
data: {} data: {},
}) });
}) });

View File

@ -3,7 +3,7 @@ const ErrorResponse = require('../utils/ErrorResponse');
const Category = require('../models/Category'); const Category = require('../models/Category');
const Bookmark = require('../models/Bookmark'); const Bookmark = require('../models/Bookmark');
const Config = require('../models/Config'); const Config = require('../models/Config');
const { Sequelize } = require('sequelize') const { Sequelize } = require('sequelize');
// @desc Create new category // @desc Create new category
// @route POST /api/categories // @route POST /api/categories
@ -11,7 +11,7 @@ const { Sequelize } = require('sequelize')
exports.createCategory = asyncWrapper(async (req, res, next) => { exports.createCategory = asyncWrapper(async (req, res, next) => {
// Get config from database // Get config from database
const pinCategories = await Config.findOne({ const pinCategories = await Config.findOne({
where: { key: 'pinCategoriesByDefault' } where: { key: 'pinCategoriesByDefault' },
}); });
let category; let category;
@ -20,8 +20,8 @@ exports.createCategory = asyncWrapper(async (req, res, next) => {
if (parseInt(pinCategories.value)) { if (parseInt(pinCategories.value)) {
category = await Category.create({ category = await Category.create({
...req.body, ...req.body,
isPinned: true isPinned: true,
}) });
} else { } else {
category = await Category.create(req.body); category = await Category.create(req.body);
} }
@ -29,9 +29,9 @@ exports.createCategory = asyncWrapper(async (req, res, next) => {
res.status(201).json({ res.status(201).json({
success: true, success: true,
data: category data: category,
}) });
}) });
// @desc Get all categories // @desc Get all categories
// @route GET /api/categories // @route GET /api/categories
@ -39,7 +39,7 @@ exports.createCategory = asyncWrapper(async (req, res, next) => {
exports.getCategories = asyncWrapper(async (req, res, next) => { exports.getCategories = asyncWrapper(async (req, res, next) => {
// Get config from database // Get config from database
const useOrdering = await Config.findOne({ const useOrdering = await Config.findOne({
where: { key: 'useOrdering' } where: { key: 'useOrdering' },
}); });
const orderType = useOrdering ? useOrdering.value : 'createdAt'; const orderType = useOrdering ? useOrdering.value : 'createdAt';
@ -47,27 +47,31 @@ exports.getCategories = asyncWrapper(async (req, res, next) => {
if (orderType == 'name') { if (orderType == 'name') {
categories = await Category.findAll({ categories = await Category.findAll({
include: [{ include: [
model: Bookmark, {
as: 'bookmarks' model: Bookmark,
}], as: 'bookmarks',
order: [[ Sequelize.fn('lower', Sequelize.col('Category.name')), 'ASC' ]] },
],
order: [[Sequelize.fn('lower', Sequelize.col('Category.name')), 'ASC']],
}); });
} else { } else {
categories = await Category.findAll({ categories = await Category.findAll({
include: [{ include: [
model: Bookmark, {
as: 'bookmarks' model: Bookmark,
}], as: 'bookmarks',
order: [[ orderType, 'ASC' ]] },
],
order: [[orderType, 'ASC']],
}); });
} }
res.status(200).json({ res.status(200).json({
success: true, success: true,
data: categories data: categories,
}) });
}) });
// @desc Get single category // @desc Get single category
// @route GET /api/categories/:id // @route GET /api/categories/:id
@ -75,41 +79,53 @@ exports.getCategories = asyncWrapper(async (req, res, next) => {
exports.getCategory = asyncWrapper(async (req, res, next) => { exports.getCategory = asyncWrapper(async (req, res, next) => {
const category = await Category.findOne({ const category = await Category.findOne({
where: { id: req.params.id }, where: { id: req.params.id },
include: [{ include: [
model: Bookmark, {
as: 'bookmarks' model: Bookmark,
}] as: 'bookmarks',
},
],
}); });
if (!category) { if (!category) {
return next(new ErrorResponse(`Category with id of ${req.params.id} was not found`, 404)) return next(
new ErrorResponse(
`Category with id of ${req.params.id} was not found`,
404
)
);
} }
res.status(200).json({ res.status(200).json({
success: true, success: true,
data: category data: category,
}) });
}) });
// @desc Update category // @desc Update category
// @route PUT /api/categories/:id // @route PUT /api/categories/:id
// @access Public // @access Public
exports.updateCategory = asyncWrapper(async (req, res, next) => { exports.updateCategory = asyncWrapper(async (req, res, next) => {
let category = await Category.findOne({ let category = await Category.findOne({
where: { id: req.params.id } where: { id: req.params.id },
}); });
if (!category) { if (!category) {
return next(new ErrorResponse(`Category with id of ${req.params.id} was not found`, 404)) return next(
new ErrorResponse(
`Category with id of ${req.params.id} was not found`,
404
)
);
} }
category = await category.update({ ...req.body }); category = await category.update({ ...req.body });
res.status(200).json({ res.status(200).json({
success: true, success: true,
data: category data: category,
}) });
}) });
// @desc Delete category // @desc Delete category
// @route DELETE /api/categories/:id // @route DELETE /api/categories/:id
@ -117,44 +133,54 @@ exports.updateCategory = asyncWrapper(async (req, res, next) => {
exports.deleteCategory = asyncWrapper(async (req, res, next) => { exports.deleteCategory = asyncWrapper(async (req, res, next) => {
const category = await Category.findOne({ const category = await Category.findOne({
where: { id: req.params.id }, where: { id: req.params.id },
include: [{ include: [
model: Bookmark, {
as: 'bookmarks' model: Bookmark,
}] as: 'bookmarks',
},
],
}); });
if (!category) { if (!category) {
return next(new ErrorResponse(`Category with id of ${req.params.id} was not found`, 404)) return next(
new ErrorResponse(
`Category with id of ${req.params.id} was not found`,
404
)
);
} }
category.bookmarks.forEach(async (bookmark) => { category.bookmarks.forEach(async (bookmark) => {
await Bookmark.destroy({ await Bookmark.destroy({
where: { id: bookmark.id } where: { id: bookmark.id },
}) });
}) });
await Category.destroy({ await Category.destroy({
where: { id: req.params.id } where: { id: req.params.id },
}) });
res.status(200).json({ res.status(200).json({
success: true, success: true,
data: {} data: {},
}) });
}) });
// @desc Reorder categories // @desc Reorder categories
// @route PUT /api/categories/0/reorder // @route PUT /api/categories/0/reorder
// @access Public // @access Public
exports.reorderCategories = asyncWrapper(async (req, res, next) => { exports.reorderCategories = asyncWrapper(async (req, res, next) => {
req.body.categories.forEach(async ({ id, orderId }) => { req.body.categories.forEach(async ({ id, orderId }) => {
await Category.update({ orderId }, { await Category.update(
where: { id } { orderId },
}) {
}) where: { id },
}
);
});
res.status(200).json({ res.status(200).json({
success: true, success: true,
data: {} data: {},
}) });
}) });

View File

@ -14,9 +14,9 @@ exports.createPair = asyncWrapper(async (req, res, next) => {
res.status(201).json({ res.status(201).json({
success: true, success: true,
data: pair data: pair,
}) });
}) });
// @desc Get all key:value pairs // @desc Get all key:value pairs
// @route GET /api/config // @route GET /api/config
@ -27,14 +27,14 @@ exports.getAllPairs = asyncWrapper(async (req, res, next) => {
if (req.query.keys) { if (req.query.keys) {
// Check for specific keys to get in a single query // Check for specific keys to get in a single query
const keys = req.query.keys const keys = req.query.keys.split(',').map((key) => {
.split(',') return { key };
.map((key) => { return { key } }); });
pairs = await Config.findAll({ pairs = await Config.findAll({
where: { where: {
[Op.or]: keys [Op.or]: keys,
} },
}); });
} else { } else {
// Else get all // Else get all
@ -43,16 +43,16 @@ exports.getAllPairs = asyncWrapper(async (req, res, next) => {
res.status(200).json({ res.status(200).json({
success: true, success: true,
data: pairs data: pairs,
}) });
}) });
// @desc Get single key:value pair // @desc Get single key:value pair
// @route GET /api/config/:key // @route GET /api/config/:key
// @access Public // @access Public
exports.getSinglePair = asyncWrapper(async (req, res, next) => { exports.getSinglePair = asyncWrapper(async (req, res, next) => {
const pair = await Config.findOne({ const pair = await Config.findOne({
where: { key: req.params.key } where: { key: req.params.key },
}); });
if (!pair) { if (!pair) {
@ -61,16 +61,16 @@ exports.getSinglePair = asyncWrapper(async (req, res, next) => {
res.status(200).json({ res.status(200).json({
success: true, success: true,
data: pair data: pair,
}) });
}) });
// @desc Update value // @desc Update value
// @route PUT /api/config/:key // @route PUT /api/config/:key
// @access Public // @access Public
exports.updateValue = asyncWrapper(async (req, res, next) => { exports.updateValue = asyncWrapper(async (req, res, next) => {
let pair = await Config.findOne({ let pair = await Config.findOne({
where: { key: req.params.key } where: { key: req.params.key },
}); });
if (!pair) { if (!pair) {
@ -78,41 +78,49 @@ exports.updateValue = asyncWrapper(async (req, res, next) => {
} }
if (pair.isLocked) { if (pair.isLocked) {
return next(new ErrorResponse(`Value of key ${req.params.key} is locked and can not be changed`, 400)); return next(
new ErrorResponse(
`Value of key ${req.params.key} is locked and can not be changed`,
400
)
);
} }
pair = await pair.update({ ...req.body }); pair = await pair.update({ ...req.body });
res.status(200).json({ res.status(200).json({
success: true, success: true,
data: pair data: pair,
}) });
}) });
// @desc Update multiple values // @desc Update multiple values
// @route PUT /api/config/ // @route PUT /api/config/
// @access Public // @access Public
exports.updateValues = asyncWrapper(async (req, res, next) => { exports.updateValues = asyncWrapper(async (req, res, next) => {
Object.entries(req.body).forEach(async ([key, value]) => { Object.entries(req.body).forEach(async ([key, value]) => {
await Config.update({ value }, { await Config.update(
where: { key } { value },
}) {
}) where: { key },
}
);
});
const config = await Config.findAll(); const config = await Config.findAll();
res.status(200).send({ res.status(200).send({
success: true, success: true,
data: config data: config,
}) });
}) });
// @desc Delete key:value pair // @desc Delete key:value pair
// @route DELETE /api/config/:key // @route DELETE /api/config/:key
// @access Public // @access Public
exports.deletePair = asyncWrapper(async (req, res, next) => { exports.deletePair = asyncWrapper(async (req, res, next) => {
const pair = await Config.findOne({ const pair = await Config.findOne({
where: { key: req.params.key } where: { key: req.params.key },
}); });
if (!pair) { if (!pair) {
@ -120,16 +128,21 @@ exports.deletePair = asyncWrapper(async (req, res, next) => {
} }
if (pair.isLocked) { if (pair.isLocked) {
return next(new ErrorResponse(`Value of key ${req.params.key} is locked and can not be deleted`, 400)); return next(
new ErrorResponse(
`Value of key ${req.params.key} is locked and can not be deleted`,
400
)
);
} }
await pair.destroy(); await pair.destroy();
res.status(200).json({ res.status(200).json({
success: true, success: true,
data: {} data: {},
}) });
}) });
// @desc Get custom CSS file // @desc Get custom CSS file
// @route GET /api/config/0/css // @route GET /api/config/0/css
@ -140,10 +153,9 @@ exports.getCss = asyncWrapper(async (req, res, next) => {
res.status(200).json({ res.status(200).json({
success: true, success: true,
data: content data: content,
}) });
}) });
// @desc Update custom CSS file // @desc Update custom CSS file
// @route PUT /api/config/0/css // @route PUT /api/config/0/css
@ -153,10 +165,13 @@ exports.updateCss = asyncWrapper(async (req, res, next) => {
file.write(req.body.styles); file.write(req.body.styles);
// Copy file to docker volume // Copy file to docker volume
fs.copyFileSync(join(__dirname, '../public/flame.css'), join(__dirname, '../data/flame.css')); fs.copyFileSync(
join(__dirname, '../public/flame.css'),
join(__dirname, '../data/flame.css')
);
res.status(200).json({ res.status(200).json({
success: true, success: true,
data: {} data: {},
}) });
}) });

View File

@ -9,14 +9,14 @@ const getExternalWeather = require('../utils/getExternalWeather');
exports.getWeather = asyncWrapper(async (req, res, next) => { exports.getWeather = asyncWrapper(async (req, res, next) => {
const weather = await Weather.findAll({ const weather = await Weather.findAll({
order: [['createdAt', 'DESC']], order: [['createdAt', 'DESC']],
limit: 1 limit: 1,
}); });
res.status(200).json({ res.status(200).json({
success: true, success: true,
data: weather data: weather,
}) });
}) });
// @desc Update weather // @desc Update weather
// @route GET /api/weather/update // @route GET /api/weather/update
@ -26,6 +26,6 @@ exports.updateWeather = asyncWrapper(async (req, res, next) => {
res.status(200).json({ res.status(200).json({
success: true, success: true,
data: weather data: weather,
}) });
}) });