feat: add hints to session, update API

This commit is contained in:
wancat committed 2023-08-08 20:38:27 +08:00
1 parent ae61bfc768
commit 6f368f761e
8 files changed
+52 -46

No files matched your search

@@ -6,7 +6,7 @@ import commandHandler from '../../game/commandHandler.js'
export async function newCommand(req, res) {
console.log('new command:', req.body)
const { token, command, pwd, exit_code, output } = req.body
const { token, command, pwd, output, error } = req.body
if (!command) {
res.status(400).json({ message: 'command is required' })
@@ -33,8 +33,8 @@ export async function newCommand(req, res) {
session,
command,
pwd,
exit_code,
output,
error,
})
await c.save()
@@ -3,9 +3,8 @@ import Quest from '../../models/quest.js'
export async function getQuests(req, res) {
const quests = await Quest.find({}).sort({ order: 1 })
res.json(
quests.map(({ name, title, order, _id }) => ({
quests.map(({ title, order, _id }) => ({
_id,
name,
title,
order,
}))
@@ -19,5 +18,6 @@ export async function getQuestDetail(req, res) {
res.status(404).json({ message: 'Quest not found.' })
return
}
res.json(quest)
const { _id, title, order, instruction } = quest
res.json({ _id, title, order, instruction })
}
+1 -1
View File
@@ -28,6 +28,7 @@ const commandHandler = async (session, commandInput) => {
if (!commandMatch || !outputMatch || !errorMatch) return {}
session.completion.push(session.progress)
session.hints.push(...stage.hints)
const nextStage = quest.stages.find((s) => s.id === stage.next)
session.progress = nextStage.id
@@ -35,7 +36,6 @@ const commandHandler = async (session, commandInput) => {
return {
responses: stage.responses,
hint: stage.hint,
}
}
+2 -2
View File
@@ -23,7 +23,7 @@ const stageSchema = new Schema({
type: [String],
required: true,
},
hint: {
hints: {
type: [String],
required: true,
},
@@ -39,7 +39,7 @@ const Quest = model(
_id: String,
title: String,
order: Number,
introduction: String,
instruction: String,
stages: [stageSchema],
})
)
+1
View File
@@ -16,6 +16,7 @@ const Session = model(
finishedAt: Date,
progress: String,
completion: [String],
hints: [String],
},
{ timestamps: true }
)