mirror of
https://github.com/pawelmalak/flame.git
synced 2025-07-19 11:39:36 +02:00
Pushed version 1.6.2. Small formatting fixes
This commit is contained in:
parent
1962af01e6
commit
a01661d0d5
6 changed files with 123 additions and 78 deletions
|
@ -28,7 +28,7 @@ exports.createApp = asyncWrapper(async (req, res, next) => {
|
|||
app = await App.create({
|
||||
..._body,
|
||||
isPinned: true
|
||||
})
|
||||
});
|
||||
} else {
|
||||
app = await App.create(req.body);
|
||||
}
|
||||
|
@ -37,8 +37,8 @@ exports.createApp = asyncWrapper(async (req, res, next) => {
|
|||
res.status(201).json({
|
||||
success: true,
|
||||
data: app
|
||||
})
|
||||
})
|
||||
});
|
||||
});
|
||||
|
||||
// @desc Get all apps
|
||||
// @route GET /api/apps
|
||||
|
@ -58,37 +58,45 @@ exports.getApps = asyncWrapper(async (req, res, next) => {
|
|||
const orderType = useOrdering ? useOrdering.value : 'createdAt';
|
||||
let apps;
|
||||
|
||||
|
||||
if (useDockerApi && useDockerApi.value==1) {
|
||||
if (useDockerApi && useDockerApi.value == 1) {
|
||||
let containers = null;
|
||||
|
||||
try {
|
||||
let {data} = await axios.get('http://localhost/containers/json?{"status":["running"]}', {
|
||||
socketPath: '/var/run/docker.sock'
|
||||
});
|
||||
containers = data;
|
||||
} catch{logger.log("Can't connect to the docker socket","ERROR")}
|
||||
let { data } = await axios.get(
|
||||
'http://localhost/containers/json?{"status":["running"]}',
|
||||
{
|
||||
socketPath: '/var/run/docker.sock'
|
||||
}
|
||||
);
|
||||
containers = data;
|
||||
} catch {
|
||||
logger.log("Can't connect to the docker socket", 'ERROR');
|
||||
}
|
||||
|
||||
if (containers) {
|
||||
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 = [];
|
||||
for (const container of containers) {
|
||||
const labels = container.Labels;
|
||||
|
||||
if ('flame.name' in labels && 'flame.url' in labels && /^app/.test(labels['flame.type'])) {
|
||||
if (
|
||||
'flame.name' in labels &&
|
||||
'flame.url' in labels &&
|
||||
/^app/.test(labels['flame.type'])
|
||||
) {
|
||||
dockerApps.push({
|
||||
name: labels['flame.name'],
|
||||
url: labels['flame.url'],
|
||||
icon: labels['flame.icon'] || 'docker'
|
||||
})
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
if (unpinStoppedApps && unpinStoppedApps.value==1) {
|
||||
if (unpinStoppedApps && unpinStoppedApps.value == 1) {
|
||||
for (const app of apps) {
|
||||
await app.update({ isPinned: false });
|
||||
}
|
||||
|
@ -97,12 +105,12 @@ exports.getApps = asyncWrapper(async (req, res, next) => {
|
|||
for (const item of dockerApps) {
|
||||
if (apps.some(app => app.name === item.name)) {
|
||||
const app = apps.filter(e => e.name === item.name)[0];
|
||||
await app.update({ ...item,isPinned: true });
|
||||
await app.update({ ...item, isPinned: true });
|
||||
} else {
|
||||
await App.create({
|
||||
...item,
|
||||
isPinned: true
|
||||
})
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -110,20 +118,20 @@ exports.getApps = asyncWrapper(async (req, res, next) => {
|
|||
|
||||
if (orderType == 'name') {
|
||||
apps = await App.findAll({
|
||||
order: [[ Sequelize.fn('lower', Sequelize.col('name')), 'ASC' ]]
|
||||
order: [[Sequelize.fn('lower', Sequelize.col('name')), 'ASC']]
|
||||
});
|
||||
} else {
|
||||
apps = await App.findAll({
|
||||
order: [[ orderType, 'ASC' ]]
|
||||
order: [[orderType, 'ASC']]
|
||||
});
|
||||
}
|
||||
|
||||
// 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,
|
||||
data: apps
|
||||
})
|
||||
})
|
||||
});
|
||||
});
|
||||
|
||||
// @desc Get single app
|
||||
// @route GET /api/apps/:id
|
||||
|
@ -134,14 +142,16 @@ exports.getApp = asyncWrapper(async (req, res, next) => {
|
|||
});
|
||||
|
||||
if (!app) {
|
||||
return next(new ErrorResponse(`App with id of ${req.params.id} was not found`, 404));
|
||||
return next(
|
||||
new ErrorResponse(`App with id of ${req.params.id} was not found`, 404)
|
||||
);
|
||||
}
|
||||
|
||||
res.status(200).json({
|
||||
success: true,
|
||||
data: app
|
||||
})
|
||||
})
|
||||
});
|
||||
});
|
||||
|
||||
// @desc Update app
|
||||
// @route PUT /api/apps/:id
|
||||
|
@ -152,7 +162,9 @@ exports.updateApp = asyncWrapper(async (req, res, next) => {
|
|||
});
|
||||
|
||||
if (!app) {
|
||||
return next(new ErrorResponse(`App with id of ${req.params.id} was not found`, 404));
|
||||
return next(
|
||||
new ErrorResponse(`App with id of ${req.params.id} was not found`, 404)
|
||||
);
|
||||
}
|
||||
|
||||
let _body = { ...req.body };
|
||||
|
@ -166,8 +178,8 @@ exports.updateApp = asyncWrapper(async (req, res, next) => {
|
|||
res.status(200).json({
|
||||
success: true,
|
||||
data: app
|
||||
})
|
||||
})
|
||||
});
|
||||
});
|
||||
|
||||
// @desc Delete app
|
||||
// @route DELETE /api/apps/:id
|
||||
|
@ -175,26 +187,29 @@ exports.updateApp = asyncWrapper(async (req, res, next) => {
|
|||
exports.deleteApp = asyncWrapper(async (req, res, next) => {
|
||||
await App.destroy({
|
||||
where: { id: req.params.id }
|
||||
})
|
||||
});
|
||||
|
||||
res.status(200).json({
|
||||
success: true,
|
||||
data: {}
|
||||
})
|
||||
})
|
||||
});
|
||||
});
|
||||
|
||||
// @desc Reorder apps
|
||||
// @route PUT /api/apps/0/reorder
|
||||
// @access Public
|
||||
exports.reorderApps = asyncWrapper(async (req, res, next) => {
|
||||
req.body.apps.forEach(async ({ id, orderId }) => {
|
||||
await App.update({ orderId }, {
|
||||
where: { id }
|
||||
})
|
||||
})
|
||||
await App.update(
|
||||
{ orderId },
|
||||
{
|
||||
where: { id }
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
res.status(200).json({
|
||||
success: true,
|
||||
data: {}
|
||||
})
|
||||
})
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue