mirror of
https://github.com/DI0IK/homepage-plus.git
synced 2025-07-08 06:38:46 +00:00
Change to server-side implementation
This commit is contained in:
parent
82c69ff68d
commit
3740426bb5
2 changed files with 26 additions and 18 deletions
|
@ -4,7 +4,7 @@ import path from "path";
|
|||
|
||||
import yaml from "js-yaml";
|
||||
|
||||
import checkAndCopyConfig from "utils/config/config";
|
||||
import checkAndCopyConfig, { getSettings } from "utils/config/config";
|
||||
import { servicesFromConfig, servicesFromDocker, cleanServiceGroups } from "utils/config/service-helpers";
|
||||
import { cleanWidgetGroups, widgetsFromConfig } from "utils/config/widget-helpers";
|
||||
|
||||
|
@ -46,6 +46,7 @@ export async function widgetsResponse() {
|
|||
export async function servicesResponse() {
|
||||
let discoveredServices;
|
||||
let configuredServices;
|
||||
let initialSettings;
|
||||
|
||||
try {
|
||||
discoveredServices = cleanServiceGroups(await servicesFromDocker());
|
||||
|
@ -63,6 +64,14 @@ export async function servicesResponse() {
|
|||
configuredServices = [];
|
||||
}
|
||||
|
||||
try {
|
||||
initialSettings = await getSettings();
|
||||
} catch (e) {
|
||||
console.error("Failed to load settings.yaml, please check for errors");
|
||||
if (e) console.error(e);
|
||||
initialSettings = {};
|
||||
}
|
||||
|
||||
const mergedGroupsNames = [
|
||||
...new Set([discoveredServices.map((group) => group.name), configuredServices.map((group) => group.name)].flat()),
|
||||
];
|
||||
|
@ -81,5 +90,18 @@ export async function servicesResponse() {
|
|||
mergedGroups.push(mergedGroup);
|
||||
});
|
||||
|
||||
return mergedGroups;
|
||||
let sortedServices = [];
|
||||
|
||||
const layouts = Object.keys(initialSettings.layout);
|
||||
layouts.forEach((currentServer) => {
|
||||
if (initialSettings.layout[currentServer]?.sort) {
|
||||
const idx = mergedGroups.findIndex((service) => service.name === currentServer);
|
||||
sortedServices.push(...mergedGroups.splice(idx, 1));
|
||||
}
|
||||
});
|
||||
if (mergedGroups.length) {
|
||||
sortedServices = sortedServices.concat(mergedGroups);
|
||||
}
|
||||
|
||||
return sortedServices;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue