Skip to content

Commit bb81f53

Browse files
authored
updates on rules
1 parent 217b350 commit bb81f53

1 file changed

Lines changed: 51 additions & 5 deletions

File tree

src/lib/config.ts

Lines changed: 51 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ export const CONFIG = {
66

77
// File Upload
88
MAX_FILE_SIZE: 50 * 1024 * 1024, // 50MB
9+
10+
// MIME types
911
ALLOWED_FILE_TYPES: [
1012
// Documents
1113
'application/pdf',
@@ -16,17 +18,42 @@ export const CONFIG = {
1618
'application/vnd.ms-powerpoint',
1719
'application/vnd.openxmlformats-officedocument.presentationml.presentation',
1820
'text/plain',
21+
1922
// Images
2023
'image/jpeg',
2124
'image/png',
2225
'image/gif',
2326
'image/webp',
27+
2428
// Videos
2529
'video/mp4',
2630
'video/webm',
2731
'video/quicktime',
2832
],
2933

34+
// Extension fallback (IMPORTANT for pptx, docx, etc.)
35+
ALLOWED_EXTENSIONS: [
36+
'pdf',
37+
'doc',
38+
'docx',
39+
'xls',
40+
'xlsx',
41+
'ppt',
42+
'pptx',
43+
'txt',
44+
'csv',
45+
'jpg',
46+
'jpeg',
47+
'png',
48+
'gif',
49+
'webp',
50+
'mp4',
51+
'webm',
52+
'mov',
53+
'avi',
54+
'mkv'
55+
],
56+
3057
// Password Requirements
3158
PASSWORD_MIN_LENGTH: 8,
3259
PASSWORD_REQUIRE_UPPERCASE: true,
@@ -38,15 +65,33 @@ export const CONFIG = {
3865
UNDO_DURATION_MS: 30000, // 30 seconds
3966
} as const;
4067

41-
// Utility functions
68+
69+
// Email validation
4270
export const isAllowedEmail = (email: string): boolean => {
4371
return email.endsWith(CONFIG.ALLOWED_EMAIL_DOMAIN);
4472
};
4573

46-
export const isAllowedFileType = (fileType: string): boolean => {
47-
return CONFIG.ALLOWED_FILE_TYPES.includes(fileType as any);
74+
75+
// ✅ FIXED: Now accepts File instead of string
76+
export const isAllowedFileType = (file: File): boolean => {
77+
const mimeType = file.type;
78+
const ext = file.name.split('.').pop()?.toLowerCase() || '';
79+
80+
// 1) Check MIME type
81+
if (mimeType && CONFIG.ALLOWED_FILE_TYPES.includes(mimeType as any)) {
82+
return true;
83+
}
84+
85+
// 2) Fallback to extension (handles pptx/docx when browser sends wrong type)
86+
if (CONFIG.ALLOWED_EXTENSIONS.includes(ext)) {
87+
return true;
88+
}
89+
90+
return false;
4891
};
4992

93+
94+
// Password validation
5095
export const validatePassword = (password: string): { valid: boolean; message?: string } => {
5196
if (password.length < CONFIG.PASSWORD_MIN_LENGTH) {
5297
return { valid: false, message: `Password must be at least ${CONFIG.PASSWORD_MIN_LENGTH} characters` };
@@ -66,10 +111,11 @@ export const validatePassword = (password: string): { valid: boolean; message?:
66111
return { valid: true };
67112
};
68113

114+
69115
// Input sanitization
70116
export const sanitizeInput = (input: string): string => {
71117
return input
72118
.trim()
73-
.replace(/[<>]/g, '') // Remove < and > to prevent basic XSS
74-
.replace(/\s+/g, ' '); // Normalize whitespace
119+
.replace(/[<>]/g, '')
120+
.replace(/\s+/g, ' ');
75121
};

0 commit comments

Comments
 (0)