forked from forks/microblog.pub
404 on bad media
This commit is contained in:
parent
f01015c73b
commit
b42f82acde
1 changed files with 12 additions and 2 deletions
10
app.py
10
app.py
|
@ -5,6 +5,7 @@ import traceback
|
|||
from datetime import datetime
|
||||
from uuid import uuid4
|
||||
|
||||
from bson.errors import InvalidId
|
||||
from bson.objectid import ObjectId
|
||||
from flask import Flask
|
||||
from flask import Response
|
||||
|
@ -16,6 +17,7 @@ from flask import render_template
|
|||
from flask import request
|
||||
from flask import session
|
||||
from flask import url_for
|
||||
from gridfs.errors import NoFile
|
||||
from itsdangerous import BadSignature
|
||||
from little_boxes import activitypub as ap
|
||||
from little_boxes.activitypub import ActivityType
|
||||
|
@ -219,7 +221,11 @@ def robots_txt():
|
|||
@app.route("/media/<media_id>")
|
||||
@noindex
|
||||
def serve_media(media_id):
|
||||
try:
|
||||
f = MEDIA_CACHE.fs.get(ObjectId(media_id))
|
||||
except (InvalidId, NoFile):
|
||||
abort(404)
|
||||
|
||||
resp = app.response_class(f, direct_passthrough=True, mimetype=f.content_type)
|
||||
resp.headers.set("Content-Length", f.length)
|
||||
resp.headers.set("ETag", f.md5)
|
||||
|
@ -233,7 +239,11 @@ def serve_media(media_id):
|
|||
|
||||
@app.route("/uploads/<oid>/<fname>")
|
||||
def serve_uploads(oid, fname):
|
||||
try:
|
||||
f = MEDIA_CACHE.fs.get(ObjectId(oid))
|
||||
except (InvalidId, NoFile):
|
||||
abort(404)
|
||||
|
||||
resp = app.response_class(f, direct_passthrough=True, mimetype=f.content_type)
|
||||
resp.headers.set("Content-Length", f.length)
|
||||
resp.headers.set("ETag", f.md5)
|
||||
|
|
Loading…
Reference in a new issue