mirror of
https://github.com/thepeacockproject/Peacock
synced 2024-11-22 22:12:45 +01:00
Escalation picker fixes and improvements (#61)
This commit is contained in:
parent
3801d41048
commit
e7fb1c9211
@ -127,7 +127,10 @@ app.use("/_wf", webFeaturesRouter)
|
|||||||
|
|
||||||
app.get("/", (req: Request, res) => {
|
app.get("/", (req: Request, res) => {
|
||||||
if (PEACOCK_DEV) {
|
if (PEACOCK_DEV) {
|
||||||
res.send("dev active, you need to access the UI from port 3000")
|
res.contentType("text/html")
|
||||||
|
res.send(
|
||||||
|
'<html> PEACOCK_DEV active, please run "yarn webui start" to start the web UI on port 3000 and access it there. </html>',
|
||||||
|
)
|
||||||
} else {
|
} else {
|
||||||
const data = readFileSync("webui/dist/index.html").toString()
|
const data = readFileSync("webui/dist/index.html").toString()
|
||||||
|
|
||||||
|
@ -24,6 +24,9 @@ import { join } from "path"
|
|||||||
import { uuidRegex } from "./utils"
|
import { uuidRegex } from "./utils"
|
||||||
import { getUserData, loadUserData, writeUserData } from "./databaseHandler"
|
import { getUserData, loadUserData, writeUserData } from "./databaseHandler"
|
||||||
import { readdirSync } from "fs"
|
import { readdirSync } from "fs"
|
||||||
|
import { getLevelCount } from "./contracts/escalations/escalationService"
|
||||||
|
import { controller } from "./controller"
|
||||||
|
import { log, LogLevel } from "./loggingInterop"
|
||||||
|
|
||||||
const webFeaturesRouter = Router()
|
const webFeaturesRouter = Router()
|
||||||
|
|
||||||
@ -39,6 +42,13 @@ if (PEACOCK_DEV) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function formErrorMessage(res: Response, message: string): void {
|
||||||
|
res.json({
|
||||||
|
success: false,
|
||||||
|
error: message,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
webFeaturesRouter.get("/codenames", (req, res) => {
|
webFeaturesRouter.get("/codenames", (req, res) => {
|
||||||
res.json(getConfig("EscalationCodenames", false))
|
res.json(getConfig("EscalationCodenames", false))
|
||||||
})
|
})
|
||||||
@ -50,7 +60,7 @@ webFeaturesRouter.get(
|
|||||||
!req.query.gv ||
|
!req.query.gv ||
|
||||||
!["h1", "h2", "h3"].includes(req.query.gv ?? null)
|
!["h1", "h2", "h3"].includes(req.query.gv ?? null)
|
||||||
) {
|
) {
|
||||||
res.json({ error: "bad gv" })
|
res.json([])
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -89,12 +99,15 @@ function validateUserAndGv(
|
|||||||
res: Response,
|
res: Response,
|
||||||
): boolean {
|
): boolean {
|
||||||
if (!req.query.gv || !["h1", "h2", "h3"].includes(req.query.gv ?? null)) {
|
if (!req.query.gv || !["h1", "h2", "h3"].includes(req.query.gv ?? null)) {
|
||||||
res.json({ error: "bad gv" })
|
formErrorMessage(
|
||||||
|
res,
|
||||||
|
'The request must contain a valid game version among "h1", "h2", and "h3".',
|
||||||
|
)
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!req.query.user || !uuidRegex.test(req.query.user)) {
|
if (!req.query.user || !uuidRegex.test(req.query.user)) {
|
||||||
res.json({ error: "bad user" })
|
formErrorMessage(res, "The request must contain the uuid of a user.")
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -115,24 +128,55 @@ webFeaturesRouter.get(
|
|||||||
if (!validateUserAndGv(req, res)) {
|
if (!validateUserAndGv(req, res)) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
if (!req.query.level) {
|
||||||
if (!req.query.level && !isNaN(parseInt(req.query.level))) {
|
formErrorMessage(
|
||||||
res.json({ error: "bad level" })
|
res,
|
||||||
|
"The request must contain the level to set the escalation to.",
|
||||||
|
)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if (
|
||||||
|
isNaN(parseInt(req.query.level)) ||
|
||||||
|
parseInt(req.query.level) <= 0
|
||||||
|
) {
|
||||||
|
formErrorMessage(res, "The level must be a positive integer.")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!req.query.id && !uuidRegex.test(req.query.id)) {
|
if (!req.query.id || !uuidRegex.test(req.query.id)) {
|
||||||
res.json({ error: "bad id" })
|
formErrorMessage(
|
||||||
|
res,
|
||||||
|
"The request must contain the uuid of an escalation.",
|
||||||
|
)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await loadUserData(req.query.user, req.query.gv)
|
await loadUserData(req.query.user, req.query.gv)
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
res.json({ error: "failed to load user data" })
|
formErrorMessage(res, "Failed to load user data.")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if (controller.escalationMappings[req.query.id] === undefined) {
|
||||||
|
formErrorMessage(res, "Unknown escalation.")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (
|
||||||
|
getLevelCount(controller.escalationMappings[req.query.id]) <
|
||||||
|
parseInt(req.query.level, 10)
|
||||||
|
) {
|
||||||
|
formErrorMessage(
|
||||||
|
res,
|
||||||
|
"Cannot exceed the maximum level for this escalation!",
|
||||||
|
)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
log(
|
||||||
|
LogLevel.INFO,
|
||||||
|
`Setting the level of escalation ${req.query.id} to ${req.query.level}`,
|
||||||
|
)
|
||||||
const read = getUserData(req.query.user, req.query.gv)
|
const read = getUserData(req.query.user, req.query.gv)
|
||||||
|
|
||||||
read.Extensions.PeacockEscalations[req.query.id] = parseInt(
|
read.Extensions.PeacockEscalations[req.query.id] = parseInt(
|
||||||
@ -163,7 +207,7 @@ webFeaturesRouter.get(
|
|||||||
try {
|
try {
|
||||||
await loadUserData(req.query.user, req.query.gv)
|
await loadUserData(req.query.user, req.query.gv)
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
res.json({ error: "failed to load user data" })
|
formErrorMessage(res, "Failed to load user data.")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -514,7 +514,7 @@
|
|||||||
{
|
{
|
||||||
"codename": "Snake's Head",
|
"codename": "Snake's Head",
|
||||||
"name": "The Baskerville Barney",
|
"name": "The Baskerville Barney",
|
||||||
"id": "5680108a-19dc-4448-9344-3d0290217162"
|
"id": "b12d08ea-c842-498a-82ea-889653588592"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"codename": "Harebell",
|
"codename": "Harebell",
|
||||||
|
@ -78,10 +78,18 @@ export function EscalationLevelPicker({
|
|||||||
level: fork[id],
|
level: fork[id],
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
.then(() => console.debug("Changes made"))
|
.then((value) => {
|
||||||
.catch(console.error)
|
let message: string
|
||||||
|
if (value.data.success) {
|
||||||
|
message = "Changes made. "
|
||||||
setProgressWeb(fork)
|
setProgressWeb(fork)
|
||||||
|
} else {
|
||||||
|
message = "Error: " + value.data.error
|
||||||
|
alert(message)
|
||||||
|
}
|
||||||
|
return console.debug(message)
|
||||||
|
})
|
||||||
|
.catch(console.error)
|
||||||
}
|
}
|
||||||
|
|
||||||
//#region Bootleg column paginator
|
//#region Bootleg column paginator
|
||||||
|
Loading…
Reference in New Issue
Block a user