WebHost: give proper incompatible version error message.. in the future when this is deployed for next time.
This commit is contained in:
parent
b82e0749b7
commit
a6cca3094d
2
Main.py
2
Main.py
|
@ -311,7 +311,7 @@ def main(args, seed=None, baked_server_options: Optional[Dict[str, object]] = No
|
||||||
multidata = zlib.compress(pickle.dumps(multidata), 9)
|
multidata = zlib.compress(pickle.dumps(multidata), 9)
|
||||||
|
|
||||||
with open(os.path.join(temp_dir, f'{outfilebase}.archipelago'), 'wb') as f:
|
with open(os.path.join(temp_dir, f'{outfilebase}.archipelago'), 'wb') as f:
|
||||||
f.write(bytes([1])) # version of format
|
f.write(bytes([2])) # version of format
|
||||||
f.write(multidata)
|
f.write(multidata)
|
||||||
|
|
||||||
multidata_task = pool.submit(write_multidata)
|
multidata_task = pool.submit(write_multidata)
|
||||||
|
|
|
@ -241,8 +241,8 @@ class Context:
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def decompress(data: bytes) -> dict:
|
def decompress(data: bytes) -> dict:
|
||||||
format_version = data[0]
|
format_version = data[0]
|
||||||
if format_version != 1:
|
if format_version > 2:
|
||||||
raise Exception("Incompatible multidata.")
|
raise Utils.VersionException("Incompatible multidata.")
|
||||||
return restricted_loads(zlib.decompress(data[1:]))
|
return restricted_loads(zlib.decompress(data[1:]))
|
||||||
|
|
||||||
def _load(self, decoded_obj: dict, use_embedded_server_options: bool):
|
def _load(self, decoded_obj: dict, use_embedded_server_options: bool):
|
||||||
|
|
4
Utils.py
4
Utils.py
|
@ -474,3 +474,7 @@ def stream_input(stream, queue):
|
||||||
thread = Thread(target=queuer, name=f"Stream handler for {stream.name}", daemon=True)
|
thread = Thread(target=queuer, name=f"Stream handler for {stream.name}", daemon=True)
|
||||||
thread.start()
|
thread.start()
|
||||||
return thread
|
return thread
|
||||||
|
|
||||||
|
|
||||||
|
class VersionException(Exception):
|
||||||
|
pass
|
||||||
|
|
|
@ -136,7 +136,7 @@ def view_seed(seed: UUID):
|
||||||
seed = Seed.get(id=seed)
|
seed = Seed.get(id=seed)
|
||||||
if not seed:
|
if not seed:
|
||||||
abort(404)
|
abort(404)
|
||||||
return render_template("viewSeed.html", seed=seed)
|
return render_template("viewSeed.html", seed=seed, slot_count=count(seed.slots))
|
||||||
|
|
||||||
|
|
||||||
@app.route('/new_room/<suuid:seed>')
|
@app.route('/new_room/<suuid:seed>')
|
||||||
|
|
|
@ -22,6 +22,10 @@
|
||||||
<td>Created: </td>
|
<td>Created: </td>
|
||||||
<td id="creation-time" data-creation-time="{{ seed.creation_time }}"></td>
|
<td id="creation-time" data-creation-time="{{ seed.creation_time }}"></td>
|
||||||
</tr>
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>Players: </td>
|
||||||
|
<td>{{ slot_count }}</td>
|
||||||
|
</tr>
|
||||||
{% if seed.spoiler %}
|
{% if seed.spoiler %}
|
||||||
<tr>
|
<tr>
|
||||||
<td>Spoiler: </td>
|
<td>Spoiler: </td>
|
||||||
|
|
|
@ -9,7 +9,7 @@ from flask import request, flash, redirect, url_for, session, render_template
|
||||||
from pony.orm import flush, select
|
from pony.orm import flush, select
|
||||||
|
|
||||||
from WebHostLib import app, Seed, Room, Slot
|
from WebHostLib import app, Seed, Room, Slot
|
||||||
from Utils import parse_yaml
|
from Utils import parse_yaml, VersionException
|
||||||
from Patch import preferred_endings
|
from Patch import preferred_endings
|
||||||
|
|
||||||
banned_zip_contents = (".sfc",)
|
banned_zip_contents = (".sfc",)
|
||||||
|
@ -102,11 +102,15 @@ def uploads():
|
||||||
elif file and allowed_file(file.filename):
|
elif file and allowed_file(file.filename):
|
||||||
if zipfile.is_zipfile(file):
|
if zipfile.is_zipfile(file):
|
||||||
with zipfile.ZipFile(file, 'r') as zfile:
|
with zipfile.ZipFile(file, 'r') as zfile:
|
||||||
res = upload_zip_to_db(zfile)
|
try:
|
||||||
if type(res) == str:
|
res = upload_zip_to_db(zfile)
|
||||||
return res
|
except VersionException:
|
||||||
elif res:
|
flash(f"Could not load multidata. Wrong Version detected.")
|
||||||
return redirect(url_for("view_seed", seed=res.id))
|
else:
|
||||||
|
if type(res) == str:
|
||||||
|
return res
|
||||||
|
elif res:
|
||||||
|
return redirect(url_for("view_seed", seed=res.id))
|
||||||
else:
|
else:
|
||||||
file.seek(0) # offset from is_zipfile check
|
file.seek(0) # offset from is_zipfile check
|
||||||
# noinspection PyBroadException
|
# noinspection PyBroadException
|
||||||
|
|
Loading…
Reference in New Issue