mirror of
https://github.com/linux-odyssey/linux-odyssey.git
synced 2026-11-05 19:20:12 +08:00
fix: validate command input in newCommand controller
This commit is contained in:
1 parent
cb1e395579
commit
b86697b6db
1 file changed
+8
-3
@@ -8,7 +8,12 @@ import { questManager } from '../../models/quest'
|
|||||||
import { CLIFileExistenceChecker } from '../../containers/cli'
|
import { CLIFileExistenceChecker } from '../../containers/cli'
|
||||||
|
|
||||||
export const newCommand = asyncHandler(async (req: Request, res: Response) => {
|
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 { sessionId } = req.user as any
|
||||||
const session = await Session.findById(sessionId)
|
const session = await Session.findById(sessionId)
|
||||||
@@ -40,10 +45,10 @@ export const newCommand = asyncHandler(async (req: Request, res: Response) => {
|
|||||||
new CLIFileExistenceChecker(session.containerId!)
|
new CLIFileExistenceChecker(session.containerId!)
|
||||||
)
|
)
|
||||||
|
|
||||||
const event = await gameSession.runCommand(command)
|
const event = await gameSession.runCommand(body)
|
||||||
|
|
||||||
const c = new Command({
|
const c = new Command({
|
||||||
...command,
|
...body,
|
||||||
session: sessionId,
|
session: sessionId,
|
||||||
stage: event,
|
stage: event,
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in new issue
Block a user