various fixes to WebHost

This commit is contained in:
Fabian Dill 2021-04-10 15:26:30 +02:00
parent d4b422840a
commit ea15f221ae
5 changed files with 8 additions and 8 deletions

View File

@ -46,6 +46,7 @@ app.config["PONY"] = {
app.config["MAX_ROLL"] = 20 app.config["MAX_ROLL"] = 20
app.config["CACHE_TYPE"] = "simple" app.config["CACHE_TYPE"] = "simple"
app.config["JSON_AS_ASCII"] = False app.config["JSON_AS_ASCII"] = False
app.config["PATCH_TARGET"] = "archipelago.gg"
app.autoversion = True app.autoversion = True

View File

@ -81,9 +81,9 @@ class WebHostContext(Context):
def init_save(self, enabled: bool = True): def init_save(self, enabled: bool = True):
self.saving = enabled self.saving = enabled
if self.saving: if self.saving:
existing_savegame = restricted_loads(Room.get(id=self.room_id).multisave) savegame_data = Room.get(id=self.room_id).multisave
if existing_savegame: if savegame_data:
self.set_save(existing_savegame) self.set_save(restricted_loads(Room.get(id=self.room_id).multisave))
self._start_async_saving() self._start_async_saving()
threading.Thread(target=self.listen_to_db_commands, daemon=True).start() threading.Thread(target=self.listen_to_db_commands, daemon=True).start()

View File

@ -16,7 +16,7 @@ def download_patch(room_id, patch_id):
room = Room.get(id=room_id) room = Room.get(id=room_id)
last_port = room.last_port last_port = room.last_port
patch_data = update_patch_data(patch.data, server=f"{app.config['HOSTNAME']}:{last_port}") patch_data = update_patch_data(patch.data, server=f"{app.config['PATCH_TARGET']}:{last_port}")
patch_data = io.BytesIO(patch_data) patch_data = io.BytesIO(patch_data)
fname = f"P{patch.player_id}_{patch.player_name}_{app.jinja_env.filters['suuid'](room_id)}.apbp" fname = f"P{patch.player_id}_{patch.player_name}_{app.jinja_env.filters['suuid'](room_id)}.apbp"

View File

@ -9,7 +9,7 @@
{% macro list_patches_room(room) %} {% macro list_patches_room(room) %}
{% if room.seed.patches %} {% if room.seed.patches %}
<ul> <ul>
{% for patch in patches|list|sort(attribute="player") %} {% for patch in room.seed.patches|list|sort(attribute="player_id") %}
<li><a href="{{ url_for("download_patch", patch_id=patch.id, room_id=room.id) }}"> <li><a href="{{ url_for("download_patch", patch_id=patch.id, room_id=room.id) }}">
Patch for player {{ patch.player_id }} - {{ patch.player_name }}</a></li> Patch for player {{ patch.player_id }} - {{ patch.player_name }}</a></li>
{% endfor %} {% endfor %}

View File

@ -41,8 +41,8 @@ def uploads():
return "Uploaded data contained a rom file, which is likely to contain copyrighted material. Your file was deleted." return "Uploaded data contained a rom file, which is likely to contain copyrighted material. Your file was deleted."
elif file.filename.endswith(".apbp"): elif file.filename.endswith(".apbp"):
splitted = file.filename.split("/")[-1][3:].split("P", 1) splitted = file.filename.split("/")[-1][3:].split("P", 1)
player = int(splitted[1].split(".")[0].split("_")[0]) player_id, player_name = splitted[1].split(".")[0].split("_")
patches.add(Patch(data=zfile.open(file, "r").read(), player=player)) patches.add(Patch(data=zfile.open(file, "r").read(), player_name=player_name, player_id=player_id))
elif file.filename.endswith(".txt"): elif file.filename.endswith(".txt"):
spoiler = zfile.open(file, "r").read().decode("utf-8-sig") spoiler = zfile.open(file, "r").read().decode("utf-8-sig")
elif file.filename.endswith(".archipelago"): elif file.filename.endswith(".archipelago"):
@ -71,7 +71,6 @@ def uploads():
flash("Could not load multidata. File may be corrupted or incompatible.") flash("Could not load multidata. File may be corrupted or incompatible.")
raise raise
else: else:
logging.info(multidata)
seed = Seed(multidata=multidata, owner=session["_id"]) seed = Seed(multidata=multidata, owner=session["_id"])
commit() # place into DB and generate ids commit() # place into DB and generate ids
return redirect(url_for("viewSeed", seed=seed.id)) return redirect(url_for("viewSeed", seed=seed.id))