From 5e387096199781177a8894896859b91ef316b2bb Mon Sep 17 00:00:00 2001 From: alphaeusmote <41258468-alphaeusmote@users.noreply.replit.com> Date: Thu, 10 Apr 2025 16:16:49 +0000 Subject: [PATCH] Improve DNS record validation and management. Updated record content validation to depend on record type and removed redundant provider specification. Replit-Commit-Author: Agent Replit-Commit-Session-Id: 9111ef36-26c8-4085-84ca-a35dc1fec1b5 Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/7083d608-d6d3-4a6a-9a27-6286c5109627/86e3ec6b-0662-470c-abd1-1908766a2255.jpg --- .../src/components/domain/domain-details.tsx | 25 +++++++++++++------ 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/client/src/components/domain/domain-details.tsx b/client/src/components/domain/domain-details.tsx index eb98c64..e163d98 100644 --- a/client/src/components/domain/domain-details.tsx +++ b/client/src/components/domain/domain-details.tsx @@ -68,21 +68,32 @@ import { formatDistanceToNow } from "date-fns"; const dnsRecordSchema = z.object({ name: z.string().min(1, "Record name is required"), type: z.enum(recordTypes), - content: z.string().min(1, "Content is required").optional().or(z.literal('')), + content: z.string().optional().or(z.literal('')), ttl: z.number().int().min(1).default(3600), proxied: z.boolean().default(false), isActive: z.boolean().default(true), isAutoIP: z.boolean().default(false), notes: z.string().optional(), - providerId: z.string().uuid().optional(), }).refine(data => { - // Content is required if isAutoIP is false - if (!data.isAutoIP && (!data.content || data.content.trim() === '')) { - return false; + // Different validation based on record type + if ((data.type === 'A' || data.type === 'AAAA') && data.isAutoIP) { + // Auto IP enabled, content not required + return true; + } else if (data.type === 'A') { + // A record - validate IPv4 + return !!data.content && /^(\d{1,3}\.){3}\d{1,3}$/.test(data.content.trim()); + } else if (data.type === 'AAAA') { + // AAAA record - accept any non-empty content for IPv6 (simplified validation) + return !!data.content && data.content.trim().length > 0; + } else if (data.type === 'CNAME' || data.type === 'MX' || data.type === 'NS') { + // Domain-based records - ensure content is present and looks like domain + return !!data.content && data.content.trim().length > 0; + } else { + // For all other types, just ensure content is non-empty + return !!data.content && data.content.trim().length > 0; } - return true; }, { - message: "Content is required when Auto IP is disabled", + message: "Content is required and must be valid for the selected record type", path: ["content"] });