mirror of
https://github.com/monkeytypegame/monkeytype.git
synced 2024-09-20 15:26:15 +08:00
better request validation
This commit is contained in:
parent
c34b56bc50
commit
f76849f921
|
@ -39,9 +39,9 @@ router.post(
|
|||
RateLimit.newQuotesAdd,
|
||||
validateRequest({
|
||||
body: {
|
||||
text: joi.string().min(60).required(),
|
||||
source: joi.string().required(),
|
||||
language: joi.string().required(),
|
||||
text: joi.string().min(60).regex(/^\w+$/).required(),
|
||||
source: joi.string().regex(/^\w+$/).required(),
|
||||
language: joi.string().regex(/^\w+$/).required(),
|
||||
captcha: joi.string().required(),
|
||||
},
|
||||
validationErrorMessage: "Please fill all the fields",
|
||||
|
@ -56,8 +56,8 @@ router.post(
|
|||
validateRequest({
|
||||
body: {
|
||||
quoteId: joi.string().required(),
|
||||
editText: joi.string().allow(null),
|
||||
editSource: joi.string().allow(null),
|
||||
editText: joi.string().regex(/^\w+$/).allow(null),
|
||||
editSource: joi.string().regex(/^\w+$/).allow(null),
|
||||
},
|
||||
validationErrorMessage: "Please fill all the fields",
|
||||
}),
|
||||
|
@ -85,7 +85,7 @@ router.get(
|
|||
validateRequest({
|
||||
query: {
|
||||
quoteId: joi.string().regex(/^\d+$/).required(),
|
||||
language: joi.string().required(),
|
||||
language: joi.string().regex(/^\w+$/).required(),
|
||||
},
|
||||
}),
|
||||
asyncHandler(QuoteController.getRating)
|
||||
|
@ -99,7 +99,7 @@ router.post(
|
|||
body: {
|
||||
quoteId: joi.number().required(),
|
||||
rating: joi.number().min(1).max(5).required(),
|
||||
language: joi.string().required(),
|
||||
language: joi.string().regex(/^\w+$/).required(),
|
||||
},
|
||||
}),
|
||||
asyncHandler(QuoteController.submitRating)
|
||||
|
@ -118,7 +118,7 @@ router.post(
|
|||
validateRequest({
|
||||
body: {
|
||||
quoteId: joi.string().required(),
|
||||
quoteLanguage: joi.string().required(),
|
||||
quoteLanguage: joi.string().regex(/^\w+$/).required(),
|
||||
reason: joi
|
||||
.string()
|
||||
.valid(
|
||||
|
@ -128,7 +128,7 @@ router.post(
|
|||
"Incorrect source"
|
||||
)
|
||||
.required(),
|
||||
comment: joi.string().allow("").max(250).required(),
|
||||
comment: joi.string().allow("").regex(/^\w+$/).max(250).required(),
|
||||
captcha: joi.string().required(),
|
||||
},
|
||||
}),
|
||||
|
|
Loading…
Reference in a new issue