(
image: ResolvedInlineImage,
{ sniff }: { sniff: boolean }
)
| 20 | * stored content type is served, matching the in-app serve route. |
| 21 | */ |
| 22 | export 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 | } |
no test coverage detected