From 6db56ef6aa84f74e49734688659b6add0b31237b Mon Sep 17 00:00:00 2001 From: realcgcristi Date: Mon, 9 Sep 2024 10:25:58 +0300 Subject: [PATCH] 404 page --- app.py | 15 +++++++++- templates/404.html | 72 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 86 insertions(+), 1 deletion(-) create mode 100644 templates/404.html diff --git a/app.py b/app.py index 9391510..a34e2ed 100644 --- a/app.py +++ b/app.py @@ -109,10 +109,13 @@ def shorten_url(): @app.route('/', methods=['GET']) def redirect_vanity(vanity): target = data_store.get(vanity) + if target: if target['type'] == 'pastebin': + return render_template(f'{vanity}.html') elif target['type'] == 'file': + file_path = os.path.join(app.config['UPLOAD_FOLDER'], f'{vanity}_{target["filename"]}') file_info = { 'name': target['filename'], @@ -120,12 +123,22 @@ def redirect_vanity(vanity): 'modified_at': datetime.fromtimestamp(os.path.getmtime(file_path)).strftime('%Y-%m-%d %H:%M:%S'), 'url': url_for('download_file', vanity=vanity) } + + return render_template('file.html', **file_info) + + return render_template('404.html'), 404 + @app.route('//raw', methods=['GET']) -def rawvanity(vanity): +def raw_vanity(vanity): target = data_store.get(vanity) + if target: if target['type'] == 'pastebin': + return render_template(f'{vanity}raw.html') + + return render_template('404.html'), 404 + if __name__ == '__main__': app.run(debug=True,port=7123) \ No newline at end of file diff --git a/templates/404.html b/templates/404.html new file mode 100644 index 0000000..bc73bec --- /dev/null +++ b/templates/404.html @@ -0,0 +1,72 @@ + + + + + + 404 Not Found + + + +
+

404

+

Oops! The page you’re looking for doesn’t exist.

+

Go back to the homepage

+
+
+
+
+

Source code on:

GitHub | Spitkov's Git +
+ +