mirror of
https://github.com/DI0IK/homepage-plus.git
synced 2025-07-08 06:38:46 +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
|
@ -5,7 +5,7 @@ import yaml from "js-yaml";
|
|||
import Docker from "dockerode";
|
||||
import * as shvl from "shvl";
|
||||
|
||||
import checkAndCopyConfig, { sanitizePrivateOptions } from "utils/config/config";
|
||||
import checkAndCopyConfig from "utils/config/config";
|
||||
import getDockerArguments from "utils/config/docker";
|
||||
|
||||
export async function servicesFromConfig() {
|
||||
|
@ -165,23 +165,4 @@ export default async function getServiceWidget(group, service) {
|
|||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
export async function getPrivateWidgetOptions(type, index) {
|
||||
checkAndCopyConfig("widgets.yaml");
|
||||
|
||||
const widgetsYaml = path.join(process.cwd(), "config", "widgets.yaml");
|
||||
const fileContents = await fs.readFile(widgetsYaml, "utf8");
|
||||
const widgets = yaml.load(fileContents);
|
||||
|
||||
if (!widgets) return [];
|
||||
|
||||
const privateOptions = widgets.map((group, widgetIndex) => ({
|
||||
type: Object.keys(group)[0],
|
||||
index: widgetIndex,
|
||||
options: sanitizePrivateOptions(group[Object.keys(group)[0]], true),
|
||||
}));
|
||||
|
||||
return (type !== undefined && index !== undefined) ? privateOptions.find(o => o.type === type && o.index === parseInt(index, 10))?.options : privateOptions;
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue