Skip to content

Commit

Permalink
Merge branch 'main' into dependabot/npm_and_yarn/dcl/catalyst-storage…
Browse files Browse the repository at this point in the history
…-4.3.0
  • Loading branch information
pentreathm authored Oct 14, 2024
2 parents 3005129 + 2230b08 commit 9975f5c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
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.request.headers.get('Accept') === 'Any'
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/octet-stream' },
body: context.request.method.toUpperCase() === 'GET' ? await content.asRawStream() : undefined
}
}
10 changes: 5 additions & 5 deletions content/test/integration/controller/entity-metadata.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ describe('Integration - Get wearable image and thumbnail', () => {
})

describe('image', () => {
it('when entity has not image, it should return 404', async () => {
it('when entity has not image, it should return 404 with', async () => {
const deployResult = await buildDeployData(['wearable'], {
metadata: { thumbnail: 'some-binary-file.png' },
contentPaths: ['test/integration/resources/some-binary-file.png']
Expand All @@ -107,8 +107,8 @@ describe('Integration - Get wearable image and thumbnail', () => {
await server.deployEntity(deployResult.deployData)

const responses = await Promise.all([
fetch(`${server.getUrl()}/queries/items/wearable/image`),
fetch(`${server.getUrl()}/queries/items/wearable/image`, { method: 'HEAD' })
fetch(`${server.getUrl()}/queries/items/wearable/image`, { headers: { Accept: 'Any' } }),
fetch(`${server.getUrl()}/queries/items/wearable/image`, { method: 'HEAD', headers: { Accept: 'Any' } })
])

for (const response of responses) {
Expand All @@ -125,8 +125,8 @@ describe('Integration - Get wearable image and thumbnail', () => {
await server.deployEntity(deployResult.deployData)

const responses = await Promise.all([
fetch(`${server.getUrl()}/queries/items/wearable/image`),
fetch(`${server.getUrl()}/queries/items/wearable/image`, { method: 'HEAD' })
fetch(`${server.getUrl()}/queries/items/wearable/image`, { headers: { Accept: 'Any' } }),
fetch(`${server.getUrl()}/queries/items/wearable/image`, { method: 'HEAD', headers: { Accept: 'Any' } })
])

for (const response of responses) {
Expand Down

0 comments on commit 9975f5c

Please sign in to comment.