Skip to content

Commit 1e176d9

Browse files
Berserker66FlySniper
authored andcommitted
WebHost: offer combined yaml file on /check if successful (ArchipelagoMW#2337)
1 parent da32ebe commit 1e176d9

File tree

16 files changed

+41
-27
lines changed

16 files changed

+41
-27
lines changed

WebHostLib/check.py

+23-13
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import zipfile
2-
from typing import *
2+
import base64
3+
from typing import Union, Dict, Set, Tuple
34

45
from flask import request, flash, redirect, url_for, render_template
56
from markupsafe import Markup
@@ -30,7 +31,15 @@ def check():
3031
flash(options)
3132
else:
3233
results, _ = roll_options(options)
33-
return render_template("checkResult.html", results=results)
34+
if len(options) > 1:
35+
# offer combined file back
36+
combined_yaml = "---\n".join(f"# original filename: {file_name}\n{file_content.decode('utf-8-sig')}"
37+
for file_name, file_content in options.items())
38+
combined_yaml = base64.b64encode(combined_yaml.encode("utf-8-sig")).decode()
39+
else:
40+
combined_yaml = ""
41+
return render_template("checkResult.html",
42+
results=results, combined_yaml=combined_yaml)
3443
return render_template("check.html")
3544

3645

@@ -41,31 +50,32 @@ def mysterycheck():
4150

4251
def get_yaml_data(files) -> Union[Dict[str, str], str, Markup]:
4352
options = {}
44-
for file in files:
53+
for uploaded_file in files:
4554
# if user does not select file, browser also
4655
# submit an empty part without filename
47-
if file.filename == '':
56+
if uploaded_file.filename == '':
4857
return 'No selected file'
49-
elif file.filename in options:
50-
return f'Conflicting files named {file.filename} submitted'
51-
elif file and allowed_file(file.filename):
52-
if file.filename.endswith(".zip"):
58+
elif uploaded_file.filename in options:
59+
return f'Conflicting files named {uploaded_file.filename} submitted'
60+
elif uploaded_file and allowed_file(uploaded_file.filename):
61+
if uploaded_file.filename.endswith(".zip"):
5362

54-
with zipfile.ZipFile(file, 'r') as zfile:
63+
with zipfile.ZipFile(uploaded_file, 'r') as zfile:
5564
infolist = zfile.infolist()
5665

5766
if any(file.filename.endswith(".archipelago") for file in infolist):
5867
return Markup("Error: Your .zip file contains an .archipelago file. "
59-
'Did you mean to <a href="/uploads">host a game</a>?')
68+
'Did you mean to <a href="/uploads">host a game</a>?')
6069

6170
for file in infolist:
6271
if file.filename.endswith(banned_zip_contents):
63-
return "Uploaded data contained a rom file, which is likely to contain copyrighted material. " \
64-
"Your file was deleted."
72+
return ("Uploaded data contained a rom file, "
73+
"which is likely to contain copyrighted material. "
74+
"Your file was deleted.")
6575
elif file.filename.endswith((".yaml", ".json", ".yml", ".txt")):
6676
options[file.filename] = zfile.open(file, "r").read()
6777
else:
68-
options[file.filename] = file.read()
78+
options[uploaded_file.filename] = uploaded_file.read()
6979
if not options:
7080
return "Did not find a .yaml file to process."
7181
return options

WebHostLib/templates/checkResult.html

+4
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ <h1>Verification Results</h1>
2828
{% endfor %}
2929
</tbody>
3030
</table>
31+
{% if combined_yaml %}
32+
<h1>Combined File Download</h1>
33+
<p><a href="data:text/yaml;base64,{{ combined_yaml }}" download="combined.yaml">Download</a></p>
34+
{% endif %}
3135
</div>
3236
</div>
3337
{% endblock %}

worlds/alttp/docs/multiworld_de.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ Wenn du eine Option nicht gewählt haben möchtest, setze ihren Wert einfach auf
6767

6868
### Überprüfung deiner YAML-Datei
6969

70-
Wenn man sichergehen will, ob die YAML-Datei funktioniert, kann man dies bei der [YAML Validator](/mysterycheck) Seite
70+
Wenn man sichergehen will, ob die YAML-Datei funktioniert, kann man dies bei der [YAML Validator](/check) Seite
7171
tun.
7272

7373
## ein Einzelspielerspiel erstellen

worlds/alttp/docs/multiworld_es.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ debe tener al menos un valor mayor que cero, si no la generación fallará.
8282
### Verificando tu archivo YAML
8383

8484
Si quieres validar que tu fichero YAML para asegurarte que funciona correctamente, puedes hacerlo en la pagina
85-
[YAML Validator](/mysterycheck).
85+
[YAML Validator](/check).
8686

8787
## Generar una partida para un jugador
8888

worlds/alttp/docs/multiworld_fr.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ chaque paramètre il faut au moins une option qui soit paramétrée sur un nombr
8383
### Vérifier son fichier YAML
8484

8585
Si vous voulez valider votre fichier YAML pour être sûr qu'il fonctionne, vous pouvez le vérifier sur la page du
86-
[Validateur de YAML](/mysterycheck).
86+
[Validateur de YAML](/check).
8787

8888
## Générer une partie pour un joueur
8989

worlds/dkc3/docs/setup_en.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ them. Player settings page: [Donkey Kong Country 3 Player Settings Page](/games/
5050
### Verifying your config file
5151

5252
If you would like to validate your config file to make sure it works, you may do so on the YAML Validator page. YAML
53-
validator page: [YAML Validation page](/mysterycheck)
53+
validator page: [YAML Validation page](/check)
5454

5555
## Generating a Single-Player Game
5656

worlds/factorio/docs/setup_en.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ them. Factorio player settings page: [Factorio Settings Page](/games/Factorio/pl
3131
### Verifying your config file
3232

3333
If you would like to validate your config file to make sure it works, you may do so on the YAML Validator page. YAML
34-
Validator page: [Yaml Validation Page](/mysterycheck)
34+
Validator page: [Yaml Validation Page](/check)
3535

3636
## Connecting to Someone Else's Factorio Game
3737

worlds/generic/docs/setup_en.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ game you will be playing as well as the settings you would like for that game.
4040

4141
YAML is a format very similar to JSON however it is made to be more human-readable. If you are ever unsure of the
4242
validity of your YAML file you may check the file by uploading it to the check page on the Archipelago website:
43-
[YAML Validation Page](/mysterycheck)
43+
[YAML Validation Page](/check)
4444

4545
### Creating a YAML
4646

worlds/ladx/docs/setup_en.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ your personal settings and export a config file from them.
4040
### Verifying your config file
4141

4242
If you would like to validate your config file to make sure it works, you may do so on the
43-
[YAML Validator](/mysterycheck) page.
43+
[YAML Validator](/check) page.
4444

4545
## Generating a Single-Player Game
4646

worlds/lufia2ac/docs/setup_en.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ your personal settings and export a config file from them.
4444
### Verifying your config file
4545

4646
If you would like to validate your config file to make sure it works, you may do so on the
47-
[YAML Validator](/mysterycheck) page.
47+
[YAML Validator](/check) page.
4848

4949
## Generating a Single-Player Game
5050

worlds/sm/docs/multiworld_en.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ them. Player settings page: [Super Metroid Player Settings Page](/games/Super%20
4949
### Verifying your config file
5050

5151
If you would like to validate your config file to make sure it works, you may do so on the YAML Validator page. YAML
52-
validator page: [YAML Validation page](/mysterycheck)
52+
validator page: [YAML Validation page](/check)
5353

5454
## Generating a Single-Player Game
5555

worlds/smw/docs/setup_en.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ them. Player settings page: [Super Mario World Player Settings Page](/games/Supe
5050
### Verifying your config file
5151

5252
If you would like to validate your config file to make sure it works, you may do so on the YAML Validator page. YAML
53-
validator page: [YAML Validation page](/mysterycheck)
53+
validator page: [YAML Validation page](/check)
5454

5555
## Joining a MultiWorld Game
5656

worlds/smz3/docs/multiworld_en.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ them. Player settings page: [SMZ3 Player Settings Page](/games/SMZ3/player-setti
4747
### Verifying your config file
4848

4949
If you would like to validate your config file to make sure it works, you may do so on the YAML Validator page. YAML
50-
validator page: [YAML Validation page](/mysterycheck)
50+
validator page: [YAML Validation page](/check)
5151

5252
## Generating a Single-Player Game
5353

worlds/soe/docs/multiworld_en.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ them. Player settings page: [Secret of Evermore Player Settings PAge](/games/Sec
2929
### Verifying your config file
3030

3131
If you would like to validate your config file to make sure it works, you may do so on the YAML Validator
32-
page: [YAML Validation page](/mysterycheck)
32+
page: [YAML Validation page](/check)
3333

3434
## Generating a Single-Player Game
3535

worlds/tloz/docs/multiworld_en.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ them. Player settings page: [The Legend of Zelda Player Settings Page](/games/Th
4444
### Verifying your config file
4545

4646
If you would like to validate your config file to make sure it works, you may do so on the YAML Validator page. YAML
47-
validator page: [YAML Validation page](/mysterycheck)
47+
validator page: [YAML Validation page](/check)
4848

4949
## Generating a Single-Player Game
5050

worlds/zillion/docs/setup_en.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ them.
5151

5252
### Verifying your config file
5353

54-
If you would like to validate your config file to make sure it works, you may do so on the [YAML Validator page](/mysterycheck).
54+
If you would like to validate your config file to make sure it works, you may do so on the [YAML Validator page](/check).
5555

5656
## Generating a Single-Player Game
5757

0 commit comments

Comments
 (0)