Files
buzz/lib/db/sse-endpoints.ts
T
dmgnr d8e7c29c51
Build and Push Image / build-backend (push) Successful in 1m56s
Build and Push Image / build-frontend (push) Successful in 3m9s
Build and Push Image / push (push) Successful in 45s
feat: add message broadcaster
2026-09-12 00:00:51 +07:00

74 lines
1.8 KiB
TypeScript

import z from "zod/v4";
import type { YoutubeLiveInfo } from "@/app/api/live/route";
import { sseEndpoint, sseEndpointMap } from "./redis";
import type { auditLog, tierlistStates, TTrackingKey } from "./schema";
export const sse = sseEndpointMap({
// Artifact Admin Listener
artifact: {
update: z.object({
type: z.enum(["setLimit", "wipe", "submit", "toggleCheck", "toggleLock"]),
}),
},
// Rubgram Admin Listener
rubgram: {
update: z
.object({
type: z.enum([
"setLimit",
"wipe",
"toggleCheck",
"toggleLock",
"setFree",
"cancel",
"uploadSlip",
]),
})
.or(
z.object({
type: z.enum(["submit", "paid"]),
sub: z.string(),
}),
),
},
donate: {
ping: z.object({
id: z.string(),
name: z.string(),
amount: z.number(),
image: z.string().optional(),
message: z.string(),
}),
// roundtrip SSE system check
heartbeat: z.number(),
update: z.null(),
refresh: z.null(),
},
// Passive Update Checker
active: {
version: z.string(),
live: z.custom<YoutubeLiveInfo>(),
refresh: z.string().nullable(),
announcement: z.object({
severity: z.enum(["info", "success", "warning", "error"]),
message: z.string(),
prefix: z.string().default("/"),
}),
},
// Admin Live Log
log: {
update: z.custom<typeof auditLog.$inferSelect>(),
},
slip_sync: {
complete: z.custom<TTrackingKey>(),
connected: z.custom<TTrackingKey>(),
},
});
export const adminSseList: (keyof typeof sse)[] = ["log"];
export function tlSse<T extends string>(list: T) {
return sseEndpoint(`tl.${list}`, {
update_states: z.custom<(typeof tierlistStates.$inferSelect)[]>(),
update_placements: z.record(z.string(), z.string().array()),
});
}