Feature: Plugin system, site search, notifications, webhooks, caching & loading states
Local Build and Deploy / deploy (push) Successful in 1m2s
Local Build and Deploy / deploy (push) Successful in 1m2s
- Plugin/module system with registry, hooks for admin nav/permissions/i18n - Example Games plugin demonstrating the plugin system - Site-wide search with Cmd+K command palette (cmdk-based) - Real-time notification system (SSE + Redis pub/sub) - Extensible webhook system with admin management UI - Caching strategy: tiered data cache (unstable_cache + Redis) - Theme import/export as JSON - Loading states (spinner/skeleton) for all public pages - Mobile responsive fixes (admin dashboard, guilds page) - Webhooks admin page under Settings hub
This commit is contained in:
1 parent
09f1bc2bd6
commit
98d2b92218
85 files changed
+1889
-7
No files matched your search
@@ -0,0 +1,65 @@
|
||||
import { auth } from "@/lib/auth";
|
||||
import { redis } from "@/lib/redis";
|
||||
|
||||
export const dynamic = "force-dynamic";
|
||||
export const runtime = "nodejs";
|
||||
|
||||
export async function GET(request: Request) {
|
||||
const session = await auth();
|
||||
if (!session?.user?.id) {
|
||||
return new Response("Unauthorized", { status: 401 });
|
||||
}
|
||||
|
||||
const userId = Number(session.user.id);
|
||||
if (!userId) {
|
||||
return new Response("Unauthorized", { status: 401 });
|
||||
}
|
||||
|
||||
const stream = new ReadableStream({
|
||||
start(controller) {
|
||||
const encoder = new TextEncoder();
|
||||
let cleanup: (() => void) | null = null;
|
||||
|
||||
const sendEvent = (data: string) => {
|
||||
controller.enqueue(encoder.encode(`data: ${data}\n\n`));
|
||||
};
|
||||
|
||||
sendEvent(JSON.stringify({ type: "connected" }));
|
||||
|
||||
if (redis) {
|
||||
const subscriber = redis.duplicate();
|
||||
subscriber.subscribe(`user:${userId}`, (err) => {
|
||||
if (err) {
|
||||
sendEvent(JSON.stringify({ type: "error", message: "Subscription failed" }));
|
||||
}
|
||||
});
|
||||
|
||||
subscriber.on("message", (_channel, message) => {
|
||||
sendEvent(message);
|
||||
});
|
||||
|
||||
cleanup = () => {
|
||||
subscriber.unsubscribe();
|
||||
subscriber.quit();
|
||||
};
|
||||
}
|
||||
|
||||
const keepAlive = setInterval(() => {
|
||||
sendEvent(JSON.stringify({ type: "ping" }));
|
||||
}, 30000);
|
||||
|
||||
request.signal.addEventListener("abort", () => {
|
||||
clearInterval(keepAlive);
|
||||
cleanup?.();
|
||||
});
|
||||
},
|
||||
});
|
||||
|
||||
return new Response(stream, {
|
||||
headers: {
|
||||
"Content-Type": "text/event-stream",
|
||||
"Cache-Control": "no-cache",
|
||||
Connection: "keep-alive",
|
||||
},
|
||||
});
|
||||
}
|
||||
Reference in new issue
Block a user