feat: Add better covenant display
All checks were successful
Build Docker / BuildImage (push) Successful in 38s
Check Code Quality / RuffCheck (push) Successful in 49s

This commit is contained in:
2025-11-21 13:24:21 +11:00
parent b6662f400a
commit eea558361c
2 changed files with 97 additions and 10 deletions

View File

@@ -242,13 +242,37 @@ def hip02(domain: str):
@app.route("/api/v1/covenant", methods=["POST"])
def covenant_api():
data = request.get_json()
# Get the covenant data
action = data.get("action")
items = data.get("items", [])
return jsonify(
{
"success": True,
"data": data,
}
)
if not action:
return jsonify({"success": False, "data": data})
display = f"{action}"
if len(items) > 0:
name_hash = items[0]
# Lookup name from database
db = get_db()
cur = db.execute("SELECT * FROM names WHERE namehash = ?", (name_hash,))
row = cur.fetchone()
if row:
name = row["name"]
display += f' <a href="/name/{name}">{name}</a>'
else:
req = requests.get(f"https://hsd.hns.au/api/v1/namehash/{name_hash}")
if req.status_code == 200:
name = req.json().get("result")
if name:
display += f" {name}"
# Insert into database
db.execute(
"INSERT OR REPLACE INTO names (namehash, name) VALUES (?, ?)",
(name_hash, name),
)
db.commit()
return jsonify({"success": True, "data": data, "display": display})
# endregion