Tend your corner of the atmosphere. spores.garden turns your AT Protocol records into a personal site with unique themes. Your data never leaves your PDS. Grow something that's truly yours. spores.garden
at main 61 lines 1.4 kB view raw
1/** 2 * Input Validation Utilities 3 * 4 * Provides validation for user inputs before saving to PDS. 5 */ 6 7export interface ValidationResult { 8 valid: boolean; 9 error?: string; 10 sanitized?: string; 11} 12 13/** 14 * Validate site title 15 */ 16export function validateTitle(title: string): ValidationResult { 17 if (!title) return { valid: true, sanitized: '' }; 18 19 const trimmed = title.trim(); 20 if (trimmed.length > 100) { 21 return { valid: false, error: 'Title must be 100 characters or less' }; 22 } 23 24 return { valid: true, sanitized: trimmed }; 25} 26 27/** 28 * Validate site subtitle 29 */ 30export function validateSubtitle(subtitle: string): ValidationResult { 31 if (!subtitle) return { valid: true, sanitized: '' }; 32 33 const trimmed = subtitle.trim(); 34 if (trimmed.length > 200) { 35 return { valid: false, error: 'Subtitle must be 200 characters or less' }; 36 } 37 38 return { valid: true, sanitized: trimmed }; 39} 40 41/** 42 * Validate content block 43 */ 44export function validateContent(content: string, maxLength = 50000): ValidationResult { 45 if (!content) { 46 return { valid: false, error: 'Content is required' }; 47 } 48 49 const trimmed = content.trim(); 50 if (trimmed.length === 0) { 51 return { valid: false, error: 'Content cannot be empty' }; 52 } 53 54 if (trimmed.length > maxLength) { 55 return { valid: false, error: `Content must be ${maxLength} characters or less` }; 56 } 57 58 return { valid: true, sanitized: trimmed }; 59} 60 61