From 96cce19ca589b71258bbb72581319ef143eca4d5 Mon Sep 17 00:00:00 2001 From: sqozz Date: Fri, 12 Feb 2016 18:01:19 +0100 Subject: [PATCH] Implemented inspection mode by appending + on a short url. Also a clean, html free resolver is now available by appending ?resolve on a short url. --- schort.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/schort.py b/schort.py index 77b1974..75ab7ef 100755 --- a/schort.py +++ b/schort.py @@ -8,18 +8,27 @@ app = Flask(__name__) @app.route('/', methods=['GET', 'POST']) @app.route('/', methods=['GET', 'POST']) def short(shortLink=""): + print("resolve" in request.args) if request.method == "GET": if shortLink: + noauto = shortLink[-1] == "+" + if noauto: shortLink = shortLink[:-1] conn = sqlite3.connect("data/links.sqlite") c = conn.cursor() - result = c.execute('SELECT * FROM links WHERE shortLink=?', (shortLink, )).fetchone() + result = c.execute('SELECT longLink FROM links WHERE shortLink=?', (shortLink, )).fetchone() conn.close() if result: - url = result[1] + url = result[0] parsedUrl = urlparse(url) if parsedUrl.scheme == "": url = "http://" + url - return redirect(url, code=301) # Redirect to long URL saved in the database + if "resolve" in request.args: + return url + else: + if noauto: + return "" + url + "" + else: + return redirect(url, code=301) # Redirect to long URL saved in the database else: return render_template("index.html", name=shortLink, message="Enter long URL for "+ request.url_root + shortLink+":", message_type="info") # Custom link page else: