fix: can't edit monitors
This commit is contained in:
parent
63cd0c7af5
commit
437b493567
|
|
@ -460,6 +460,44 @@ export const dashboard = new Elysia()
|
|||
return redirect("/dashboard/home");
|
||||
})
|
||||
|
||||
// Edit monitor via form POST
|
||||
.post("/dashboard/monitors/:id/edit", async ({ cookie, headers, params, body }) => {
|
||||
const resolved = await getAccountId(cookie, headers);
|
||||
if (!resolved?.accountId) return redirect("/dashboard");
|
||||
|
||||
const b = body as any;
|
||||
const regions = Array.isArray(b.regions) ? b.regions : (b.regions ? [b.regions] : []);
|
||||
const query = b.query ? (typeof b.query === "string" ? JSON.parse(b.query) : b.query) : undefined;
|
||||
const requestHeaders: Record<string, string> = {};
|
||||
const hKeys = Array.isArray(b.header_key) ? b.header_key : (b.header_key ? [b.header_key] : []);
|
||||
const hVals = Array.isArray(b.header_value) ? b.header_value : (b.header_value ? [b.header_value] : []);
|
||||
for (let i = 0; i < hKeys.length; i++) {
|
||||
if (hKeys[i]?.trim()) requestHeaders[hKeys[i].trim()] = hVals[i] || "";
|
||||
}
|
||||
|
||||
try {
|
||||
const apiUrl = process.env.API_URL || "https://api.pingql.com";
|
||||
const key = cookie?.pingql_key?.value;
|
||||
await fetch(`${apiUrl}/monitors/${params.id}`, {
|
||||
method: "PATCH",
|
||||
headers: { "Content-Type": "application/json", "Authorization": `Bearer ${key}` },
|
||||
body: JSON.stringify({
|
||||
name: b.name,
|
||||
url: b.url,
|
||||
method: b.method || "GET",
|
||||
interval_s: Number(b.interval_s) || 30,
|
||||
timeout_ms: Number(b.timeout_ms) || 10000,
|
||||
regions,
|
||||
request_headers: Object.keys(requestHeaders).length ? requestHeaders : null,
|
||||
request_body: b.request_body || null,
|
||||
query,
|
||||
}),
|
||||
});
|
||||
} catch {}
|
||||
|
||||
return redirect(`/dashboard/monitors/${params.id}`);
|
||||
})
|
||||
|
||||
// Delete monitor via form POST
|
||||
.post("/dashboard/monitors/:id/delete", async ({ cookie, headers, params }) => {
|
||||
const resolved = await getAccountId(cookie, headers);
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@
|
|||
const bodyHidden = ['GET','HEAD','OPTIONS'].includes(curMethod);
|
||||
%>
|
||||
|
||||
<form id="<%= formId %>" action="<%= isEdit ? '' : '/dashboard/monitors/new' %>" method="POST" class="space-y-<%= isEdit ? '5' : '6' %>">
|
||||
<form id="<%= formId %>" action="<%= isEdit ? '/dashboard/monitors/' + monitor.id + '/edit' : '/dashboard/monitors/new' %>" method="POST" class="space-y-<%= isEdit ? '5' : '6' %>">
|
||||
<div>
|
||||
<label class="block text-sm text-gray-400 mb-1.5">Name</label>
|
||||
<input id="<%= prefix %>name" name="name" type="text" required value="<%= monitor.name || '' %>" placeholder="Production API"
|
||||
|
|
|
|||
Loading…
Reference in New Issue