Initial commit

This commit is contained in:
2026-03-08 01:34:54 +08:00
commit 1f104f73c8
441 changed files with 64911 additions and 0 deletions

32
api/core/events/routes.ts Normal file
View File

@@ -0,0 +1,32 @@
import express, { Request, Response } from 'express'
import type { ApiResponse } from '../../../shared/types.js'
import { eventBus } from '../../events/eventBus.js'
const router = express.Router()
router.get('/', (req: Request, res: Response) => {
if (process.env.VERCEL) {
const response: ApiResponse<null> = {
success: false,
error: { code: 'SSE_UNSUPPORTED', message: 'SSE在无服务器运行时中不受支持' },
}
return res.status(501).json(response)
}
const headers = {
'Content-Type': 'text/event-stream',
'Connection': 'keep-alive',
'Cache-Control': 'no-cache'
}
res.writeHead(200, headers)
res.write(`data: ${JSON.stringify({ event: 'connected' })}\n\n`)
eventBus.addClient(res)
req.on('close', () => {
eventBus.removeClient(res)
})
})
export default router