feat: add shortcut config foundation

This commit is contained in:
Federico Jaramillo Martinez
2026-06-03 20:41:16 +02:00
parent 4495a26ffd
commit a58c2113f4
20 changed files with 558 additions and 268 deletions
+2 -2
View File
@@ -37,11 +37,11 @@ describe("config routes", () => {
const response = await app.inject({
method: "PUT",
url: "/api/config",
payload: { config: { host: "0.0.0.0", port: 9000, allowedHosts: true } },
payload: { config: { host: "0.0.0.0", port: 9000, allowedHosts: true, shortcuts: { "core:view.chat": "mod+1", "core:session.stop": null } } },
});
expect(response.statusCode).toBe(200);
expect(savedConfig).toEqual({ host: "0.0.0.0", port: 9000, allowedHosts: true });
expect(savedConfig).toEqual({ host: "0.0.0.0", port: 9000, allowedHosts: true, shortcuts: { "core:view.chat": "mod+1", "core:session.stop": null } });
expect(response.json<PiWebConfigResponse>().config).toEqual(savedConfig);
});
+10
View File
@@ -55,6 +55,7 @@ function parseConfigRequest(value: unknown): PiWebConfig {
const host = value["host"];
const port = value["port"];
const allowedHosts = value["allowedHosts"];
const shortcuts = value["shortcuts"];
if (host !== undefined) {
if (typeof host !== "string") throw new Error("PI WEB config host must be a string");
config.host = host;
@@ -64,6 +65,7 @@ function parseConfigRequest(value: unknown): PiWebConfig {
config.port = port;
}
if (allowedHosts !== undefined) config.allowedHosts = parseAllowedHostsRequest(allowedHosts);
if (shortcuts !== undefined) config.shortcuts = parseShortcutsRequest(shortcuts);
return config;
}
@@ -75,6 +77,14 @@ function parseAllowedHostsRequest(value: unknown): string[] | true {
return value;
}
function parseShortcutsRequest(value: unknown): Record<string, string | null> {
if (!isRecord(value)) throw new Error("PI WEB config shortcuts must be an object");
return Object.fromEntries(Object.entries(value).map(([actionId, shortcut]) => {
if (shortcut !== null && (typeof shortcut !== "string" || shortcut === "")) throw new Error("PI WEB config shortcut values must be non-empty strings or null");
return [actionId, shortcut];
}));
}
function piWebConfigEnvOverrides(env: NodeJS.ProcessEnv): PiWebConfigEnvOverrides {
return {
host: isEnvSet(env["PI_WEB_HOST"]),