Skip to content

Commit

Permalink
fix: undefined content-type error
Browse files Browse the repository at this point in the history
  • Loading branch information
albanm committed Aug 2, 2024
1 parent 45dfcc5 commit 7d91155
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 13 deletions.
2 changes: 1 addition & 1 deletion server/router/portals.js
Original file line number Diff line number Diff line change
Expand Up @@ -703,7 +703,7 @@ router.get('/:id/uses/:useId/image', asyncWrap(setPortalAnonymous), asyncWrap(as
if (!use.image) return res.status(404).send('use image not found')
res.sendFile(path.join(usesUtils.directory(req.params.id, req.params.useId), 'image'), {
headers: {
'content-type': use.image.type,
'content-type': use.image.type ?? 'image/png',
'cache-control': use.published ? 'public' : 'private'
}
})
Expand Down
20 changes: 8 additions & 12 deletions server/utils/assets.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,18 +128,14 @@ exports.downloadAsset = async (req, res) => {
const filePath = resolvePath(portalDir, req.params.assetId)
if (req.query.hash && req.query.hash !== 'undefined') {
const maxAge = draft ? 0 : 31536000
return res.sendFile(`${filePath}-${req.query.hash}`, {
headers: {
'content-type': mime.contentType(req.query.hash) || mime.contentType(asset.name),
'cache-control': 'public,max-age=' + maxAge
}
})
const headers = { 'cache-control': 'public,max-age=' + maxAge }
const contentType = mime.contentType(req.query.hash) || mime.contentType(asset.name)
if (contentType) headers['content-type'] = contentType
return res.sendFile(`${filePath}-${req.query.hash}`, { headers })
} else {
return res.sendFile(filePath, {
headers: {
'content-type': mime.contentType(asset.name),
'cache-control': 'public,max-age=0'
}
})
const headers = { 'cache-control': 'public,max-age=0' }
const contentType = mime.contentType(asset.name)
if (contentType) headers['content-type'] = contentType
return res.sendFile(filePath, { headers })
}
}

0 comments on commit 7d91155

Please sign in to comment.