undone
This commit is contained in:
@@ -205,8 +205,7 @@ export function debounce<T extends (...args: any[]) => any>(
|
||||
// ============================================================================
|
||||
|
||||
/**
|
||||
* Validates that a comment body meets requirements (client-side UX only)
|
||||
* Server validation is in src/server/api/schemas/validation.ts
|
||||
* Validates that a comment body meets requirements
|
||||
*/
|
||||
export function isValidCommentBody(body: string): boolean {
|
||||
return body.trim().length > 0 && body.length <= 10000;
|
||||
|
||||
@@ -1,62 +1,18 @@
|
||||
/**
|
||||
* Client-side Date Utilities
|
||||
*
|
||||
* ⚠️ DEPRECATED: For new code, use server-side date utilities in src/server/date-utils.ts
|
||||
*
|
||||
* This function is kept for backward compatibility with existing client code.
|
||||
* Server-side code should use src/server/date-utils.ts instead.
|
||||
*
|
||||
* Note: This previously had a hardcoded +4 hour offset which was incorrect.
|
||||
* Now properly returns UTC time.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Get current UTC date/time formatted for SQL insert
|
||||
*
|
||||
* @deprecated Use server-side getSQLFormattedDate from ~/server/utils instead
|
||||
* @returns SQL-formatted date string (YYYY-MM-DD HH:MM:SS) in UTC
|
||||
* Formats current date to match SQL datetime format
|
||||
* Note: Adds 4 hours to match server timezone (EST)
|
||||
* Returns format: YYYY-MM-DD HH:MM:SS
|
||||
*/
|
||||
export function getSQLFormattedDate(): string {
|
||||
const date = new Date();
|
||||
date.setHours(date.getHours() + 4);
|
||||
|
||||
const year = date.getUTCFullYear();
|
||||
const month = `${date.getUTCMonth() + 1}`.padStart(2, "0");
|
||||
const day = `${date.getUTCDate()}`.padStart(2, "0");
|
||||
const hours = `${date.getUTCHours()}`.padStart(2, "0");
|
||||
const minutes = `${date.getUTCMinutes()}`.padStart(2, "0");
|
||||
const seconds = `${date.getUTCSeconds()}`.padStart(2, "0");
|
||||
const year = date.getFullYear();
|
||||
const month = `${date.getMonth() + 1}`.padStart(2, "0");
|
||||
const day = `${date.getDate()}`.padStart(2, "0");
|
||||
const hours = `${date.getHours()}`.padStart(2, "0");
|
||||
const minutes = `${date.getMinutes()}`.padStart(2, "0");
|
||||
const seconds = `${date.getSeconds()}`.padStart(2, "0");
|
||||
|
||||
return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
|
||||
}
|
||||
|
||||
/**
|
||||
* Format a date for relative display (client-side)
|
||||
* e.g., "5m ago", "2h ago", "Dec 19"
|
||||
*
|
||||
* @param dateString SQL date string or ISO string
|
||||
* @returns Formatted relative time string
|
||||
*/
|
||||
export function formatRelativeDate(dateString: string): string {
|
||||
const date = new Date(dateString);
|
||||
const now = new Date();
|
||||
const diffMs = now.getTime() - date.getTime();
|
||||
const diffMins = Math.floor(diffMs / 60000);
|
||||
const diffHours = Math.floor(diffMs / 3600000);
|
||||
const diffDays = Math.floor(diffMs / 86400000);
|
||||
|
||||
if (diffMins < 1) {
|
||||
return "just now";
|
||||
} else if (diffMins < 60) {
|
||||
return `${diffMins}m ago`;
|
||||
} else if (diffHours < 24) {
|
||||
return `${diffHours}h ago`;
|
||||
} else if (diffDays < 7) {
|
||||
return `${diffDays}d ago`;
|
||||
} else {
|
||||
return date.toLocaleDateString("en-US", {
|
||||
month: "short",
|
||||
day: "numeric",
|
||||
year: diffDays > 365 ? "numeric" : undefined
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,18 +1,9 @@
|
||||
/**
|
||||
* Client-Side Validation Utilities (UX Only - NOT Security)
|
||||
*
|
||||
* ⚠️ IMPORTANT: These functions are for user experience only!
|
||||
*
|
||||
* Server-side validation in src/server/api/schemas/validation.ts is the
|
||||
* source of truth and security boundary. These client functions provide
|
||||
* instant feedback before submission but can be bypassed.
|
||||
*
|
||||
* Always rely on server validation for security.
|
||||
* Form validation utilities
|
||||
*/
|
||||
|
||||
/**
|
||||
* Validate email format (client-side UX only)
|
||||
* Server validation is in src/server/api/schemas/validation.ts
|
||||
* Validate email format
|
||||
*/
|
||||
export function isValidEmail(email: string): boolean {
|
||||
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
|
||||
@@ -20,8 +11,7 @@ export function isValidEmail(email: string): boolean {
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate password strength (client-side UX only)
|
||||
* Server validation is in src/server/api/schemas/validation.ts
|
||||
* Validate password strength
|
||||
*/
|
||||
export function validatePassword(password: string): {
|
||||
isValid: boolean;
|
||||
@@ -51,8 +41,7 @@ export function validatePassword(password: string): {
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if two passwords match (client-side UX only)
|
||||
* Server validation is in src/server/api/schemas/validation.ts
|
||||
* Check if two passwords match
|
||||
*/
|
||||
export function passwordsMatch(
|
||||
password: string,
|
||||
@@ -62,8 +51,7 @@ export function passwordsMatch(
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate display name (client-side UX only)
|
||||
* Server validation is in src/server/api/schemas/validation.ts
|
||||
* Validate display name
|
||||
*/
|
||||
export function isValidDisplayName(name: string): boolean {
|
||||
return name.trim().length >= 1 && name.trim().length <= 50;
|
||||
|
||||
Reference in New Issue
Block a user