Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 20 additions & 9 deletions lib/constants/upload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@ export const ALLOWED_IMAGE_TYPES = new Set([
"image/heif",
]);

export const ALLOWED_DOCUMENT_TYPES = new Set([
"application/pdf",
]);
export const ALLOWED_DOCUMENT_TYPES = new Set(["application/pdf"]);

export const ALLOWED_GENERAL_TYPES = new Set([
"application/pdf",
Expand All @@ -48,6 +46,7 @@ export const ALLOWED_GENERAL_TYPES = new Set([

// Dangerous file extensions to block
export const DANGEROUS_EXTENSIONS = [
// Executables
".exe",
".bat",
".cmd",
Expand All @@ -58,6 +57,17 @@ export const DANGEROUS_EXTENSIONS = [
".app",
".deb",
".rpm",
// Scripts
".php",
".sh",
".py",
".pl",
".cgi",
// Web Content
".html",
".htm",
".svg",
".xml",
];

// Upload configuration
Expand All @@ -70,7 +80,7 @@ export const CHUNK_SIZE = 5 * 1024 * 1024; // 5MB chunks for resumable uploads
*/
export function validateFileSize(
fileSize: number,
maxSize: number
maxSize: number,
): { valid: boolean; error?: string } {
if (fileSize === 0) {
return { valid: false, error: "File is empty" };
Expand All @@ -89,9 +99,10 @@ export function validateFileSize(
/**
* Validate file name
*/
export function validateFileName(
fileName: string
): { valid: boolean; error?: string } {
export function validateFileName(fileName: string): {
valid: boolean;
error?: string;
} {
if (!fileName || fileName.trim().length === 0) {
Comment on lines +102 to 106
return { valid: false, error: "File name is required" };
}
Expand All @@ -117,7 +128,7 @@ export function validateFileName(
*/
export function validateMimeType(
mimeType: string,
allowedTypes: Set<string>
allowedTypes: Set<string>,
): { valid: boolean; error?: string } {
if (!mimeType) {
return { valid: false, error: "File type is required" };
Expand All @@ -141,7 +152,7 @@ export function validateFile(
fileSize: number,
mimeType: string,
allowedTypes: Set<string>,
maxSize: number
maxSize: number,
): { valid: boolean; error?: string } {
// Validate file name
const nameValidation = validateFileName(fileName);
Expand Down