|
@@ -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);
|
|
|
-
|
|
|
- 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]])
|
|
|
- },
|
|
|
- }));
|
|
|
+ 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 = [];
|
|
|
+ }
|
|
|
|
|
|
- return widgetsArray;
|
|
|
+ return configuredWidgets;
|
|
|
}
|
|
|
|
|
|
export async function servicesResponse() {
|