mirror of
https://github.com/linux-odyssey/linux-odyssey.git
synced 2026-11-06 03:20:13 +08:00
feat: push discover event to frontend
This commit is contained in:
1 parent
c0186c6a30
commit
096b7a7714
5 files changed
+33
-3
No files matched your search
@@ -1,4 +1,5 @@
|
||||
import Quest from '../models/quest.js'
|
||||
import { pushToSession } from '../api/socket.js'
|
||||
|
||||
// 檢查 pattern 是否符合 input
|
||||
const checkMatch = (pattern, input) => {
|
||||
@@ -9,7 +10,7 @@ const checkMatch = (pattern, input) => {
|
||||
})
|
||||
}
|
||||
|
||||
const commandHandler = async (session, commandInput) => {
|
||||
async function commandHandler(session, commandInput, additionalData) {
|
||||
const quest = await Quest.findById(session.quest)
|
||||
const stage = quest.stages.find((s) => s.id === session.progress)
|
||||
if (!stage) {
|
||||
@@ -17,6 +18,13 @@ const commandHandler = async (session, commandInput) => {
|
||||
return {}
|
||||
}
|
||||
|
||||
if ('discover' in additionalData) {
|
||||
pushToSession(session.id, 'graph', {
|
||||
pwd: commandInput.pwd,
|
||||
discover: additionalData.discover,
|
||||
})
|
||||
}
|
||||
|
||||
const commandMatch = checkMatch(stage.condition.command, commandInput.command)
|
||||
const outputMatch = checkMatch(stage.condition.output, commandInput.output)
|
||||
const errorMatch = checkMatch(stage.condition.error, commandInput.output)
|
||||
|
||||
Reference in new issue
Block a user