mirror of
https://github.com/linux-odyssey/linux-odyssey.git
synced 2026-11-08 11:30:12 +08:00
fix: no callback found error
This commit is contained in:
1 parent
c6f45e10e0
commit
d07b38c7d6
2 files changed
+34
-30
No files matched your search
+33
-29
@@ -6,6 +6,23 @@ const axios = require('axios')
|
|||||||
const { colorize, printResponses, printHints } = require('./print.js')
|
const { colorize, printResponses, printHints } = require('./print.js')
|
||||||
const discoverFiles = require('./discover.js')
|
const discoverFiles = require('./discover.js')
|
||||||
|
|
||||||
|
const {
|
||||||
|
API_ENDPOINT,
|
||||||
|
TOKEN,
|
||||||
|
PWD,
|
||||||
|
CMD_NAME,
|
||||||
|
CMD_OUTPUT_FILE,
|
||||||
|
CMD_ERROR_FILE,
|
||||||
|
CMD_EXIT_CODE,
|
||||||
|
} = process.env
|
||||||
|
|
||||||
|
const api = axios.create({
|
||||||
|
baseURL: `${API_ENDPOINT}/api/v1`,
|
||||||
|
headers: {
|
||||||
|
Authorization: `Bearer ${TOKEN}`,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
async function readOrNone(file) {
|
async function readOrNone(file) {
|
||||||
try {
|
try {
|
||||||
return await fs.readFile(file, 'utf8')
|
return await fs.readFile(file, 'utf8')
|
||||||
@@ -29,24 +46,21 @@ async function handleCommand(command) {
|
|||||||
}, {})
|
}, {})
|
||||||
}
|
}
|
||||||
|
|
||||||
async function main() {
|
async function handleResponse({ responses, hints, end }) {
|
||||||
const {
|
if (responses) {
|
||||||
API_ENDPOINT,
|
await printResponses(responses, 60)
|
||||||
TOKEN,
|
}
|
||||||
PWD,
|
if (hints) {
|
||||||
CMD_NAME,
|
await printHints(hints, 60)
|
||||||
CMD_OUTPUT_FILE,
|
}
|
||||||
CMD_ERROR_FILE,
|
if (end) {
|
||||||
CMD_EXIT_CODE,
|
console.log(colorize('Quest completed!', 'blue'))
|
||||||
} = process.env
|
}
|
||||||
if (!CMD_NAME) exit(0)
|
await api.post('/commands/completed')
|
||||||
|
}
|
||||||
|
|
||||||
const api = axios.create({
|
async function main() {
|
||||||
baseURL: `${API_ENDPOINT}/api/v1`,
|
if (!CMD_NAME) exit(0)
|
||||||
headers: {
|
|
||||||
Authorization: `Bearer ${TOKEN}`,
|
|
||||||
},
|
|
||||||
})
|
|
||||||
|
|
||||||
const params = await handleCommand(CMD_NAME)
|
const params = await handleCommand(CMD_NAME)
|
||||||
|
|
||||||
@@ -62,18 +76,8 @@ async function main() {
|
|||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
const res = await api.post('/commands', payload)
|
const res = await api.post('/commands', payload)
|
||||||
if (!res.data) return
|
if (!res.data || !res.data.responses) return
|
||||||
const { responses, hints, end } = res.data
|
await handleResponse(res.data)
|
||||||
if (responses) {
|
|
||||||
await printResponses(responses, 60)
|
|
||||||
}
|
|
||||||
if (hints) {
|
|
||||||
await printHints(hints, 60)
|
|
||||||
}
|
|
||||||
if (end) {
|
|
||||||
console.log(colorize('Quest completed!', 'blue'))
|
|
||||||
}
|
|
||||||
await api.post('/commands/completed')
|
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
if (err.response) {
|
if (err.response) {
|
||||||
console.error(err.response.data)
|
console.error(err.response.data)
|
||||||
|
|||||||
@@ -72,7 +72,7 @@ export const completedCommand = asyncHandler(async (req, res) => {
|
|||||||
|
|
||||||
const callback = commandCompleteCallbacks.get(session.id)
|
const callback = commandCompleteCallbacks.get(session.id)
|
||||||
if (!callback) {
|
if (!callback) {
|
||||||
res.status(400).json({ message: 'no callback found' })
|
res.status(200).json({ message: 'no callback found' })
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
callback()
|
callback()
|
||||||
|
|||||||
Reference in new issue
Block a user