WebHost: Support multi-select during check/generate file upload (#2138)
* Support multi-select during check/generate file upload This will allow the user to select multiple YAML files via Shift-Click or Control-Click in their browser when generating a game via the site instead of having to zip them locally first. * Update generate.html: File -> File(s) * Change check.html button text to "Upload File(s)" to match generate.html
This commit is contained in:
parent
3d9837678c
commit
57c13ff273
|
@ -24,8 +24,8 @@ def check():
|
||||||
if 'file' not in request.files:
|
if 'file' not in request.files:
|
||||||
flash('No file part')
|
flash('No file part')
|
||||||
else:
|
else:
|
||||||
file = request.files['file']
|
files = request.files.getlist('file')
|
||||||
options = get_yaml_data(file)
|
options = get_yaml_data(files)
|
||||||
if isinstance(options, str):
|
if isinstance(options, str):
|
||||||
flash(options)
|
flash(options)
|
||||||
else:
|
else:
|
||||||
|
@ -39,12 +39,15 @@ def mysterycheck():
|
||||||
return redirect(url_for("check"), 301)
|
return redirect(url_for("check"), 301)
|
||||||
|
|
||||||
|
|
||||||
def get_yaml_data(file) -> Union[Dict[str, str], str, Markup]:
|
def get_yaml_data(files) -> Union[Dict[str, str], str, Markup]:
|
||||||
options = {}
|
options = {}
|
||||||
|
for file in files:
|
||||||
# if user does not select file, browser also
|
# if user does not select file, browser also
|
||||||
# submit an empty part without filename
|
# submit an empty part without filename
|
||||||
if file.filename == '':
|
if file.filename == '':
|
||||||
return 'No selected file'
|
return 'No selected file'
|
||||||
|
elif file.filename in options:
|
||||||
|
return f'Conflicting files named {file.filename} submitted'
|
||||||
elif file and allowed_file(file.filename):
|
elif file and allowed_file(file.filename):
|
||||||
if file.filename.endswith(".zip"):
|
if file.filename.endswith(".zip"):
|
||||||
|
|
||||||
|
@ -62,7 +65,7 @@ def get_yaml_data(file) -> Union[Dict[str, str], str, Markup]:
|
||||||
elif file.filename.endswith((".yaml", ".json", ".yml", ".txt")):
|
elif file.filename.endswith((".yaml", ".json", ".yml", ".txt")):
|
||||||
options[file.filename] = zfile.open(file, "r").read()
|
options[file.filename] = zfile.open(file, "r").read()
|
||||||
else:
|
else:
|
||||||
options = {file.filename: file.read()}
|
options[file.filename] = file.read()
|
||||||
if not options:
|
if not options:
|
||||||
return "Did not find a .yaml file to process."
|
return "Did not find a .yaml file to process."
|
||||||
return options
|
return options
|
||||||
|
|
|
@ -64,8 +64,8 @@ def generate(race=False):
|
||||||
if 'file' not in request.files:
|
if 'file' not in request.files:
|
||||||
flash('No file part')
|
flash('No file part')
|
||||||
else:
|
else:
|
||||||
file = request.files['file']
|
files = request.files.getlist('file')
|
||||||
options = get_yaml_data(file)
|
options = get_yaml_data(files)
|
||||||
if isinstance(options, str):
|
if isinstance(options, str):
|
||||||
flash(options)
|
flash(options)
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -17,9 +17,9 @@
|
||||||
</p>
|
</p>
|
||||||
<div id="check-form-wrapper">
|
<div id="check-form-wrapper">
|
||||||
<form id="check-form" method="post" enctype="multipart/form-data">
|
<form id="check-form" method="post" enctype="multipart/form-data">
|
||||||
<input id="file-input" type="file" name="file">
|
<input id="file-input" type="file" name="file" multiple>
|
||||||
</form>
|
</form>
|
||||||
<button id="check-button">Upload</button>
|
<button id="check-button">Upload File(s)</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -203,10 +203,10 @@ Warning: playthrough can take a significant amount of time for larger multiworld
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div id="generate-form-button-row">
|
<div id="generate-form-button-row">
|
||||||
<input id="file-input" type="file" name="file">
|
<input id="file-input" type="file" name="file" multiple>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
<button id="generate-game-button">Upload File</button>
|
<button id="generate-game-button">Upload File(s)</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
Loading…
Reference in New Issue