Add URL encoding for instance name in API calls in webui

This commit is contained in:
2025-10-21 23:36:26 +02:00
parent 7c2c02ab2f
commit 13f3bed5fe

View File

@@ -116,7 +116,7 @@ export const nodesApi = {
list: () => apiCall<NodesMap>("/nodes"), list: () => apiCall<NodesMap>("/nodes"),
// GET /nodes/{name} // GET /nodes/{name}
get: (name: string) => apiCall<NodeResponse>(`/nodes/${name}`), get: (name: string) => apiCall<NodeResponse>(`/nodes/${encodeURIComponent(name)}`),
}; };
// Instance API functions // Instance API functions
@@ -125,52 +125,52 @@ export const instancesApi = {
list: () => apiCall<Instance[]>("/instances"), list: () => apiCall<Instance[]>("/instances"),
// GET /instances/{name} // GET /instances/{name}
get: (name: string) => apiCall<Instance>(`/instances/${name}`), get: (name: string) => apiCall<Instance>(`/instances/${encodeURIComponent(name)}`),
// POST /instances/{name} // POST /instances/{name}
create: (name: string, options: CreateInstanceOptions) => create: (name: string, options: CreateInstanceOptions) =>
apiCall<Instance>(`/instances/${name}`, { apiCall<Instance>(`/instances/${encodeURIComponent(name)}`, {
method: "POST", method: "POST",
body: JSON.stringify(options), body: JSON.stringify(options),
}), }),
// PUT /instances/{name} // PUT /instances/{name}
update: (name: string, options: CreateInstanceOptions) => update: (name: string, options: CreateInstanceOptions) =>
apiCall<Instance>(`/instances/${name}`, { apiCall<Instance>(`/instances/${encodeURIComponent(name)}`, {
method: "PUT", method: "PUT",
body: JSON.stringify(options), body: JSON.stringify(options),
}), }),
// DELETE /instances/{name} // DELETE /instances/{name}
delete: (name: string) => delete: (name: string) =>
apiCall<void>(`/instances/${name}`, { apiCall<void>(`/instances/${encodeURIComponent(name)}`, {
method: "DELETE", method: "DELETE",
}), }),
// POST /instances/{name}/start // POST /instances/{name}/start
start: (name: string) => start: (name: string) =>
apiCall<Instance>(`/instances/${name}/start`, { apiCall<Instance>(`/instances/${encodeURIComponent(name)}/start`, {
method: "POST", method: "POST",
}), }),
// POST /instances/{name}/stop // POST /instances/{name}/stop
stop: (name: string) => stop: (name: string) =>
apiCall<Instance>(`/instances/${name}/stop`, { apiCall<Instance>(`/instances/${encodeURIComponent(name)}/stop`, {
method: "POST", method: "POST",
}), }),
// POST /instances/{name}/restart // POST /instances/{name}/restart
restart: (name: string) => restart: (name: string) =>
apiCall<Instance>(`/instances/${name}/restart`, { apiCall<Instance>(`/instances/${encodeURIComponent(name)}/restart`, {
method: "POST", method: "POST",
}), }),
// GET /instances/{name}/logs // GET /instances/{name}/logs
getLogs: (name: string, lines?: number) => { getLogs: (name: string, lines?: number) => {
const params = lines ? `?lines=${lines}` : ""; const params = lines ? `?lines=${lines}` : "";
return apiCall<string>(`/instances/${name}/logs${params}`, {}, "text"); return apiCall<string>(`/instances/${encodeURIComponent(name)}/logs${params}`, {}, "text");
}, },
// GET /instances/{name}/proxy/health // GET /instances/{name}/proxy/health
getHealth: (name: string) => apiCall<Record<string, unknown>>(`/instances/${name}/proxy/health`), getHealth: (name: string) => apiCall<Record<string, unknown>>(`/instances/${encodeURIComponent(name)}/proxy/health`),
}; };