mirror of
https://github.com/DI0IK/homepage-plus.git
synced 2025-07-07 14:18:47 +00:00
Refactor info widget sanitizing / privateOptions
This commit is contained in:
parent
dced918804
commit
48a09e5a99
6 changed files with 89 additions and 53 deletions
|
@ -4,8 +4,9 @@ import path from "path";
|
|||
|
||||
import yaml from "js-yaml";
|
||||
|
||||
import checkAndCopyConfig, { sanitizePrivateOptions } from "utils/config/config";
|
||||
import checkAndCopyConfig from "utils/config/config";
|
||||
import { servicesFromConfig, servicesFromDocker, cleanServiceGroups } from "utils/config/service-helpers";
|
||||
import { cleanWidgetGroups, widgetsFromConfig } from "utils/config/widget-helpers";
|
||||
|
||||
export async function bookmarksResponse() {
|
||||
checkAndCopyConfig("bookmarks.yaml");
|
||||
|
@ -29,24 +30,17 @@ export async function bookmarksResponse() {
|
|||
}
|
||||
|
||||
export async function widgetsResponse() {
|
||||
checkAndCopyConfig("widgets.yaml");
|
||||
let configuredWidgets;
|
||||
|
||||
const widgetsYaml = path.join(process.cwd(), "config", "widgets.yaml");
|
||||
const fileContents = await fs.readFile(widgetsYaml, "utf8");
|
||||
const widgets = yaml.load(fileContents);
|
||||
try {
|
||||
configuredWidgets = cleanWidgetGroups(await widgetsFromConfig());
|
||||
} catch (e) {
|
||||
console.error("Failed to load widgets, please check widgets.yaml for errors or remove example entries.");
|
||||
if (e) console.error(e);
|
||||
configuredWidgets = [];
|
||||
}
|
||||
|
||||
if (!widgets) return [];
|
||||
|
||||
// map easy to write YAML objects into easy to consume JS arrays
|
||||
const widgetsArray = widgets.map((group, index) => ({
|
||||
type: Object.keys(group)[0],
|
||||
options: {
|
||||
index,
|
||||
...sanitizePrivateOptions(group[Object.keys(group)[0]])
|
||||
},
|
||||
}));
|
||||
|
||||
return widgetsArray;
|
||||
return configuredWidgets;
|
||||
}
|
||||
|
||||
export async function servicesResponse() {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue