feat: Add searching for files before returning a 404
All checks were successful
Build Docker / BuildImage (push) Successful in 42s

This commit is contained in:
Nathan Woodburn 2024-08-21 11:49:03 +10:00
parent 56349561f9
commit 9c0d592a24
Signed by: nathanwoodburn
GPG Key ID: 203B000478AD0EF1
3 changed files with 15 additions and 1 deletions

View File

@ -67,6 +67,11 @@ def getAddress(coin: str) -> str:
address = file.read() address = file.read()
return address return address
def find(name, path):
for root, dirs, files in os.walk(path):
if name in files:
return os.path.join(root, name)
# Assets routes # Assets routes
@app.route("/assets/<path:path>") @app.route("/assets/<path:path>")
@ -765,7 +770,7 @@ def supersecretpath():
@app.route("/<path:path>") @app.route("/<path:path>")
def catch_all(path): def catch_all(path: str):
global handshake_scripts global handshake_scripts
# If localhost, don't load handshake # If localhost, don't load handshake
if ( if (
@ -793,6 +798,15 @@ def catch_all(path):
path.strip("/") + ".html", handshake_scripts=handshake_scripts, sites=sites path.strip("/") + ".html", handshake_scripts=handshake_scripts, sites=sites
) )
# Try to find a file matching
if path.count("/") < 1:
# Try to find a file matching
filename = find(path, "templates")
if filename:
return send_file(filename)
return render_template("404.html"), 404 return render_template("404.html"), 404

Binary file not shown.

Before

Width:  |  Height:  |  Size: 479 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 53 KiB