diff --git a/src/index.coffee b/src/index.coffee index 7d61f3b..7954a65 100644 --- a/src/index.coffee +++ b/src/index.coffee @@ -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' diff --git a/src/util.coffee b/src/util.coffee index 7a7bab8..1e848bd 100644 --- a/src/util.coffee +++ b/src/util.coffee @@ -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 } \ No newline at end of file