From c1079b6d2b527a77b036d96d573a652f4cf632eb Mon Sep 17 00:00:00 2001 From: xemeds Date: Mon, 20 Jul 2020 16:40:15 +0000 Subject: [PATCH] Added the shortened url route --- tiny0/database.db | Bin 12288 -> 12288 bytes tiny0/routes.py | 17 ++++++++++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/tiny0/database.db b/tiny0/database.db index eb18bb559f400bfb82f2ac20a632711878e02e07..5dba13055853e02bb8ca3911ac5faec788853272 100644 GIT binary patch delta 33 gcmZojXh@hKEvU@Ez`zW|Fd#lr$Cy!hW5NP`0ACCRt^fc4 delta 33 gcmZojXh@hKEhxsoz`zW|Fd#Tl$Cy!UW5NP`09`!=jsO4v diff --git a/tiny0/routes.py b/tiny0/routes.py index e21cbfd..59c802c 100644 --- a/tiny0/routes.py +++ b/tiny0/routes.py @@ -4,7 +4,7 @@ from tiny0.forms import URLForm from tiny0.models import URL from tiny0.token import gen_valid_token -# Index Page +# Index route @app.route("/", methods=['GET', 'POST']) def index(): # Create a instance of the form @@ -26,3 +26,18 @@ def index(): else: # Return the index page with the form return render_template("index.html", form=form) + +# Shortened url route +@app.route("/") +def short_url(token): + # Query the token in the database + query = URL.query.filter_by(token=token).first() + + # If the query response was empty + if not query: + return "invalid" + + # Else if the query response contained data + else: + # Redirect to the url of the token + return redirect(query.url) \ No newline at end of file