Skip to content

WebHost: offer combined yaml file on /check if successful #2337

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 23 additions & 13 deletions WebHostLib/check.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -30,7 +31,15 @@ def check():
flash(options)
else:
results, _ = roll_options(options)
return render_template("checkResult.html", results=results)
if len(options) > 1:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't this be len(files) to not offer download for a single yaml file with --- already in it?

Copy link
Member Author

@Berserker66 Berserker66 Oct 21, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried uploading a combined yaml and it doesn't offer a download. options is file -> file content and is not yet yaml parsed.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh, i see. options is actually individual files, not individual options. somehow i didn't expect that

# 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")


Expand All @@ -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 <a href="/uploads">host a game</a>?')
'Did you mean to <a href="/uploads">host a game</a>?')

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
Expand Down
4 changes: 4 additions & 0 deletions WebHostLib/templates/checkResult.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ <h1>Verification Results</h1>
{% endfor %}
</tbody>
</table>
{% if combined_yaml %}
<h1>Combined File Download</h1>
<p><a href="data:text/yaml;base64,{{ combined_yaml }}" download="combined.yaml">Download</a></p>
{% endif %}
</div>
</div>
{% endblock %}
2 changes: 1 addition & 1 deletion worlds/alttp/docs/multiworld_de.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion worlds/alttp/docs/multiworld_es.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion worlds/alttp/docs/multiworld_fr.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion worlds/dkc3/docs/setup_en.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion worlds/factorio/docs/setup_en.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion worlds/generic/docs/setup_en.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion worlds/ladx/docs/setup_en.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion worlds/lufia2ac/docs/setup_en.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion worlds/sm/docs/multiworld_en.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion worlds/smw/docs/setup_en.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion worlds/smz3/docs/multiworld_en.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion worlds/soe/docs/multiworld_en.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion worlds/tloz/docs/multiworld_en.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion worlds/zillion/docs/setup_en.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down