Update hivegrid-cloud reference to latest main
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
1 parent
e98d38e716
commit
7b21524c86
3781 files changed
+373484
-225607
No files matched your search
+40
@@ -0,0 +1,40 @@
|
||||
import { type LoaderFunctionArgs } from "react-router";
|
||||
import { loadLeadContext, notFoundResponse, requireLeadPermission } from "~/utils/integrations/leads/leadAccess.server";
|
||||
import { LEADS_MODULE_KEY } from "~/utils/integrations/leads/leadRoutePaths";
|
||||
|
||||
function encodeSse(event: string, data: Record<string, unknown>): string {
|
||||
return `event: ${event}\ndata: ${JSON.stringify(data)}\n\n`;
|
||||
}
|
||||
|
||||
export const loader = async ({ request, params }: LoaderFunctionArgs) => {
|
||||
const ctx = await loadLeadContext({ request, params, requireModule: true });
|
||||
try {
|
||||
requireLeadPermission(ctx, "leads.read_own");
|
||||
} catch {
|
||||
throw notFoundResponse();
|
||||
}
|
||||
|
||||
const encoder = new TextEncoder();
|
||||
const stream = new ReadableStream<Uint8Array>({
|
||||
start(controller) {
|
||||
controller.enqueue(encoder.encode(encodeSse("snapshot", { tenantId: ctx.tenantId, generatedAt: new Date().toISOString() })));
|
||||
const heartbeat = setInterval(() => {
|
||||
controller.enqueue(encoder.encode(encodeSse("heartbeat", { generatedAt: new Date().toISOString() })));
|
||||
}, 25_000);
|
||||
request.signal.addEventListener("abort", () => {
|
||||
clearInterval(heartbeat);
|
||||
controller.close();
|
||||
}, { once: true });
|
||||
},
|
||||
});
|
||||
|
||||
return new Response(stream, {
|
||||
headers: {
|
||||
"Cache-Control": "no-cache, no-transform",
|
||||
"Content-Type": "text/event-stream; charset=utf-8",
|
||||
Connection: "keep-alive",
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
export const handle = { moduleKey: LEADS_MODULE_KEY };
|
||||
Reference in new issue
Block a user