From 422999115a63215e76754d46356bc20d931f5020 Mon Sep 17 00:00:00 2001 From: The Stranjer <791672+TheStranjer@users.noreply.github.com> Date: Wed, 18 Dec 2019 19:58:42 -0500 Subject: [PATCH] Show 404 message instead of crashing when requesting a file that isn't there --- fhost.py | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/fhost.py b/fhost.py index 72363a6..b47171d 100755 --- a/fhost.py +++ b/fhost.py @@ -262,23 +262,28 @@ def store_url(url, addr): else: return "Could not determine remote file size (no Content-Length in response header; shoot admin).\n", 411 +def msg404(fn): + return make_response("404 File Not Found: /{0}\n".format(fn), 404) + @app.route("/") def get(path): p = os.path.splitext(path) id = su.debase(p[0]) if p[1]: - f = File.query.get(id) + try: + f = File.query.get(id) + except: + f = None - if f and f.ext == p[1]: + if not f: + return msg404(path) + elif f.ext == p[1]: if f.removed: return legal() fpath = getpath(f.sha256) - if not os.path.exists(fpath): - abort(404) - fsize = os.path.getsize(fpath) if app.config["FHOST_USE_X_ACCEL_REDIRECT"]: @@ -295,7 +300,7 @@ def get(path): if u: return redirect(u.url) - abort(404) + return msg404(path) @app.route("/dump_urls/") @app.route("/dump_urls/")