Foundation for in browser downloading

This adds /download as a URL to immediately download the file, this will allow html changes that initiate a file download.
This commit is contained in:
henk717 2021-09-01 15:58:56 +02:00 committed by GitHub
parent 55059bddcf
commit 9b3e298089
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 27 additions and 0 deletions

View File

@ -491,6 +491,33 @@ else:
@app.route('/index')
def index():
return render_template('index.html')
@app.route('/download')
def download():
# Leave Edit/Memory mode before continuing
exitModes()
# Build json to write
js = {}
js["gamestarted"] = vars.gamestarted
js["prompt"] = vars.prompt
js["memory"] = vars.memory
js["authorsnote"] = vars.authornote
js["actions"] = tuple(vars.actions.values())
js["worldinfo"] = []
# Extract only the important bits of WI
for wi in vars.worldinfo:
if(wi["constant"] or wi["key"] != ""):
js["worldinfo"].append({
"key": wi["key"],
"keysecondary": wi["keysecondary"],
"content": wi["content"],
"selective": wi["selective"],
"constant": wi["constant"]
})
save = flask.Response(json.dumps(js, indent=3))
save.headers.set('Content-Disposition', 'attachment', filename='%s.json' % path.basename(vars.savedir))
return(save)
#============================ METHODS =============================#