black lint
This commit is contained in:
+11
-10
@@ -43,10 +43,13 @@ queue = Queue(connection=redis_conn)
|
|||||||
@app.errorhandler(413)
|
@app.errorhandler(413)
|
||||||
def too_large(_: Any) -> tuple[Response, int]:
|
def too_large(_: Any) -> tuple[Response, int]:
|
||||||
"""Error Handler for Max File Size."""
|
"""Error Handler for Max File Size."""
|
||||||
sentry_sdk.set_context("upload", {
|
sentry_sdk.set_context(
|
||||||
"content_length": request.content_length,
|
"upload",
|
||||||
"max_allowed": app.config["MAX_CONTENT_LENGTH"],
|
{
|
||||||
})
|
"content_length": request.content_length,
|
||||||
|
"max_allowed": app.config["MAX_CONTENT_LENGTH"],
|
||||||
|
},
|
||||||
|
)
|
||||||
sentry_sdk.capture_message("Upload failed: 413 Payload Too Large", level="warning")
|
sentry_sdk.capture_message("Upload failed: 413 Payload Too Large", level="warning")
|
||||||
return jsonify({"error": "Image size exceeded"}), 413
|
return jsonify({"error": "Image size exceeded"}), 413
|
||||||
|
|
||||||
@@ -56,8 +59,10 @@ def not_found(_: Any) -> str:
|
|||||||
"""Error Handler for 404 not found."""
|
"""Error Handler for 404 not found."""
|
||||||
return render_template("error.html", message="Resource not found", statuscode=404)
|
return render_template("error.html", message="Resource not found", statuscode=404)
|
||||||
|
|
||||||
|
|
||||||
# Sentry automatically captures 500 errors
|
# Sentry automatically captures 500 errors
|
||||||
|
|
||||||
|
|
||||||
@app.route("/")
|
@app.route("/")
|
||||||
def index() -> str:
|
def index() -> str:
|
||||||
"""Render the main index page."""
|
"""Render the main index page."""
|
||||||
@@ -127,9 +132,7 @@ def upload_image() -> tuple[Response, int]:
|
|||||||
submission_path = RESULT_FOLDER / img_hash / submission_hash
|
submission_path = RESULT_FOLDER / img_hash / submission_hash
|
||||||
|
|
||||||
# Check if hash is present on the DB
|
# Check if hash is present on the DB
|
||||||
submission: Submission = Submission.query.filter_by(
|
submission: Submission = Submission.query.filter_by(hash=submission_hash).first()
|
||||||
hash=submission_hash
|
|
||||||
).first()
|
|
||||||
|
|
||||||
# Only return if BOTH the file exists AND the DB entry exists
|
# Only return if BOTH the file exists AND the DB entry exists
|
||||||
if submission_path.exists() and submission is not None:
|
if submission_path.exists() and submission is not None:
|
||||||
@@ -145,9 +148,7 @@ def upload_image() -> tuple[Response, int]:
|
|||||||
f.write(image_data)
|
f.write(image_data)
|
||||||
|
|
||||||
# Try to find image in DB by hash
|
# Try to find image in DB by hash
|
||||||
sub_img = Image.query.filter_by(
|
sub_img = Image.query.filter_by(hash=img_hash).first()
|
||||||
hash=img_hash
|
|
||||||
).first()
|
|
||||||
|
|
||||||
# If DB entry is missing (even if file exists on disk), create it!
|
# If DB entry is missing (even if file exists on disk), create it!
|
||||||
if sub_img is None:
|
if sub_img is None:
|
||||||
|
|||||||
Reference in New Issue
Block a user