Skip to content

Commit

Permalink
fix: opt-in for calculated Content-Type
Browse files Browse the repository at this point in the history
  • Loading branch information
aleortega committed Oct 12, 2024
1 parent da804e3 commit 1c0f7d6
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion content/src/controller/handlers/get-content-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,21 @@ import { createContentFileHeaders } from '../utils'

// Method: GET or HEAD
export async function getContentHandler(context: HandlerContextWithPath<'storage', '/contents/:hashId'>) {
const shouldCalculateContentType = context.url.searchParams.has('calculateContentType')
const hash = context.params.hashId

const content: ContentItem | undefined = await context.components.storage.retrieve(hash)
if (!content) {
throw new NotFoundError(`No content found with hash ${hash}`)
}

const calculatedHeaders = await createContentFileHeaders(content, hash)

return {
status: 200,
headers: await createContentFileHeaders(content, hash),
headers: shouldCalculateContentType
? calculatedHeaders
: { ...calculatedHeaders, 'Content-Type': 'application/json' },
body: context.request.method.toUpperCase() === 'GET' ? await content.asRawStream() : undefined
}
}

0 comments on commit 1c0f7d6

Please sign in to comment.