From af464fa3a1e92165795cadc92a031d4dab0d6829 Mon Sep 17 00:00:00 2001 From: Klesti Selimaj Date: Mon, 16 Feb 2026 01:38:53 +0100 Subject: [PATCH] Text stability sync --- src/app/api/run/route.ts | 14 ++++++++++++++ src/app/api/run/types.ts | 4 ++++ src/app/api/view-run/route.ts | 5 +++-- 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/src/app/api/run/route.ts b/src/app/api/run/route.ts index 0ee1098..4d964ee 100644 --- a/src/app/api/run/route.ts +++ b/src/app/api/run/route.ts @@ -5,6 +5,7 @@ import { getSession } from "@/modules/account/core"; import * as Core from "@/modules/live-run/core"; import { ClientMessage } from "./types"; import { NextRequest } from "next/server"; +import { redis } from "@/lib/redis"; export function GET(req: NextRequest) { const headers = new Headers(); @@ -204,6 +205,19 @@ export function UPGRADE(client: WebSocket, server: WebSocketServer) { break; } + case "getText": + const { runId } = msg; + const data = await redis.get(`liveRunText:${runId}`); + + client.send( + JSON.stringify({ + requestId, + ok: true, + data, + }), + ); + break; + default: client.send( JSON.stringify({ diff --git a/src/app/api/run/types.ts b/src/app/api/run/types.ts index 6208587..1029cc8 100644 --- a/src/app/api/run/types.ts +++ b/src/app/api/run/types.ts @@ -21,6 +21,10 @@ export type ClientMessage = { requestId: string } & ( type: "delete"; runId: string; } + | { + type: "getText"; + runId: string; + } ); export type ServerMessage = diff --git a/src/app/api/view-run/route.ts b/src/app/api/view-run/route.ts index bb8c58c..8686012 100644 --- a/src/app/api/view-run/route.ts +++ b/src/app/api/view-run/route.ts @@ -2,7 +2,8 @@ import { WebSocketServer, WebSocket } from "ws"; import Redis from "ioredis"; import { NextRequest, NextResponse } from "next/server"; import { LiveRunEvent } from "@/modules/live-run/types"; -import { getLiveRun, updateLiveRunViews } from "@/modules/live-run/core"; +import { updateLiveRunViews } from "@/modules/live-run/core"; +import { redis } from "@/lib/redis"; export function GET(req: NextRequest) { const headers = new Headers(); @@ -23,7 +24,7 @@ export function UPGRADE(client: WebSocket, server: WebSocketServer) { let lastEvent: LiveRunEvent | null = null; const sendText = async () => { - const text = await subscriber.get(`liveRunText:${runId}`); + const text = await redis.get(`liveRunText:${runId}`); if (client.readyState === WebSocket.OPEN) { client.send(