From 253b202a5feb2d0e005c67bcabdf6fcc14574dcc Mon Sep 17 00:00:00 2001 From: Nathan Woodburn Date: Sat, 18 Nov 2023 11:39:07 +1100 Subject: [PATCH] fix: Update varo with avatar edit --- README.md | 4 ++++ avatar.py | 7 ++++++- main.py | 10 ++++++---- templates/edit.html | 4 +++- 4 files changed, 19 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 1e1733a..b74167f 100644 --- a/README.md +++ b/README.md @@ -16,6 +16,8 @@ services: image: git.woodburn.au/nathanwoodburn/shakecities:latest depends_on: - db + volumes: + - images:/data environment: DB_HOST: db DB_USER: main @@ -24,6 +26,7 @@ services: CITY_DOMAIN: exampledomainnathan1 REG_KEY: CITY_ALIAS: city.hnshosting.au # ICANN domain that points to the IP for the cities server + MAIN_DOMAIN: cities.hnshosting.au WORKERS: 2 # number of workers to run (should be 2 * number of cores) sites: @@ -49,4 +52,5 @@ services: - db_data:/var/lib/mysql volumes: db_data: + images: ``` \ No newline at end of file diff --git a/avatar.py b/avatar.py index 40c82a7..7900cd6 100644 --- a/avatar.py +++ b/avatar.py @@ -3,6 +3,7 @@ import dotenv import db import random import json +import varo IMAGE_LOCATION = os.getenv('IMAGE_LOCATION') @@ -31,11 +32,15 @@ def save_avatar(file,owner): user_data = db.get_website_data_raw(owner) user_data['avatar'] = MAIN_DOMAIN + "/avatar/" + filename db.update_website_data_raw(owner,json.dumps(user_data)) + varo.update_avatar(user_data['avatar'],owner) return filename def clear(owner): user_data = db.get_website_data_raw(owner) filename = user_data['avatar'].split('/')[-1] - os.remove(f"{IMAGE_LOCATION}/{filename}") + + if filename != "": + os.remove(f"{IMAGE_LOCATION}/{filename}") user_data['avatar'] = "" db.update_website_data_raw(owner,json.dumps(user_data)) + varo.update_avatar(user_data['avatar'],owner) diff --git a/main.py b/main.py index 2432dc4..f654e5f 100644 --- a/main.py +++ b/main.py @@ -149,6 +149,11 @@ def edit(): location = data['location'] if 'avatar' in data: avatar = data['avatar'] + if avatar != "": + avatar = "" + else: + avatar = "

No avatar set

" + if 'bg_colour' in data: bg_colour = data['bg_colour'] if 'fg_colour' in data: @@ -180,21 +185,18 @@ def send_edit(): return resp # Json data - data = {} + data = db.get_website_data_raw(user['domain']) data['data'] = request.form['data'] data['HNS'] = request.form['hns'] data['BTC'] = request.form['btc'] data['ETH'] = request.form['eth'] data['hnschat'] = request.form['hnschat'] data['location'] = request.form['location'] - data['avatar'] = request.form['avatar'] data['bg_colour'] = request.form['bg_colour'] data['fg_colour'] = request.form['fg_colour'] data['text_colour'] = request.form['text_colour'] data['email'] = request.form['email'] - - varo.update_avatar(data['avatar'],user['domain']) # Convert to json data = json.dumps(data) db.update_website_data_raw(user['domain'],data) diff --git a/templates/edit.html b/templates/edit.html index e026088..4089857 100644 --- a/templates/edit.html +++ b/templates/edit.html @@ -42,7 +42,9 @@

Edit your page

-
Clear
+
+
{{avatar|safe}}
Clear +