feat : notify new update income

This commit is contained in:
2026-09-26 23:34:42 +07:00 Unverified
parent e99a5b76b1
commit 4ef1968b04
14 changed files with 499 additions and 33 deletions
+19 -7
View File
@@ -3,7 +3,11 @@ import { limitRequest, trustedClientAddress } from "@/lib/security/rate-limit";
import { connection } from "next/server";
import { normalizeDeploymentId } from "@/lib/deployment/version";
import { createEventStream, eventStreamHeaders } from "@/lib/events/sse";
import {
DEPLOYMENT_EVENT_TOPIC,
getLatestDeploymentStatus,
} from "@/lib/deployment/repository";
import { createRedisNamedEventResponse } from "@/lib/events/redis-stream";
export async function GET(request: Request) {
await connection();
@@ -11,12 +15,20 @@ export async function GET(request: Request) {
await limitRequest("stream-open", trustedClientAddress(request.headers), 60);
const deploymentId =
normalizeDeploymentId(process.env.NEXT_DEPLOYMENT_ID) ?? "development";
const channel = createEventStream({ signal: request.signal });
channel.sendNamed("deployment", deploymentId);
return new Response(channel.stream, {
headers: eventStreamHeaders(),
});
return await createRedisNamedEventResponse(
DEPLOYMENT_EVENT_TOPIC,
"deployment-status",
request.signal,
async () => {
const latestStatus = await getLatestDeploymentStatus();
return [
{ eventName: "deployment", data: deploymentId },
...(latestStatus
? [{ eventName: "deployment-status", data: JSON.stringify(latestStatus) }]
: []),
];
},
);
} catch (cause) {
return errorResponse(cause);
}