Add output cleanup policy

This commit is contained in:
Alfredo Di Stasio
2026-04-27 14:17:44 +02:00
parent 93cebeb002
commit b8069d6771
9 changed files with 227 additions and 4 deletions

View File

@@ -12,12 +12,13 @@ from flask import (
url_for,
)
from werkzeug.datastructures import FileStorage
from werkzeug.wsgi import ClosingIterator
from app.constants import MODES, OUTPUT_FORMATS, SORTABLE_FIELDS, SORT_ORDERS
from app.services.conversion import convert_uploaded_log
from app.services.parser import LogParseError
from app.services.processing import ProcessingError, ProcessingOptions
from app.services.storage import load_result_metadata
from app.services.storage import delete_result_files, load_result_metadata
main_blueprint = Blueprint("main", __name__)
@@ -139,10 +140,17 @@ def download(result_id: str):
flash("Requested output file could not be found.", "danger")
return redirect(url_for("main.index"))
return send_file(
response = send_file(
Path(metadata["file_path"]),
as_attachment=True,
download_name=metadata["download_name"],
mimetype=metadata["mimetype"],
max_age=0,
)
if current_app.config.get("CLEANUP_AFTER_DOWNLOAD", False):
output_dir = current_app.config["OUTPUT_DIRECTORY"]
response.response = ClosingIterator(
response.response,
[lambda: delete_result_files(output_dir=output_dir, result_id=result_id)],
)
return response