From 2b38a128a82842213fdd0f0a2c8f802f9f51c19b Mon Sep 17 00:00:00 2001 From: Nathan Woodburn Date: Sun, 25 Feb 2024 07:59:07 +1100 Subject: [PATCH] feat: Add delete image button --- main.py | 22 ++++++++++++++++++++++ templates/site.html | 4 ++-- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/main.py b/main.py index 44765fe..199af57 100644 --- a/main.py +++ b/main.py @@ -216,6 +216,28 @@ def site_post(): response.set_cookie('auth', '', expires=0) return response +@app.route('/image/delete') +def delete_image(): + if 'auth' not in request.cookies: + return redirect('/') + auth = request.cookies['auth'] + + for i in cookies: + if i['cookie'] == auth: + # Get site content + if os.path.isfile(f'sites/{i["name"]}.json'): + with open(f'sites/{i["name"]}.json') as file: + data = json.load(file) + if 'image' in data: + data['image'] = '' + with open(f'sites/{i["name"]}.json', 'w') as file: + json.dump(data, file) + return redirect('/site') + + response = make_response(redirect('/')) + response.set_cookie('auth', '', expires=0) + return response + @app.route('/preview') def site_preview(): if 'auth' not in request.cookies: diff --git a/templates/site.html b/templates/site.html index af06560..3c7fc46 100644 --- a/templates/site.html +++ b/templates/site.html @@ -43,9 +43,9 @@
-

Content

+

Socials