summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJon Bergli Heier <snakebite@jvnv.net>2021-09-28 17:23:49 +0200
committerJon Bergli Heier <snakebite@jvnv.net>2021-09-28 17:23:49 +0200
commit466ebbf11f958279f20bca9aacd2a2deeaaab2bf (patch)
treea469bacc22fd2e33fbaaf9d1a95972c2ada73c33
parente09d2d258e992a08df0f96efbf296ad05f798e9b (diff)
Make MIMETYPE_BLACKLIST work with the S3 module
-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)