From 88c5ebdd2fae2229e7c39da9f5fd9564055a0294 Mon Sep 17 00:00:00 2001 From: Fabian Dill Date: Tue, 31 Aug 2021 18:58:54 +0200 Subject: [PATCH] WebHost: add per-game yaml file downloads --- WebHostLib/downloads.py | 16 +++++++++++++--- WebHostLib/templates/templates.html | 21 +++++++++++++++++++++ 2 files changed, 34 insertions(+), 3 deletions(-) create mode 100644 WebHostLib/templates/templates.html diff --git a/WebHostLib/downloads.py b/WebHostLib/downloads.py index 2d944117..4ba358cc 100644 --- a/WebHostLib/downloads.py +++ b/WebHostLib/downloads.py @@ -1,8 +1,8 @@ -from flask import send_file, Response +from flask import send_file, Response, render_template from pony.orm import select from Patch import update_patch_data -from WebHostLib import app, Slot, Room, Seed +from WebHostLib import app, Slot, Room, Seed, cache import zipfile @app.route("/dl_patch//") @@ -68,4 +68,14 @@ def download_slot_file(room_id, player_id: int): fname = name.rsplit("/", 1)[0]+".zip" else: return "Game download not supported." - return send_file(io.BytesIO(slot_data.data), as_attachment=True, attachment_filename=fname) \ No newline at end of file + return send_file(io.BytesIO(slot_data.data), as_attachment=True, attachment_filename=fname) + +@app.route("/templates") +@cache.cached() +def list_yaml_templates(): + import os + files = [] + for file in os.scandir(os.path.join(app.static_folder, "generated")): + if file.is_file() and file.name.endswith(".yaml"): + files.append(file.name) + return render_template("templates.html", files=files) \ No newline at end of file diff --git a/WebHostLib/templates/templates.html b/WebHostLib/templates/templates.html new file mode 100644 index 00000000..0f5920df --- /dev/null +++ b/WebHostLib/templates/templates.html @@ -0,0 +1,21 @@ +{% extends 'pageWrapper.html' %} + +{% block head %} + {% include 'header/grassHeader.html' %} + Option Templates (YAML) + + +{% endblock %} + +{% block body %} +
+

Option Templates (YAML)

+
    + {% for file in files %} +
  • {{ file }}
  • + {% endfor %} +
+
+{% endblock %}