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

Function serveInlineImage

apps/sim/app/api/files/serve-inline-image.ts:22–44  ·  view source on GitHub ↗
(
  image: ResolvedInlineImage,
  { sniff }: { sniff: boolean }
)

Source from the content-addressed store, hash-verified

20 * stored content type is served, matching the in-app serve route.
21 */
22export async function serveInlineImage(
23 image: ResolvedInlineImage,
24 { sniff }: { sniff: boolean }
25): Promise<NextResponse> {
26 const buffer = await downloadFile({ key: image.key, context: 'workspace' })
27
28 let contentType = image.contentType
29 if (sniff) {
30 const sniffed = sniffImageContentType(buffer)
31 if (!sniffed) {
32 logger.warn('Embedded reference is not a renderable image', { key: image.key })
33 throw new FileNotFoundError('Not found')
34 }
35 contentType = sniffed
36 }
37
38 return createFileResponse({
39 buffer,
40 contentType,
41 filename: image.filename,
42 cacheControl: INLINE_CACHE_CONTROL,
43 })
44}

Callers 2

route.tsFile · 0.90
route.tsFile · 0.90

Calls 4

downloadFileFunction · 0.90
sniffImageContentTypeFunction · 0.90
createFileResponseFunction · 0.90
warnMethod · 0.65

Tested by

no test coverage detected