From 067667da1eea4c63505964cc4c32aa06e88bae01 Mon Sep 17 00:00:00 2001
From: YinDongfang <1136005348@qq.com>
Date: Sat, 1 Feb 2025 22:14:27 +0800
Subject: [PATCH 1/2] Fix validation error of container id
---
Client/src/Pages/Uptime/Create/index.jsx | 16 +++++++----
Client/src/Validation/validation.js | 34 ++++++++++++++----------
2 files changed, 31 insertions(+), 19 deletions(-)
diff --git a/Client/src/Pages/Uptime/Create/index.jsx b/Client/src/Pages/Uptime/Create/index.jsx
index 9086c87af..a0fcce43b 100644
--- a/Client/src/Pages/Uptime/Create/index.jsx
+++ b/Client/src/Pages/Uptime/Create/index.jsx
@@ -88,7 +88,7 @@ const CreateMonitor = () => {
? `http${https ? "s" : ""}://` + monitor.url
: monitor.url,
port: monitor.type === "port" ? monitor.port : undefined,
- name: monitor.name === "" ? monitor.url : monitor.name,
+ name: monitor.name || monitor.url.substring(0, 50),
type: monitor.type,
interval: monitor.interval * MS_PER_MINUTE,
};
@@ -122,7 +122,7 @@ const CreateMonitor = () => {
form = {
...form,
- description: form.name,
+ description: monitor.name || monitor.url,
teamId: user.teamId,
userId: user._id,
notifications: monitor.notifications,
@@ -138,17 +138,23 @@ const CreateMonitor = () => {
const handleChange = (event, formName) => {
const { value } = event.target;
- setMonitor({
+
+ const newMonitor = {
...monitor,
[formName]: value,
- });
+ };
+ if (formName === 'type') {
+ newMonitor.url = '';
+ }
+ setMonitor(newMonitor);
const { error } = monitorValidation.validate(
- { [formName]: value },
+ { type: monitor.type, [formName]: value },
{ abortEarly: false }
);
setErrors((prev) => ({
...prev,
+ url: undefined,
...(error ? { [formName]: error.details[0].message } : { [formName]: undefined }),
}));
};
diff --git a/Client/src/Validation/validation.js b/Client/src/Validation/validation.js
index e40a9c174..ec9245cdb 100644
--- a/Client/src/Validation/validation.js
+++ b/Client/src/Validation/validation.js
@@ -91,13 +91,17 @@ const credentials = joi.object({
});
const monitorValidation = joi.object({
- url: joi
- .string()
- .trim()
- .custom((value, helpers) => {
- // Regex from https://gist.github.com/dperini/729294
- var urlRegex = new RegExp(
- "^" +
+ url: joi.when('type', {
+ is: 'docker',
+ then: joi.string()
+ .trim().regex(/^[a-z0-9]{64}$/),
+ otherwise: joi
+ .string()
+ .trim()
+ .custom((value, helpers) => {
+ // Regex from https://gist.github.com/dperini/729294
+ var urlRegex = new RegExp(
+ "^" +
// protocol identifier (optional)
// short syntax // still required
"(?:(?:https?|ftp):\\/\\/)?" +
@@ -130,18 +134,20 @@ const monitorValidation = joi.object({
// resource path (optional)
"(?:[/?#]\\S*)?" +
"$",
- "i"
- );
- if (!urlRegex.test(value)) {
- return helpers.error("string.invalidUrl");
- }
+ "i"
+ );
+ if (!urlRegex.test(value)) {
+ return helpers.error("string.invalidUrl");
+ }
- return value;
- })
+ return value;
+ })
+ })
.messages({
"string.empty": "This field is required.",
"string.uri": "The URL you provided is not valid.",
"string.invalidUrl": "Please enter a valid URL with optional port",
+ "string.pattern.base": "Please enter a valid container ID.",
}),
port: joi.number(),
name: joi.string().trim().max(50).allow("").messages({
From 58d22dfa9a51918c165294e795df35a515f799cb Mon Sep 17 00:00:00 2001
From: YinDongfang <1136005348@qq.com>
Date: Sat, 1 Feb 2025 23:01:53 +0800
Subject: [PATCH 2/2] Fix input style error while edit uptime monitor
---
Client/src/Pages/Uptime/Configure/index.jsx | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/Client/src/Pages/Uptime/Configure/index.jsx b/Client/src/Pages/Uptime/Configure/index.jsx
index bdb90891b..4f281a763 100644
--- a/Client/src/Pages/Uptime/Configure/index.jsx
+++ b/Client/src/Pages/Uptime/Configure/index.jsx
@@ -347,7 +347,7 @@ const Configure = () => {
}
+ startAdornment={monitor?.type === "http" && }
id="monitor-url"
label="URL to monitor"
placeholder="google.com"