mirror of
https://github.com/pawelmalak/flame.git
synced 2025-07-19 11:39:36 +02:00
chore(): removed docker & kubernetes from database + stoppedApp pin option
This commit is contained in:
parent
1c9a0303fd
commit
5111c7ad79
3 changed files with 28 additions and 69 deletions
|
@ -62,6 +62,7 @@ exports.getApps = asyncWrapper(async (req, res, next) => {
|
|||
const orderType = useOrdering ? useOrdering.value : 'createdAt';
|
||||
let apps;
|
||||
|
||||
let dockerApps = [];
|
||||
if (useDockerApi && useDockerApi.value == 1) {
|
||||
let containers = null;
|
||||
|
||||
|
@ -78,12 +79,7 @@ exports.getApps = asyncWrapper(async (req, res, next) => {
|
|||
}
|
||||
|
||||
if (containers) {
|
||||
apps = await App.findAll({
|
||||
order: [[orderType, 'ASC']]
|
||||
});
|
||||
|
||||
containers = containers.filter(e => Object.keys(e.Labels).length !== 0);
|
||||
const dockerApps = [];
|
||||
for (const container of containers) {
|
||||
const labels = container.Labels;
|
||||
|
||||
|
@ -95,24 +91,7 @@ exports.getApps = asyncWrapper(async (req, res, next) => {
|
|||
dockerApps.push({
|
||||
name: labels['flame.name'],
|
||||
url: labels['flame.url'],
|
||||
icon: labels['flame.icon'] || 'docker'
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
if (unpinStoppedApps && unpinStoppedApps.value == 1) {
|
||||
for (const app of apps) {
|
||||
await app.update({ isPinned: false });
|
||||
}
|
||||
}
|
||||
|
||||
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 });
|
||||
} else {
|
||||
await App.create({
|
||||
...item,
|
||||
icon: labels['flame.icon'] || 'docker',
|
||||
isPinned: true
|
||||
});
|
||||
}
|
||||
|
@ -120,6 +99,7 @@ exports.getApps = asyncWrapper(async (req, res, next) => {
|
|||
}
|
||||
}
|
||||
|
||||
let kubernetesApps = [];
|
||||
if (useKubernetesApi && useKubernetesApi.value == 1) {
|
||||
let ingresses = null;
|
||||
|
||||
|
@ -136,14 +116,10 @@ exports.getApps = asyncWrapper(async (req, res, next) => {
|
|||
}
|
||||
|
||||
if (ingresses) {
|
||||
apps = await App.findAll({
|
||||
order: [[orderType, 'ASC']]
|
||||
});
|
||||
|
||||
ingresses = ingresses.filter(e => Object.keys(e.metadata.annotations).length !== 0);
|
||||
const kubernetesApps = [];
|
||||
for (const ingress of ingresses) {
|
||||
const annotations = ingress.metadata.annotations;
|
||||
const creationTimestamp = ingress.metadata.creationTimestamp;
|
||||
|
||||
if (
|
||||
'flame.pawelmalak/name' in annotations &&
|
||||
|
@ -153,24 +129,8 @@ exports.getApps = asyncWrapper(async (req, res, next) => {
|
|||
kubernetesApps.push({
|
||||
name: annotations['flame.pawelmalak/name'],
|
||||
url: annotations['flame.pawelmalak/url'],
|
||||
icon: annotations['flame.pawelmalak/icon'] || 'kubernetes'
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
if (unpinStoppedApps && unpinStoppedApps.value == 1) {
|
||||
for (const app of apps) {
|
||||
await app.update({ isPinned: false });
|
||||
}
|
||||
}
|
||||
|
||||
for (const item of kubernetesApps) {
|
||||
if (apps.some(app => app.name === item.name)) {
|
||||
const app = apps.filter(e => e.name === item.name)[0];
|
||||
await app.update({ ...item, isPinned: true });
|
||||
} else {
|
||||
await App.create({
|
||||
...item,
|
||||
icon: annotations['flame.pawelmalak/icon'] || 'kubernetes',
|
||||
createdAt: creationTimestamp,
|
||||
isPinned: true
|
||||
});
|
||||
}
|
||||
|
@ -179,12 +139,28 @@ exports.getApps = asyncWrapper(async (req, res, next) => {
|
|||
}
|
||||
|
||||
if (orderType == 'name') {
|
||||
apps = await App.findAll({
|
||||
order: [[Sequelize.fn('lower', Sequelize.col('name')), 'ASC']]
|
||||
apps = await App.findAll();
|
||||
apps = apps.concat(dockerApps);
|
||||
apps = apps.concat(kubernetesApps);
|
||||
apps.sort((a, b) => {
|
||||
if (a.name < b.name)
|
||||
return -1;
|
||||
if (a.name > b.name)
|
||||
return 1;
|
||||
return 0;
|
||||
});
|
||||
} else {
|
||||
apps = await App.findAll({
|
||||
order: [[orderType, 'ASC']]
|
||||
apps = await App.findAll();
|
||||
apps = apps.concat(dockerApps);
|
||||
apps = apps.concat(kubernetesApps);
|
||||
apps.sort((a, b) => {
|
||||
if (!a[orderType] || !b[orderType])
|
||||
return -1;
|
||||
if (a[orderType] < b[orderType])
|
||||
return -1;
|
||||
if (a[orderType] > b[orderType])
|
||||
return 1;
|
||||
return 0;
|
||||
});
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue