(filePath: string)
| 110 | * @throws ImportError if the file exceeds the size limit |
| 111 | */ |
| 112 | export async function validateFileSize(filePath: string): Promise<number> { |
| 113 | const stats = await fs.stat(filePath) |
| 114 | |
| 115 | if (stats.size <= 0) { |
| 116 | throw new ImportError('File is empty', 400) |
| 117 | } |
| 118 | |
| 119 | if (stats.size > MAX_FILE_SIZE) { |
| 120 | const sizeMB = Math.round(MAX_FILE_SIZE / (1024 * 1024)) |
| 121 | throw new ImportError(`File exceeds ${sizeMB}MB limit`, 413) |
| 122 | } |
| 123 | |
| 124 | const fileName = basename(filePath) |
| 125 | if (fileName.length > 255) { |
| 126 | throw new ImportError('File name is too long (max 255 characters)', 400) |
| 127 | } |
| 128 | |
| 129 | return stats.size |
| 130 | } |
| 131 | |
| 132 | /** |
| 133 | * Custom error class for import-related errors. |
no outgoing calls
no test coverage detected