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

This commit is contained in:
2024-10-04 21:36:31 +10:00
parent ed5595c79c
commit 0ce3f9c629
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
conversation = get_conversation(conversation_id)
if not conversation:
print("No conversation found")
return
print(conversation)
if len(conversation) < 1:
print("No conversation found")
return
headers = {
@@ -231,6 +233,7 @@ def delete_email(conversation_id, email):
if email in message["to"]:
requests.delete(
f"https://ticket.woodburn.au/api/conversations/{thread['id']}", headers=headers)
clear_cache()
return
@@ -249,11 +252,11 @@ def newemail():
return jsonify(json)
@app.route("/api/email/<path:path>")
def getemail(path):
email = f'{path}@login.hns.au'
return jsonify(get_email(email))
# Removed for now
# @app.route("/api/email/<path:path>")
# def getemail(path):
# email = f'{path}@login.hns.au'
# return jsonify(get_email(email))
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",
"attachments": []
}
@@ -339,6 +342,24 @@ def send_webhook(webhook, data):
req = requests.post(
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
def get_user(token):
@@ -445,7 +466,8 @@ def parse_email(conversation):
"name": f'{thread["createdBy"]["firstName"]} {thread["createdBy"]["lastName"]}',
"body": thread["body"],
"date": thread["createdAt"],
"to": thread["to"]
"to": thread["to"],
"subject": conversation["subject"]
})
return {"messages": messages, "id": conversation["id"]}