fix inline detection

This commit is contained in:
Peter Cai 2020-02-17 14:55:25 +08:00
parent 21bb3856b5
commit 768d10bb75
No known key found for this signature in database
GPG key ID: 71F5FB4E4F3FD54F
2 changed files with 14 additions and 5 deletions

View file

@ -94,10 +94,9 @@ handleGET = (req, file) ->
headers['content-type'] = 'text/plain'
# Add content-disposition header to indicate file name
if headers['content-type'].startsWith 'image/'
headers['content-disposition'] = 'inline; filename=' + fileName
else
headers['content-disposition'] = 'attachment; filename=' + fileName
inline = util.shouldShowInline headers['content-type']
headers['content-disposition'] =
(if inline then 'inline;' else 'attachment;') + ' filename=' + fileName
# Handle ranged resposes
if resp.headers.has 'content-range'

View file

@ -32,10 +32,20 @@ idToPath = (id) ->
id.split ''
.join '/'
# Determine if we show something inline or not
shouldShowInline = (mime) ->
mime.startsWith 'text/' or
mime.startsWith 'image/' or
mime.startsWith 'audio/' or
mime.startsWith 'video/' or
mime == 'application/json' or
mime == 'application/javascript'
export {
getFileName,
validateLength,
MAX_UPLOAD_SIZE,
randomID,
idToPath
idToPath,
shouldShowInline
}