fix: Add refresh button to bypass cache
All checks were successful
Build Docker / BuildImage (push) Successful in 37s

This commit is contained in:
Nathan Woodburn 2024-10-04 21:36:31 +10:00
parent ed5595c79c
commit 0ce3f9c629
Signed by: nathanwoodburn
GPG Key ID: 203B000478AD0EF1
2 changed files with 37 additions and 10 deletions

View File

@ -217,10 +217,12 @@ def delete_email(conversation_id, email):
# Get email by id # Get email by id
conversation = get_conversation(conversation_id) conversation = get_conversation(conversation_id)
if not conversation: if not conversation:
print("No conversation found")
return return
print(conversation) print(conversation)
if len(conversation) < 1: if len(conversation) < 1:
print("No conversation found")
return return
headers = { headers = {
@ -231,6 +233,7 @@ def delete_email(conversation_id, email):
if email in message["to"]: if email in message["to"]:
requests.delete( requests.delete(
f"https://ticket.woodburn.au/api/conversations/{thread['id']}", headers=headers) f"https://ticket.woodburn.au/api/conversations/{thread['id']}", headers=headers)
clear_cache()
return return
@ -249,11 +252,11 @@ def newemail():
return jsonify(json) return jsonify(json)
# Removed for now
@app.route("/api/email/<path:path>") # @app.route("/api/email/<path:path>")
def getemail(path): # def getemail(path):
email = f'{path}@login.hns.au' # email = f'{path}@login.hns.au'
return jsonify(get_email(email)) # return jsonify(get_email(email))
def send_notification(data): def send_notification(data):
@ -327,7 +330,7 @@ def send_webhook(webhook, data):
} }
} }
], ],
"username": "HNS Login Email", "username": "HNS Email",
"avatar_url": "https://hns.au/favicon.png", "avatar_url": "https://hns.au/favicon.png",
"attachments": [] "attachments": []
} }
@ -339,6 +342,24 @@ def send_webhook(webhook, data):
req = requests.post( req = requests.post(
webhook, json=body) webhook, json=body)
@app.route("/refresh")
def refresh():
# Check if user is logged in
token = request.cookies.get("token")
if not token:
return redirect("/")
# Get user info
user = get_user(token)
if not user:
return redirect("/logout")
clear_cache()
return redirect("/inbox")
def clear_cache():
get_email.cache_clear()
@cache @cache
def get_user(token): def get_user(token):
@ -445,7 +466,8 @@ def parse_email(conversation):
"name": f'{thread["createdBy"]["firstName"]} {thread["createdBy"]["lastName"]}', "name": f'{thread["createdBy"]["firstName"]} {thread["createdBy"]["lastName"]}',
"body": thread["body"], "body": thread["body"],
"date": thread["createdAt"], "date": thread["createdAt"],
"to": thread["to"] "to": thread["to"],
"subject": conversation["subject"]
}) })
return {"messages": messages, "id": conversation["id"]} return {"messages": messages, "id": conversation["id"]}

View File

@ -12,16 +12,21 @@
<body> <body>
<header style="display: inline;"> <header style="display: inline;">
<img src="/favicon.png" style="width:50px;height:50px;"> <img src="/favicon.png" style="width:50px;height:50px;">
<h1>HNS Email</h1> <span style="float:right">{{emails.email}} | <a href="/notifications">Notifications</a> | <a href="/logout">Logout</a></span> <h1>HNS Email</h1> <span style="float:right">{{emails.email}} | <a href="/notifications">Notifications</a> | <a
href="/logout">Logout</a></span>
</header> </header>
<br>
<a href="/refresh" class="button" style="float: right;">Refresh</a>
<div class="centre"> <div class="centre">
{% for conversation in emails.conversations %} {% for conversation in emails.conversations %}
<div class="conversation"> <div class="conversation">
<span>Conversation: {{conversation.id}}</span> <span>Conversation: {{conversation.id}}</span>
{% for message in conversation.messages %} {% for message in conversation.messages %}
<div class="email"> <div class="email">
<div class="from">{{message.name}} ({{message.from}})</div> <div class="date">{{message.date}}</div> <div class="from">{{message.name}} ({{message.from}})</div>
<div class="date">{{message.date}}</div>
<div class="subject">{{message.subject}}</div>
<div class="body">{{message.body|safe}}</div> <div class="body">{{message.body|safe}}</div>
</div> </div>
{% endfor %} {% endfor %}