clean up
This commit is contained in:
@@ -3,7 +3,6 @@ import { requireAuth } from "./auth";
|
||||
import sql from "../db";
|
||||
|
||||
const Theme = t.Union([t.Literal("auto"), t.Literal("light"), t.Literal("dark")]);
|
||||
const DisplayMode = t.Union([t.Literal("compact"), t.Literal("expanded")]);
|
||||
const BarFrequency = t.Union([t.Literal("hourly"), t.Literal("daily")]);
|
||||
|
||||
const StatusPageBody = t.Object({
|
||||
@@ -16,7 +15,6 @@ const StatusPageBody = t.Object({
|
||||
show_powered_by: t.Optional(t.Boolean()),
|
||||
show_response_time: t.Optional(t.Boolean()),
|
||||
show_cert_expiry: t.Optional(t.Boolean()),
|
||||
display_mode: t.Optional(DisplayMode),
|
||||
bar_frequency: t.Optional(BarFrequency),
|
||||
bar_count: t.Optional(t.Number({ minimum: 1, maximum: 180 })),
|
||||
custom_css: t.Optional(t.Nullable(t.String({ maxLength: 50_000 }))),
|
||||
@@ -32,7 +30,6 @@ const StatusPageBody = t.Object({
|
||||
monitor_id: t.String(),
|
||||
group_index: t.Optional(t.Nullable(t.Number())),
|
||||
display_name: t.Optional(t.Nullable(t.String({ maxLength: 200 }))),
|
||||
display_mode: t.Optional(t.Nullable(DisplayMode)),
|
||||
position: t.Optional(t.Number()),
|
||||
}))),
|
||||
});
|
||||
@@ -55,7 +52,7 @@ async function replaceGroupsAndMonitors(
|
||||
pageId: string,
|
||||
accountId: string,
|
||||
groups: { name: string; position?: number }[] | undefined,
|
||||
monitorsList: { monitor_id: string; group_index?: number | null; display_name?: string | null; display_mode?: "compact" | "expanded" | null; position?: number }[] | undefined,
|
||||
monitorsList: { monitor_id: string; group_index?: number | null; display_name?: string | null; position?: number }[] | undefined,
|
||||
) {
|
||||
if (groups !== undefined) {
|
||||
await sql`DELETE FROM status_page_groups WHERE status_page_id = ${pageId}`;
|
||||
@@ -99,13 +96,12 @@ async function replaceGroupsAndMonitors(
|
||||
monitor_id: m.monitor_id,
|
||||
group_id: groupId,
|
||||
display_name: m.display_name ?? null,
|
||||
display_mode: m.display_mode ?? null,
|
||||
position: m.position ?? i,
|
||||
});
|
||||
}
|
||||
if (rows.length > 0) {
|
||||
await sql`
|
||||
INSERT INTO status_page_monitors ${sql(rows, "status_page_id", "monitor_id", "group_id", "display_name", "display_mode", "position")}
|
||||
INSERT INTO status_page_monitors ${sql(rows, "status_page_id", "monitor_id", "group_id", "display_name", "position")}
|
||||
`;
|
||||
}
|
||||
}
|
||||
@@ -131,7 +127,7 @@ export const statusPages = new Elysia({ prefix: "/pages" })
|
||||
[row] = await sql`
|
||||
INSERT INTO status_pages (
|
||||
account_id, slug, title, description, theme, password_hash, index_search,
|
||||
show_powered_by, show_response_time, show_cert_expiry, display_mode,
|
||||
show_powered_by, show_response_time, show_cert_expiry,
|
||||
bar_frequency, bar_count,
|
||||
custom_css, footer_text, og_image_url, analytics_html, auto_refresh_s
|
||||
)
|
||||
@@ -139,7 +135,7 @@ export const statusPages = new Elysia({ prefix: "/pages" })
|
||||
${accountId}, ${body.slug}, ${body.title}, ${body.description ?? null},
|
||||
${body.theme ?? 'auto'}, ${password_hash}, ${body.index_search ?? true},
|
||||
${body.show_powered_by ?? true}, ${body.show_response_time ?? true},
|
||||
${body.show_cert_expiry ?? false}, ${body.display_mode ?? 'expanded'},
|
||||
${body.show_cert_expiry ?? false},
|
||||
${body.bar_frequency ?? 'daily'}, ${body.bar_count ?? 90},
|
||||
${css}, ${body.footer_text ?? null}, ${body.og_image_url ?? null},
|
||||
${body.analytics_html ?? null}, ${body.auto_refresh_s ?? 60}
|
||||
@@ -195,7 +191,6 @@ export const statusPages = new Elysia({ prefix: "/pages" })
|
||||
show_powered_by = COALESCE(${body.show_powered_by ?? null}, show_powered_by),
|
||||
show_response_time = COALESCE(${body.show_response_time ?? null}, show_response_time),
|
||||
show_cert_expiry = COALESCE(${body.show_cert_expiry ?? null}, show_cert_expiry),
|
||||
display_mode = COALESCE(${body.display_mode ?? null}, display_mode),
|
||||
bar_frequency = COALESCE(${body.bar_frequency ?? null}, bar_frequency),
|
||||
bar_count = COALESCE(${body.bar_count ?? null}, bar_count),
|
||||
custom_css = CASE WHEN ${body.custom_css !== undefined} THEN ${css} ELSE custom_css END,
|
||||
|
||||
Reference in New Issue
Block a user