feat: Add delete image button

This commit is contained in:
Nathan Woodburn 2024-02-25 07:59:07 +11:00
parent c24ab6ad48
commit 2b38a128a8
Signed by: nathanwoodburn
GPG Key ID: 203B000478AD0EF1
2 changed files with 24 additions and 2 deletions

22
main.py
View File

@ -216,6 +216,28 @@ def site_post():
response.set_cookie('auth', '', expires=0) response.set_cookie('auth', '', expires=0)
return response 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') @app.route('/preview')
def site_preview(): def site_preview():
if 'auth' not in request.cookies: if 'auth' not in request.cookies:

View File

@ -43,9 +43,9 @@
<div class="row"> <div class="row">
<div class="col-md-6"> <div class="col-md-6">
<form method="post" enctype="multipart/form-data"> <form method="post" enctype="multipart/form-data">
<h1>Content</h1><label class="form-label" style="font-size: 24px;margin-right: 10px;">Image</label><input class="form-control" type="file" style="margin-bottom: 25px;width: auto;display: inline-block;" name="image"><button class="btn btn-primary" type="button" style="display: inline;padding-top: 8px;padding-right: 12px;padding-bottom: 8px;padding-left: 12px;margin-left: 5px;"><svg xmlns="http://www.w3.org/2000/svg" width="1em" height="1em" fill="currentColor" viewBox="0 0 16 16" class="bi bi-trash3-fill"> <h1>Content</h1><label class="form-label" style="font-size: 24px;margin-right: 10px;">Image</label><input class="form-control" type="file" style="margin-bottom: 25px;width: auto;display: inline-block;" name="image"><a class="btn btn-primary" role="button" style="display: inline;padding-top: 8px;padding-right: 12px;padding-bottom: 8px;padding-left: 12px;margin-left: 5px;" href="/image/delete"><svg xmlns="http://www.w3.org/2000/svg" width="1em" height="1em" fill="currentColor" viewBox="0 0 16 16" class="bi bi-trash3-fill">
<path d="M11 1.5v1h3.5a.5.5 0 0 1 0 1h-.538l-.853 10.66A2 2 0 0 1 11.115 16h-6.23a2 2 0 0 1-1.994-1.84L2.038 3.5H1.5a.5.5 0 0 1 0-1H5v-1A1.5 1.5 0 0 1 6.5 0h3A1.5 1.5 0 0 1 11 1.5m-5 0v1h4v-1a.5.5 0 0 0-.5-.5h-3a.5.5 0 0 0-.5.5M4.5 5.029l.5 8.5a.5.5 0 1 0 .998-.06l-.5-8.5a.5.5 0 1 0-.998.06Zm6.53-.528a.5.5 0 0 0-.528.47l-.5 8.5a.5.5 0 0 0 .998.058l.5-8.5a.5.5 0 0 0-.47-.528ZM8 4.5a.5.5 0 0 0-.5.5v8.5a.5.5 0 0 0 1 0V5a.5.5 0 0 0-.5-.5"></path> <path d="M11 1.5v1h3.5a.5.5 0 0 1 0 1h-.538l-.853 10.66A2 2 0 0 1 11.115 16h-6.23a2 2 0 0 1-1.994-1.84L2.038 3.5H1.5a.5.5 0 0 1 0-1H5v-1A1.5 1.5 0 0 1 6.5 0h3A1.5 1.5 0 0 1 11 1.5m-5 0v1h4v-1a.5.5 0 0 0-.5-.5h-3a.5.5 0 0 0-.5.5M4.5 5.029l.5 8.5a.5.5 0 1 0 .998-.06l-.5-8.5a.5.5 0 1 0-.998.06Zm6.53-.528a.5.5 0 0 0-.528.47l-.5 8.5a.5.5 0 0 0 .998.058l.5-8.5a.5.5 0 0 0-.47-.528ZM8 4.5a.5.5 0 0 0-.5.5v8.5a.5.5 0 0 0 1 0V5a.5.5 0 0 0-.5-.5"></path>
</svg></button><input class="form-control" type="text" style="margin-bottom: 25px;" name="title" value="{{title}}" placeholder="Title"> </svg></a><input class="form-control" type="text" style="margin-bottom: 25px;" name="title" value="{{title}}" placeholder="Title">
<div style="margin-bottom: 25px;"> <div style="margin-bottom: 25px;">
<h4>Socials</h4><input class="form-control" type="text" style="display: inline-block;width: auto;" name="email" value="{{socials['email']}}" placeholder="Email"><input class="form-control" type="text" style="display: inline-block;width: auto;" name="twitter" value="{{socials['twitter']}}" placeholder="Twitter"><input class="form-control" type="text" style="display: inline-block;width: auto;" name="github" value="{{socials['github']}}" placeholder="Github"><input class="form-control" type="text" style="display: inline-block;width: auto;" name="youtube" value="{{socials['youtube']}}" placeholder="YouTube"> <h4>Socials</h4><input class="form-control" type="text" style="display: inline-block;width: auto;" name="email" value="{{socials['email']}}" placeholder="Email"><input class="form-control" type="text" style="display: inline-block;width: auto;" name="twitter" value="{{socials['twitter']}}" placeholder="Twitter"><input class="form-control" type="text" style="display: inline-block;width: auto;" name="github" value="{{socials['github']}}" placeholder="Github"><input class="form-control" type="text" style="display: inline-block;width: auto;" name="youtube" value="{{socials['youtube']}}" placeholder="YouTube">
</div> </div>