|
8 | 8 | MAX_IMAGE_BASE64_SIZE, |
9 | 9 | MAX_TOTAL_IMAGE_SIZE, |
10 | 10 | IMAGE_EXTENSIONS_PATTERN, |
| 11 | + getImageMimeType, |
11 | 12 | } from '@codebuff/common/constants/images' |
12 | 13 | import { Jimp } from 'jimp' |
13 | 14 |
|
@@ -41,18 +42,6 @@ interface CompressionResult { |
41 | 42 | error?: string |
42 | 43 | } |
43 | 44 |
|
44 | | -// Extension to MIME type mapping |
45 | | -const EXTENSION_TO_MIME: Record<string, string> = { |
46 | | - '.jpg': 'image/jpeg', |
47 | | - '.jpeg': 'image/jpeg', |
48 | | - '.png': 'image/png', |
49 | | - '.webp': 'image/webp', |
50 | | - '.gif': 'image/gif', |
51 | | - '.bmp': 'image/bmp', |
52 | | - '.tiff': 'image/tiff', |
53 | | - '.tif': 'image/tiff', |
54 | | -} |
55 | | - |
56 | 45 | // Compression settings for iterative compression |
57 | 46 | const COMPRESSION_QUALITIES = [85, 70, 50, 30] |
58 | 47 | const DIMENSION_LIMITS = [1500, 1200, 800, 600] |
@@ -97,14 +86,6 @@ function normalizeUserProvidedPath(filePath: string): string { |
97 | 86 | return normalized |
98 | 87 | } |
99 | 88 |
|
100 | | -/** |
101 | | - * Gets MIME type from file extension |
102 | | - */ |
103 | | -function getMimeTypeFromExtension(filePath: string): string | null { |
104 | | - const ext = path.extname(filePath).toLowerCase() |
105 | | - return EXTENSION_TO_MIME[ext] ?? null |
106 | | -} |
107 | | - |
108 | 89 | /** |
109 | 90 | * Validates if a file path is a supported image |
110 | 91 | */ |
@@ -238,7 +219,7 @@ export async function processImageFile( |
238 | 219 | } |
239 | 220 |
|
240 | 221 | // Get MIME type |
241 | | - const mediaType = getMimeTypeFromExtension(resolvedPath) |
| 222 | + const mediaType = getImageMimeType(path.extname(resolvedPath)) |
242 | 223 | if (!mediaType) { |
243 | 224 | return { success: false, error: `Could not determine image type for: ${filePath}` } |
244 | 225 | } |
|
0 commit comments