From 8b25e738e0c7eb1b81e003175d6b765afe819255 Mon Sep 17 00:00:00 2001 From: Zero Tang Date: Mon, 1 Mar 2021 08:37:23 +0800 Subject: [PATCH] Fix download errors. --- Python/filegenerator.py | 4 ++-- pserver.py | 19 ++++++++++++------- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/Python/filegenerator.py b/Python/filegenerator.py index da44edb..9be9d00 100644 --- a/Python/filegenerator.py +++ b/Python/filegenerator.py @@ -18,8 +18,8 @@ def __init__(self, make_log, make_summary, self.makeSummary = make_summary self.makeAnimation = make_animation # File Name to be used - self.logFileName = "logs\log-{0}.csv".format(str(sessionId)) - self.summaryFileName = "summaries\summary-{0}.csv".format(str(sessionId)) + self.logFileName = "logs\\log-{0}.csv".format(str(sessionId)) + self.summaryFileName = "summaries\\summary-{0}.csv".format(str(sessionId)) # names of the output files self.logName = log_name self.summaryName = summary_name diff --git a/pserver.py b/pserver.py index 8814124..6a16149 100644 --- a/pserver.py +++ b/pserver.py @@ -60,23 +60,28 @@ def runSimulation(input1): @app.route('/download/') # This is the endpoint that the javascript code will call to run simulation on server def download(fileName): - return send_file(fileName, as_attachment=True) + if fileName.startswith("log"): + return send_file("logs\\" + fileName, as_attachment=True) + elif fileName.startswith("summary"): + return send_file("summaries\\" + fileName, as_attachment=True) @app.route('/download2/') def download2(statement): - filename = "" - newname = "" + fileName = "" + newName = "" for i in range(0, len(statement)): # Search for delimiter. if(statement[i] == '&'): # Construct file names... - filename = statement[:i] - newname = statement[i+1:] + fileName = statement[:i] + newName = statement[i+1:] break # Things are over. - return send_file(filename, as_attachment=True, attachment_filename=newname) - + if fileName.startswith("log"): + return send_file("logs\\" + fileName, as_attachment=True, attachment_filename=newName) + elif fileName.startswith("summary"): + return send_file("summaries\\" + fileName, as_attachment=True, attachment_filename=newName) @app.route('/') def index():