fix: Update varo with avatar edit
All checks were successful
Build Docker / Build SLDs Image (push) Successful in 20s
Build Docker / Build Main Image (push) Successful in 21s

This commit is contained in:
Nathan Woodburn 2023-11-18 11:39:07 +11:00
parent 40a794c0d4
commit 253b202a5f
Signed by: nathanwoodburn
GPG Key ID: 203B000478AD0EF1
4 changed files with 19 additions and 6 deletions

View File

@ -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: <your-varo-apikey>
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:
```

View File

@ -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]
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)

10
main.py
View File

@ -149,6 +149,11 @@ def edit():
location = data['location']
if 'avatar' in data:
avatar = data['avatar']
if avatar != "":
avatar = "<img class='rounded-circle' width='100px' height='100px' src='"+avatar+"' style='margin-right: 25px;' />"
else:
avatar = "<p style='margin-right: 25px;'>No avatar set</p>"
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)

View File

@ -42,7 +42,9 @@
<h1 style="text-align: center;margin-bottom: 30px;">Edit your page</h1>
</section>
<section style="width: 80%;margin: auto;">
<form action="/upload" method="post" enctype="multipart/form-data"><label class="form-label" style="margin-right: 20px;">Avatar</label><img class="rounded-circle" width="100px" height="100px" src="{{avatar}}" style="margin-right: 25px;"><input class="form-control" type="file" style="display: inline-block;width: 300px;margin-right: 25px;" name="file" accept="image/*" required=""><input class="btn btn-primary" type="submit" style="margin-right: 20px;" value="Upload"><a class="btn btn-primary" role="button" href="/avatar/clear">Clear</a></form>
<form action="/upload" method="post" enctype="multipart/form-data"><label class="form-label" style="margin-right: 20px;">Avatar</label>
<div style="display: inline-block;">{{avatar|safe}}</div><input class="form-control" type="file" style="display: inline-block;width: 300px;margin-right: 25px;" name="file" accept="image/*" required=""><input class="btn btn-primary" type="submit" style="margin-right: 20px;" value="Upload"><a class="btn btn-primary" role="button" href="/avatar/clear">Clear</a>
</form>
<form method="post"><input class="form-control" type="text" style="margin-top: 10px;" name="location" value="{{location}}" placeholder="Location"><input class="form-control" type="text" style="margin-top: 10px;" name="hnschat" placeholder="HNSChat" value="{{hnschat}}"><input class="form-control" type="text" style="margin-top: 10px;" name="email" placeholder="Public Email" value="{{email}}">
<div class="d-xl-flex justify-content-xl-center align-items-xl-center" style="margin-bottom: 10px;margin-top: 10px;"><label class="form-label" style="display: inline-block;margin-right: 15px;">Background colour&nbsp;</label><input class="form-control form-control-color" type="color" style="display: inline-block;border-radius: 50%;width: 50px;height: 50px;" name="bg_colour" value="{{bg_colour}}"></div>
<div class="d-xl-flex justify-content-xl-center align-items-xl-center" style="margin-bottom: 10px;margin-top: 10px;"><label class="form-label" style="display: inline-block;margin-right: 15px;">Foreground colour&nbsp;</label><input class="form-control form-control-color" type="color" style="display: inline-block;border-radius: 50%;width: 50px;height: 50px;" name="fg_colour" value="{{fg_colour}}"></div>