recommended changes

This commit is contained in:
Anurag123Chauhan committed 2025-05-15 11:16:02 +05:30
1 parent 18b439bad6
commit 9da9ef6939
1 file changed
+8 -9
+8 -9
View File
@@ -109,14 +109,15 @@ const monitorValidation = joi.object({
then: joi then: joi
.string() .string()
.trim() .trim()
.regex(/^[a-z0-9]{64}$/), .regex(/^[a-z0-9]{64}$/)
.messages({
"string.empty": "This field is required.",
"string.pattern.base": "Please enter a valid 64-character Docker container ID.",
}),
otherwise: joi otherwise: joi
.string() .string()
.trim() .trim()
.custom((value, helpers) => { .custom((value, helpers) => {
// Get the current validation context
const { type } = helpers.state.ancestors[0];
// Regex from https://gist.github.com/dperini/729294 // Regex from https://gist.github.com/dperini/729294
var urlRegex = new RegExp( var urlRegex = new RegExp(
"^" + "^" +
@@ -155,19 +156,16 @@ const monitorValidation = joi.object({
"i" "i"
); );
if (!urlRegex.test(value)) { if (!urlRegex.test(value)) {
// Use different error key based on monitor type return helpers.error("string.invalidUrl");
return helpers.error(type === "docker" ? "string.invalidDockerID" : "string.invalidUrl");
} }
return value; return value;
}),
}) })
.messages({ .messages({
"string.empty": "This field is required.", "string.empty": "This field is required.",
"string.uri": "The URL you provided is not valid.", "string.uri": "The URL you provided is not valid.",
"string.invalidUrl": "Please enter a valid URL with optional port", "string.invalidUrl": "Please enter a valid URL with optional port",
"string.invalidDockerID": "Please enter a valid 64-character Docker container ID.", }),
"string.pattern.base": "Please enter a valid container ID.",
}), }),
port: joi port: joi
.number() .number()
@@ -270,6 +268,7 @@ const statusPageValidation = joi.object({
showUptimePercentage: joi.boolean(), showUptimePercentage: joi.boolean(),
showCharts: joi.boolean(), showCharts: joi.boolean(),
}); });
const settingsValidation = joi.object({ const settingsValidation = joi.object({
checkTTL: joi.number().required().messages({ checkTTL: joi.number().required().messages({
"string.empty": "Please enter a value", "string.empty": "Please enter a value",