Fix inconsistency in accessing files between download and delete

This commit is contained in:
allegroai 2021-05-03 18:14:08 +03:00
parent 4fe61ee25c
commit 8c18660a82

View File

@ -6,6 +6,7 @@ from pathlib import Path
from boltons.iterutils import first from boltons.iterutils import first
from flask import Flask, request, send_from_directory, safe_join, abort, Response from flask import Flask, request, send_from_directory, safe_join, abort, Response
from flask._compat import fspath
from flask_compress import Compress from flask_compress import Compress
from flask_cors import CORS from flask_cors import CORS
@ -58,7 +59,12 @@ def download(path):
@app.route("/<path:path>", methods=["DELETE"]) @app.route("/<path:path>", methods=["DELETE"])
def delete(path): def delete(path):
path = Path(safe_join(app.config["UPLOAD_FOLDER"], path)) path = Path(
safe_join(
fspath(app.config["UPLOAD_FOLDER"]),
fspath(path)
)
)
if not path.exists() or path.is_file(): if not path.exists() or path.is_file():
abort(Response(f"File {str(path)} not found", 404)) abort(Response(f"File {str(path)} not found", 404))