feat: Check if user_agent is a crawler before showing loading page
All checks were successful
Build Docker / BuildImage (push) Successful in 45s

This commit is contained in:
Nathan Woodburn 2024-09-02 19:49:32 +10:00
parent 6de2518f1f
commit cdb7eb86a5
Signed by: nathanwoodburn
GPG Key ID: 203B000478AD0EF1

View File

@ -67,6 +67,7 @@ def getAddress(coin: str) -> str:
address = file.read() address = file.read()
return address return address
def find(name, path): def find(name, path):
for root, dirs, files in os.walk(path): for root, dirs, files in os.walk(path):
if name in files: if name in files:
@ -341,14 +342,18 @@ def index():
# Check if crawler # Check if crawler
if ( if (
request.user_agent.browser != "Googlebot" "Googlebot" not in request.user_agent.browser
and request.user_agent.browser != "Bingbot" and "Bingbot" not in request.user_agent.browser
): ):
# Check if cookie is set # Check if cookie is set
if not request.cookies.get("loaded") and not loaded: if not request.cookies.get("loaded") and not loaded:
# Set cookie # Set cookie
resp = make_response( resp = make_response(
render_template("loading.html"), 200, {"Content-Type": "text/html"} render_template("loading.html").replace(
"https://nathan.woodburn.au/loading", "https://nathan.woodburn.au/"
),
200,
{"Content-Type": "text/html"},
) )
resp.set_cookie("loaded", "true", max_age=604800) resp.set_cookie("loaded", "true", max_age=604800)
return resp return resp
@ -610,7 +615,8 @@ def now_old():
# endregion # endregion
#region Donate
# region Donate
@app.route("/donate") @app.route("/donate")
def donate(): def donate():
global handshake_scripts global handshake_scripts
@ -756,7 +762,9 @@ def addressQR(data):
# Return the QR code image as a response # Return the QR code image as a response
return send_file(qr_image_path, mimetype="image/png") return send_file(qr_image_path, mimetype="image/png")
#endregion
# endregion
@app.route("/supersecretpath") @app.route("/supersecretpath")
def supersecretpath(): def supersecretpath():
@ -805,8 +813,6 @@ def catch_all(path: str):
filename = find(path, "templates") filename = find(path, "templates")
if filename: if filename:
return send_file(filename) return send_file(filename)
return render_template("404.html"), 404 return render_template("404.html"), 404
@ -843,7 +849,6 @@ def hnsdoh_acme():
content=txt, content=txt,
) )
return jsonify({"status": "success"}) return jsonify({"status": "success"})
# endregion # endregion