mirror of
https://github.com/fosrl/pangolin.git
synced 2026-02-10 20:02:26 +00:00
create target validator and add url validator
This commit is contained in:
@@ -62,40 +62,11 @@ import {
|
||||
SettingsSectionFooter
|
||||
} from "@app/components/Settings";
|
||||
import { SwitchInput } from "@app/components/SwitchInput";
|
||||
import { useSiteContext } from "@app/hooks/useSiteContext";
|
||||
import { InfoPopup } from "@app/components/ui/info-popup";
|
||||
import { useRouter } from "next/navigation";
|
||||
|
||||
// Regular expressions for validation
|
||||
const DOMAIN_REGEX =
|
||||
/^[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/;
|
||||
const IPV4_REGEX =
|
||||
/^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/;
|
||||
const IPV6_REGEX = /^(?:[A-F0-9]{1,4}:){7}[A-F0-9]{1,4}$/i;
|
||||
|
||||
// // Schema for domain names and IP addresses
|
||||
// const domainSchema = z
|
||||
// .string()
|
||||
// .min(1, "Domain cannot be empty")
|
||||
// .max(255, "Domain name too long")
|
||||
// .refine(
|
||||
// (value) => {
|
||||
// // Check if it's a valid IP address (v4 or v6)
|
||||
// if (IPV4_REGEX.test(value) || IPV6_REGEX.test(value)) {
|
||||
// return true;
|
||||
// }
|
||||
//
|
||||
// // Check if it's a valid domain name
|
||||
// return DOMAIN_REGEX.test(value);
|
||||
// },
|
||||
// {
|
||||
// message: "Invalid domain name or IP address format",
|
||||
// path: ["domain"]
|
||||
// }
|
||||
// );
|
||||
import { isTargetValid } from "@server/lib/validators";
|
||||
|
||||
const addTargetSchema = z.object({
|
||||
ip: z.string().min(1).max(255),
|
||||
ip: z.string().refine(isTargetValid),
|
||||
method: z.string().nullable(),
|
||||
port: z.coerce.number().int().positive()
|
||||
// protocol: z.string(),
|
||||
|
||||
Reference in New Issue
Block a user