fix: validate command input in newCommand controller

This commit is contained in:
Justin Lin committed 2025-04-26 18:10:33 +08:00
1 parent cb1e395579
commit b86697b6db
1 file changed
+8 -3
@@ -8,7 +8,12 @@ import { questManager } from '../../models/quest'
import { CLIFileExistenceChecker } from '../../containers/cli'
export const newCommand = asyncHandler(async (req: Request, res: Response) => {
const command = commandSchema.parse(req.body)
const body = commandSchema.safeParse(req.body)
if (!body.success) {
res.status(400).json({ message: 'Invalid command', errors: body.error })
return
}
const command = body.data
const { sessionId } = req.user as any
const session = await Session.findById(sessionId)
@@ -40,10 +45,10 @@ export const newCommand = asyncHandler(async (req: Request, res: Response) => {
new CLIFileExistenceChecker(session.containerId!)
)
const event = await gameSession.runCommand(command)
const event = await gameSession.runCommand(body)
const c = new Command({
...command,
...body,
session: sessionId,
stage: event,
})