Skip to content

Commit

Permalink
Combine export_selected and export_all
Browse files Browse the repository at this point in the history
  • Loading branch information
argilo committed Jan 28, 2024
1 parent 8583dff commit c7971b8
Showing 1 changed file with 3 additions and 33 deletions.
36 changes: 3 additions & 33 deletions auto_rx/autorx/web.py
Original file line number Diff line number Diff line change
Expand Up @@ -335,15 +335,16 @@ def flask_get_log_by_serial_detail():
return json.dumps(read_log_by_serial(_serial, skewt_decimation=_decim))


@app.route("/export_all_log_files")
@app.route("/export_log_files/<serialb64>")
def flask_export_selected_log_files(serialb64):
def flask_export_log_files(serialb64=None):
"""
Zip and download a set of log files.
The list of log files is provided in the URL as a base64-encoded JSON list.
"""

try:
_serial_list = json.loads(base64.b64decode(serialb64))
_serial_list = json.loads(base64.b64decode(serialb64)) if serialb64 else None

_zip = zip_log_files(_serial_list)

Expand All @@ -368,37 +369,6 @@ def flask_export_selected_log_files(serialb64):
logging.error("Web - Error handling Zip request:" + str(e))
abort(400)


@app.route("/export_all_log_files")
def flask_export_all_log_files():
"""
Zip and download all log files. This may take some time.
"""

try:
_zip = zip_log_files()

_ts = datetime.datetime.strftime(datetime.datetime.utcnow(), "%Y%m%d-%H%M%SZ")

response = make_response(
flask.send_file(
_zip,
mimetype="application/zip",
as_attachment=True,
download_name=f"autorx_logfiles_{autorx.config.global_config['habitat_uploader_callsign']}_{_ts}.zip",
)
)

# Add header asking client not to cache the download
response.headers["Cache-Control"] = "no-cache, no-store, must-revalidate"
response.headers["Pragma"] = "no-cache"

return response

except Exception as e:
logging.error("Web - Error handling Zip request:" + str(e))
abort(400)

#
# Control Endpoints.
#
Expand Down

0 comments on commit c7971b8

Please sign in to comment.