From ee31051c43dc194df76ec89ba0578ac84e790d8c Mon Sep 17 00:00:00 2001 From: Fabian Dill Date: Sun, 22 Oct 2023 02:02:30 +0200 Subject: [PATCH] WebHost: offer combined yaml file on /check if successful (#2337) --- WebHostLib/check.py | 36 +++++++++++++++++---------- WebHostLib/templates/checkResult.html | 4 +++ worlds/alttp/docs/multiworld_de.md | 2 +- worlds/alttp/docs/multiworld_es.md | 2 +- worlds/alttp/docs/multiworld_fr.md | 2 +- worlds/dkc3/docs/setup_en.md | 2 +- worlds/factorio/docs/setup_en.md | 2 +- worlds/generic/docs/setup_en.md | 2 +- worlds/ladx/docs/setup_en.md | 2 +- worlds/lufia2ac/docs/setup_en.md | 2 +- worlds/sm/docs/multiworld_en.md | 2 +- worlds/smw/docs/setup_en.md | 2 +- worlds/smz3/docs/multiworld_en.md | 2 +- worlds/soe/docs/multiworld_en.md | 2 +- worlds/tloz/docs/multiworld_en.md | 2 +- worlds/zillion/docs/setup_en.md | 2 +- 16 files changed, 41 insertions(+), 27 deletions(-) diff --git a/WebHostLib/check.py b/WebHostLib/check.py index c5dfd9f5..4db2ec2c 100644 --- a/WebHostLib/check.py +++ b/WebHostLib/check.py @@ -1,5 +1,6 @@ import zipfile -from typing import * +import base64 +from typing import Union, Dict, Set, Tuple from flask import request, flash, redirect, url_for, render_template from markupsafe import Markup @@ -30,7 +31,15 @@ def check(): flash(options) else: results, _ = roll_options(options) - return render_template("checkResult.html", results=results) + if len(options) > 1: + # offer combined file back + combined_yaml = "---\n".join(f"# original filename: {file_name}\n{file_content.decode('utf-8-sig')}" + for file_name, file_content in options.items()) + combined_yaml = base64.b64encode(combined_yaml.encode("utf-8-sig")).decode() + else: + combined_yaml = "" + return render_template("checkResult.html", + results=results, combined_yaml=combined_yaml) return render_template("check.html") @@ -41,31 +50,32 @@ def mysterycheck(): def get_yaml_data(files) -> Union[Dict[str, str], str, Markup]: options = {} - for file in files: + for uploaded_file in files: # if user does not select file, browser also # submit an empty part without filename - if file.filename == '': + if uploaded_file.filename == '': return 'No selected file' - elif file.filename in options: - return f'Conflicting files named {file.filename} submitted' - elif file and allowed_file(file.filename): - if file.filename.endswith(".zip"): + elif uploaded_file.filename in options: + return f'Conflicting files named {uploaded_file.filename} submitted' + elif uploaded_file and allowed_file(uploaded_file.filename): + if uploaded_file.filename.endswith(".zip"): - with zipfile.ZipFile(file, 'r') as zfile: + with zipfile.ZipFile(uploaded_file, 'r') as zfile: infolist = zfile.infolist() if any(file.filename.endswith(".archipelago") for file in infolist): return Markup("Error: Your .zip file contains an .archipelago file. " - 'Did you mean to host a game?') + 'Did you mean to host a game?') for file in infolist: if file.filename.endswith(banned_zip_contents): - 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((".yaml", ".json", ".yml", ".txt")): options[file.filename] = zfile.open(file, "r").read() else: - options[file.filename] = file.read() + options[uploaded_file.filename] = uploaded_file.read() if not options: return "Did not find a .yaml file to process." return options diff --git a/WebHostLib/templates/checkResult.html b/WebHostLib/templates/checkResult.html index c245d738..75ae7479 100644 --- a/WebHostLib/templates/checkResult.html +++ b/WebHostLib/templates/checkResult.html @@ -28,6 +28,10 @@ {% endfor %} + {% if combined_yaml %} +

Combined File Download

+

Download

+ {% endif %} {% endblock %} diff --git a/worlds/alttp/docs/multiworld_de.md b/worlds/alttp/docs/multiworld_de.md index 38009fb5..8ccd1a87 100644 --- a/worlds/alttp/docs/multiworld_de.md +++ b/worlds/alttp/docs/multiworld_de.md @@ -67,7 +67,7 @@ Wenn du eine Option nicht gewählt haben möchtest, setze ihren Wert einfach auf ### Überprüfung deiner YAML-Datei -Wenn man sichergehen will, ob die YAML-Datei funktioniert, kann man dies bei der [YAML Validator](/mysterycheck) Seite +Wenn man sichergehen will, ob die YAML-Datei funktioniert, kann man dies bei der [YAML Validator](/check) Seite tun. ## ein Einzelspielerspiel erstellen diff --git a/worlds/alttp/docs/multiworld_es.md b/worlds/alttp/docs/multiworld_es.md index 8576318b..37aeda2a 100644 --- a/worlds/alttp/docs/multiworld_es.md +++ b/worlds/alttp/docs/multiworld_es.md @@ -82,7 +82,7 @@ debe tener al menos un valor mayor que cero, si no la generación fallará. ### Verificando tu archivo YAML Si quieres validar que tu fichero YAML para asegurarte que funciona correctamente, puedes hacerlo en la pagina -[YAML Validator](/mysterycheck). +[YAML Validator](/check). ## Generar una partida para un jugador diff --git a/worlds/alttp/docs/multiworld_fr.md b/worlds/alttp/docs/multiworld_fr.md index 329ca653..078a270f 100644 --- a/worlds/alttp/docs/multiworld_fr.md +++ b/worlds/alttp/docs/multiworld_fr.md @@ -83,7 +83,7 @@ chaque paramètre il faut au moins une option qui soit paramétrée sur un nombr ### Vérifier son fichier YAML Si vous voulez valider votre fichier YAML pour être sûr qu'il fonctionne, vous pouvez le vérifier sur la page du -[Validateur de YAML](/mysterycheck). +[Validateur de YAML](/check). ## Générer une partie pour un joueur diff --git a/worlds/dkc3/docs/setup_en.md b/worlds/dkc3/docs/setup_en.md index bb107563..9c419728 100644 --- a/worlds/dkc3/docs/setup_en.md +++ b/worlds/dkc3/docs/setup_en.md @@ -50,7 +50,7 @@ them. Player settings page: [Donkey Kong Country 3 Player Settings Page](/games/ ### Verifying your config file If you would like to validate your config file to make sure it works, you may do so on the YAML Validator page. YAML -validator page: [YAML Validation page](/mysterycheck) +validator page: [YAML Validation page](/check) ## Generating a Single-Player Game diff --git a/worlds/factorio/docs/setup_en.md b/worlds/factorio/docs/setup_en.md index 09ad431a..b6d45459 100644 --- a/worlds/factorio/docs/setup_en.md +++ b/worlds/factorio/docs/setup_en.md @@ -31,7 +31,7 @@ them. Factorio player settings page: [Factorio Settings Page](/games/Factorio/pl ### Verifying your config file If you would like to validate your config file to make sure it works, you may do so on the YAML Validator page. YAML -Validator page: [Yaml Validation Page](/mysterycheck) +Validator page: [Yaml Validation Page](/check) ## Connecting to Someone Else's Factorio Game diff --git a/worlds/generic/docs/setup_en.md b/worlds/generic/docs/setup_en.md index 132b88e2..93ae217e 100644 --- a/worlds/generic/docs/setup_en.md +++ b/worlds/generic/docs/setup_en.md @@ -40,7 +40,7 @@ game you will be playing as well as the settings you would like for that game. YAML is a format very similar to JSON however it is made to be more human-readable. If you are ever unsure of the validity of your YAML file you may check the file by uploading it to the check page on the Archipelago website: -[YAML Validation Page](/mysterycheck) +[YAML Validation Page](/check) ### Creating a YAML diff --git a/worlds/ladx/docs/setup_en.md b/worlds/ladx/docs/setup_en.md index 538d70d4..e21c5bdd 100644 --- a/worlds/ladx/docs/setup_en.md +++ b/worlds/ladx/docs/setup_en.md @@ -40,7 +40,7 @@ your personal settings and export a config file from them. ### Verifying your config file If you would like to validate your config file to make sure it works, you may do so on the -[YAML Validator](/mysterycheck) page. +[YAML Validator](/check) page. ## Generating a Single-Player Game diff --git a/worlds/lufia2ac/docs/setup_en.md b/worlds/lufia2ac/docs/setup_en.md index 4236c26e..3762f32f 100644 --- a/worlds/lufia2ac/docs/setup_en.md +++ b/worlds/lufia2ac/docs/setup_en.md @@ -44,7 +44,7 @@ your personal settings and export a config file from them. ### Verifying your config file If you would like to validate your config file to make sure it works, you may do so on the -[YAML Validator](/mysterycheck) page. +[YAML Validator](/check) page. ## Generating a Single-Player Game diff --git a/worlds/sm/docs/multiworld_en.md b/worlds/sm/docs/multiworld_en.md index ce91e7a7..12915077 100644 --- a/worlds/sm/docs/multiworld_en.md +++ b/worlds/sm/docs/multiworld_en.md @@ -49,7 +49,7 @@ them. Player settings page: [Super Metroid Player Settings Page](/games/Super%20 ### Verifying your config file If you would like to validate your config file to make sure it works, you may do so on the YAML Validator page. YAML -validator page: [YAML Validation page](/mysterycheck) +validator page: [YAML Validation page](/check) ## Generating a Single-Player Game diff --git a/worlds/smw/docs/setup_en.md b/worlds/smw/docs/setup_en.md index 9ca8bdf5..3967f544 100644 --- a/worlds/smw/docs/setup_en.md +++ b/worlds/smw/docs/setup_en.md @@ -50,7 +50,7 @@ them. Player settings page: [Super Mario World Player Settings Page](/games/Supe ### Verifying your config file If you would like to validate your config file to make sure it works, you may do so on the YAML Validator page. YAML -validator page: [YAML Validation page](/mysterycheck) +validator page: [YAML Validation page](/check) ## Joining a MultiWorld Game diff --git a/worlds/smz3/docs/multiworld_en.md b/worlds/smz3/docs/multiworld_en.md index da6e29ab..53842a3c 100644 --- a/worlds/smz3/docs/multiworld_en.md +++ b/worlds/smz3/docs/multiworld_en.md @@ -47,7 +47,7 @@ them. Player settings page: [SMZ3 Player Settings Page](/games/SMZ3/player-setti ### Verifying your config file If you would like to validate your config file to make sure it works, you may do so on the YAML Validator page. YAML -validator page: [YAML Validation page](/mysterycheck) +validator page: [YAML Validation page](/check) ## Generating a Single-Player Game diff --git a/worlds/soe/docs/multiworld_en.md b/worlds/soe/docs/multiworld_en.md index d995cea5..58b9aabf 100644 --- a/worlds/soe/docs/multiworld_en.md +++ b/worlds/soe/docs/multiworld_en.md @@ -29,7 +29,7 @@ them. Player settings page: [Secret of Evermore Player Settings PAge](/games/Sec ### Verifying your config file If you would like to validate your config file to make sure it works, you may do so on the YAML Validator -page: [YAML Validation page](/mysterycheck) +page: [YAML Validation page](/check) ## Generating a Single-Player Game diff --git a/worlds/tloz/docs/multiworld_en.md b/worlds/tloz/docs/multiworld_en.md index 581e8cf7..ae53d953 100644 --- a/worlds/tloz/docs/multiworld_en.md +++ b/worlds/tloz/docs/multiworld_en.md @@ -44,7 +44,7 @@ them. Player settings page: [The Legend of Zelda Player Settings Page](/games/Th ### Verifying your config file If you would like to validate your config file to make sure it works, you may do so on the YAML Validator page. YAML -validator page: [YAML Validation page](/mysterycheck) +validator page: [YAML Validation page](/check) ## Generating a Single-Player Game diff --git a/worlds/zillion/docs/setup_en.md b/worlds/zillion/docs/setup_en.md index 16000dbe..22dee5ee 100644 --- a/worlds/zillion/docs/setup_en.md +++ b/worlds/zillion/docs/setup_en.md @@ -51,7 +51,7 @@ them. ### Verifying your config file -If you would like to validate your config file to make sure it works, you may do so on the [YAML Validator page](/mysterycheck). +If you would like to validate your config file to make sure it works, you may do so on the [YAML Validator page](/check). ## Generating a Single-Player Game