mirror of
https://github.com/wukko/cobalt.git
synced 2024-11-15 04:39:58 +00:00
web/onDemand: check blockId is string, early return if not
This commit is contained in:
parent
479e14778d
commit
315ddb17c1
1 changed files with 35 additions and 34 deletions
|
@ -26,45 +26,46 @@ export async function runWeb(express, app, gitCommit, gitBranch, __dirname) {
|
||||||
|
|
||||||
app.get('/onDemand', (req, res) => {
|
app.get('/onDemand', (req, res) => {
|
||||||
try {
|
try {
|
||||||
if (req.query.blockId) {
|
if (typeof req.query.blockId !== 'string') {
|
||||||
let blockId = req.query.blockId.slice(0, 3);
|
|
||||||
let blockData;
|
|
||||||
switch(blockId) {
|
|
||||||
// changelog history
|
|
||||||
case "0":
|
|
||||||
let history = changelogHistory();
|
|
||||||
if (history) {
|
|
||||||
blockData = createResponse("success", { t: history })
|
|
||||||
} else {
|
|
||||||
blockData = createResponse("error", {
|
|
||||||
t: "couldn't render this block, please try again!"
|
|
||||||
})
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
// celebrations emoji
|
|
||||||
case "1":
|
|
||||||
let celebration = celebrationsEmoji();
|
|
||||||
if (celebration) {
|
|
||||||
blockData = createResponse("success", { t: celebration })
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
blockData = createResponse("error", {
|
|
||||||
t: "couldn't find a block with this id"
|
|
||||||
})
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if (blockData?.body) {
|
|
||||||
return res.status(blockData.status).json(blockData.body);
|
|
||||||
} else {
|
|
||||||
return res.status(204).end();
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
return res.status(400).json({
|
return res.status(400).json({
|
||||||
status: "error",
|
status: "error",
|
||||||
text: "couldn't render this block, please try again!"
|
text: "couldn't render this block, please try again!"
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let blockId = req.query.blockId.slice(0, 3);
|
||||||
|
let blockData;
|
||||||
|
switch(blockId) {
|
||||||
|
// changelog history
|
||||||
|
case "0":
|
||||||
|
let history = changelogHistory();
|
||||||
|
if (history) {
|
||||||
|
blockData = createResponse("success", { t: history })
|
||||||
|
} else {
|
||||||
|
blockData = createResponse("error", {
|
||||||
|
t: "couldn't render this block, please try again!"
|
||||||
|
})
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
// celebrations emoji
|
||||||
|
case "1":
|
||||||
|
let celebration = celebrationsEmoji();
|
||||||
|
if (celebration) {
|
||||||
|
blockData = createResponse("success", { t: celebration })
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
blockData = createResponse("error", {
|
||||||
|
t: "couldn't find a block with this id"
|
||||||
|
})
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (blockData?.body) {
|
||||||
|
return res.status(blockData.status).json(blockData.body);
|
||||||
|
} else {
|
||||||
|
return res.status(204).end();
|
||||||
|
}
|
||||||
} catch {
|
} catch {
|
||||||
return res.status(400).json({
|
return res.status(400).json({
|
||||||
status: "error",
|
status: "error",
|
||||||
|
|
Loading…
Reference in a new issue