summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xfbin/fbin.py25
1 files changed, 17 insertions, 8 deletions
diff --git a/fbin/fbin.py b/fbin/fbin.py
index 04811c0..148c0dd 100755
--- a/fbin/fbin.py
+++ b/fbin/fbin.py
@@ -160,6 +160,21 @@ def uploaded(hash):
return render_template('uploaded.html', **context)
+def _get_mimetype(f, path):
+ if isinstance(path, Response):
+ mimetype = path.content_type
+ else:
+ mimetype = f.get_mime_type()
+ # Serve blacklisted mimetypes as either text/plain or application/octet-stream
+ if mimetype in current_app.config['MIMETYPE_BLACKLIST'] and (f.user is None
+ or f.user.username not in current_app.config['MIMETYPE_USER_WHITELIST']):
+ if mimetype.startswith('text/'):
+ mimetype = 'text/plain'
+ else:
+ mimetype = 'application/octet-stream'
+ return mimetype
+
+
@app.route('/f/<hash:hash>')
@app.route('/f/<hash:hash><ext:ext>')
@app.route('/f/<hash:hash>/<path:filename>')
@@ -173,18 +188,12 @@ def _file(hash, ext=None, filename=None):
for scan in f.blocked_reason['scans'].values()))):
abort(404)
path = storage.get_file(f)
+ mimetype = _get_mimetype(f, path)
if isinstance(path, Response):
+ path.content_type = mimetype
return path
if not path or not os.path.exists(path):
abort(404)
- mimetype = f.get_mime_type()
- # Serve blacklisted mimetypes as either text/plain or application/octet-stream
- if mimetype in current_app.config['MIMETYPE_BLACKLIST'] and (f.user is None
- or f.user.username not in current_app.config['MIMETYPE_USER_WHITELIST']):
- if mimetype.startswith('text/'):
- mimetype = 'text/plain'
- else:
- mimetype = 'application/octet-stream'
return send_file(path, mimetype=mimetype, attachment_filename=f.filename)