MCPcopy Index your code
hub / github.com/simstudioai/sim / sniffImageContentType

Function sniffImageContentType

apps/sim/lib/uploads/utils/validation.ts:347–364  ·  view source on GitHub ↗
(buffer: Buffer)

Source from the content-addressed store, hash-verified

345 * or a script. SVG is deliberately excluded: it can carry script and is not a raster format.
346 */
347export function sniffImageContentType(buffer: Buffer): string | null {
348 if (isValidPng(buffer)) return 'image/png'
349 if (buffer.length >= 3 && buffer[0] === 0xff && buffer[1] === 0xd8 && buffer[2] === 0xff) {
350 return 'image/jpeg'
351 }
352 if (buffer.length >= 6) {
353 const header = buffer.toString('latin1', 0, 6)
354 if (header === 'GIF87a' || header === 'GIF89a') return 'image/gif'
355 }
356 if (
357 buffer.length >= 12 &&
358 buffer.toString('latin1', 0, 4) === 'RIFF' &&
359 buffer.toString('latin1', 8, 12) === 'WEBP'
360 ) {
361 return 'image/webp'
362 }
363 return null
364}
365
366export function validateMediaFileType(
367 fileName: string,

Callers 2

validation.test.tsFile · 0.90
serveInlineImageFunction · 0.90

Calls 2

isValidPngFunction · 0.85
toStringMethod · 0.45

Tested by

no test coverage detected