remover unnecessary return
routes/api.js - dispatchcommand refactored
This commit is contained in:
+4
-1
@@ -26,8 +26,10 @@ export const translate = (x) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const dispatchCommand = async (cmd, table, params, res) => {
|
export const dispatchCommand = async (cmd, table, params, res) => {
|
||||||
|
let notfound = true
|
||||||
for (let c of table) {
|
for (let c of table) {
|
||||||
if (c.cmd === cmd) {
|
if (c.cmd === cmd) {
|
||||||
|
notfound = false
|
||||||
let erg = await c.func(params)
|
let erg = await c.func(params)
|
||||||
if (typeof erg === 'string') {
|
if (typeof erg === 'string') {
|
||||||
res.type('text')
|
res.type('text')
|
||||||
@@ -35,11 +37,12 @@ export const dispatchCommand = async (cmd, table, params, res) => {
|
|||||||
} else {
|
} else {
|
||||||
res.json(erg)
|
res.json(erg)
|
||||||
}
|
}
|
||||||
return
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (notfound) {
|
||||||
res.json({err: translate('CMNDUNKNOWN')})
|
res.json({err: translate('CMNDUNKNOWN')})
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// normal routes called from javascript client
|
// normal routes called from javascript client
|
||||||
apiRouter.get('/:cmd', async (req, res) => {
|
apiRouter.get('/:cmd', async (req, res) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user