mirror of
https://github.com/sergeyyarkov/asu_tools_service.git
synced 2026-10-11 02:19:09 +03:00
32 lines
826 B
JavaScript
32 lines
826 B
JavaScript
import { clients } from "#root/index.js";
|
||
import crypto from "node:crypto";
|
||
|
||
/**
|
||
* URL: /api/reports_status_parse
|
||
* Method: GET
|
||
* Description: Отправляет частями в формате JSON информацию о текущем статусе парсинга отчетов
|
||
*
|
||
* @type {import("#root/http-server/types/http-server.js").HttpRouteHandler}
|
||
*/
|
||
export default (ctx) => {
|
||
const { res } = ctx;
|
||
const clientId = crypto.randomUUID();
|
||
|
||
clients.set(clientId, ctx);
|
||
|
||
res.res.setHeaders(
|
||
new Headers({
|
||
Connection: "keep-alive",
|
||
"Cache-Control": "no-cache",
|
||
"Content-Type": "text/event-stream; charset=utf-8"
|
||
})
|
||
);
|
||
|
||
res.sendSSEJson({ message: "Connected!", clientId }, "data");
|
||
|
||
res.res.on("close", () => {
|
||
clients.delete(clientId);
|
||
res.res.end();
|
||
});
|
||
};
|