mirror of
https://github.com/linux-odyssey/linux-odyssey.git
synced 2026-11-06 03:20:13 +08:00
feat: send response to frontend
This commit is contained in:
1 parent
fb69cb4e10
commit
88ee8f2cc3
8 files changed
+46
-35
No files matched your search
@@ -51,16 +51,16 @@ export const newCommand = asyncHandler(async (req: Request, res: Response) => {
|
||||
c.stage = response.stage
|
||||
await c.save()
|
||||
|
||||
session.responses.push(response.responses)
|
||||
|
||||
if (response.stage === 'END') {
|
||||
await finishSession(session)
|
||||
}
|
||||
commandCompleteCallbacks.set(session.id, response.callback)
|
||||
pushToSession(session.id, 'status', 'pending')
|
||||
res.status(201).json(response)
|
||||
} else {
|
||||
res.status(200).end()
|
||||
// commandCompleteCallbacks.set(session.id, response.callback)
|
||||
pushToSession(session.id, 'response', response)
|
||||
}
|
||||
|
||||
res.status(200).end()
|
||||
await session.save()
|
||||
})
|
||||
|
||||
|
||||
@@ -25,6 +25,7 @@ function sessionDetail(session: ISession) {
|
||||
...sessionSummary(session),
|
||||
hints: session.hints,
|
||||
tasks: session.tasks,
|
||||
responses: session.responses,
|
||||
graph: session.graph,
|
||||
}
|
||||
}
|
||||
@@ -55,6 +56,7 @@ export const createSession = asyncHandler(
|
||||
export const getSessionById = asyncHandler(
|
||||
async (req: Request, res: Response) => {
|
||||
const { sessionId } = matchedData(req)
|
||||
console.log(sessionId)
|
||||
const session = await Session.findOne({
|
||||
_id: sessionId,
|
||||
user: (req.user as Express.ExistingUser).id,
|
||||
|
||||
@@ -22,6 +22,10 @@ router.post(
|
||||
activeSessionValidator,
|
||||
sessionController.getOrCreateSession
|
||||
)
|
||||
router.get('/:id', sessionDetailValidator, sessionController.getSessionById)
|
||||
router.get(
|
||||
'/:sessionId',
|
||||
sessionDetailValidator,
|
||||
sessionController.getSessionById
|
||||
)
|
||||
|
||||
export default router
|
||||
@@ -9,6 +9,6 @@ export const checkSessionId = () =>
|
||||
check('sessionId').notEmpty().isString().isMongoId()
|
||||
|
||||
export const sessionListValidator = [checkQuestId(), checkSessionStatus()]
|
||||
export const sessionDetailValidator = [checkSessionId(), noError]
|
||||
export const sessionDetailValidator = [checkSessionId()]
|
||||
export const createSessionValidator = [checkQuestId(), noError]
|
||||
export const activeSessionValidator = [checkQuestId(), noError]
|
||||
@@ -8,12 +8,12 @@ import type {
|
||||
IStage,
|
||||
ITask,
|
||||
} from '@linux-odyssey/models'
|
||||
import { pushToSession } from '../api/socket.js'
|
||||
|
||||
export interface ExecuteResult {
|
||||
responses: IResponse[]
|
||||
hints: string[]
|
||||
callback: () => void
|
||||
tasks?: ITask[]
|
||||
status: string
|
||||
stage?: string
|
||||
end?: boolean
|
||||
}
|
||||
@@ -82,12 +82,8 @@ export default class SessionHandler {
|
||||
return {
|
||||
responses: stage.responses,
|
||||
hints: stage.hints,
|
||||
callback: () => {
|
||||
pushToSession(this.session.id, 'tasks', this.session.tasks)
|
||||
if (stage.hints && stage.hints.length > 0)
|
||||
pushToSession(this.session.id, 'hints', stage.hints)
|
||||
pushToSession(this.session.id, 'status', this.session.status)
|
||||
},
|
||||
tasks: this.session.tasks,
|
||||
status: this.session.status,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -98,11 +94,7 @@ export default class SessionHandler {
|
||||
return {
|
||||
responses,
|
||||
hints,
|
||||
callback: () => {
|
||||
if (hints && hints.length > 0)
|
||||
pushToSession(this.session.id, 'hints', hints)
|
||||
pushToSession(this.session.id, 'status', this.session.status)
|
||||
},
|
||||
status: this.session.status,
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user