WI: Don't explode when user uploads image without a save

This is a band-aid on an underlying problem: there is no save directory
to put blobs like images in before the user saves the game. The way
forward is probably to have an in-memory (no disk, Colab privacy (thats
kind of an oxymoron)) folder or something. I want to expand the data
storage functionality into an api in the future so devs can seamlessly
do something like:

Data.get_file_contents("image/blahblah.png")

and they won't have to actually worry about stuff like this
This commit is contained in:
somebody
2023-07-22 17:04:45 -05:00
parent cf27d44f62
commit 68c6030ab0

View File

@@ -6715,11 +6715,18 @@ def UI_2_set_wi_image(uid):
except FileNotFoundError: except FileNotFoundError:
pass pass
else: else:
# Otherwise assign image try:
with open(path, "wb") as file: # Otherwise assign image
file.write(data) with open(path, "wb") as file:
file.write(data)
except FileNotFoundError:
show_error_notification(
"Unable to write image",
"Please save the game before uploading images."
)
return ":(", 500
koboldai_vars.gamesaved = False koboldai_vars.gamesaved = False
return ":)" return ":)", 200
@app.route("/get_wi_image/<int(signed=True):uid>", methods=["GET"]) @app.route("/get_wi_image/<int(signed=True):uid>", methods=["GET"])
@require_allowed_ip @require_allowed_ip