From 68c6030ab063a4a58366b69046c41439b0fcfe10 Mon Sep 17 00:00:00 2001 From: somebody Date: Sat, 22 Jul 2023 17:04:45 -0500 Subject: [PATCH] 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 --- aiserver.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/aiserver.py b/aiserver.py index dc565c97..8c07efa8 100644 --- a/aiserver.py +++ b/aiserver.py @@ -6715,11 +6715,18 @@ def UI_2_set_wi_image(uid): except FileNotFoundError: pass else: - # Otherwise assign image - with open(path, "wb") as file: - file.write(data) + try: + # Otherwise assign image + 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 - return ":)" + return ":)", 200 @app.route("/get_wi_image/", methods=["GET"]) @require_allowed_ip