redirect to home if paste was not found

This commit is contained in:
sqozz 2015-01-25 04:35:37 +01:00
parent e7fbb4a76e
commit cafe2539c2

View file

@ -1,5 +1,6 @@
#!/usr/bin/python3 #!/usr/bin/python3
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
#vim: set tabstop=2
from flask import Flask, g, request, render_template, redirect from flask import Flask, g, request, render_template, redirect
import sqlite3 import sqlite3
import random import random
@ -27,6 +28,7 @@ def teardown_request(exception):
@app.route("/") @app.route("/")
@limiter.exempt @limiter.exempt
def root(): def root():
return "Welcome to root!" return "Welcome to root!"
@app.route("/<pasteID>") @app.route("/<pasteID>")
@ -34,7 +36,7 @@ def root():
def paste(pasteID): def paste(pasteID):
target = query_db("SELECT target FROM pastes WHERE paste_url = ?", [pasteID], one=True) target = query_db("SELECT target FROM pastes WHERE paste_url = ?", [pasteID], one=True)
if target is None: if target is None:
return "Shorturl not found!" return redirect("/", 301)
else: else:
url = urlparse(target["target"]) url = urlparse(target["target"])
if url.scheme is "": if url.scheme is "":
@ -45,7 +47,7 @@ def paste(pasteID):
@app.route("/new") @app.route("/new")
@limiter.exempt @limiter.exempt
def new_paste(): def new_short():
target_url = request.args.get("target", "") target_url = request.args.get("target", "")
paste_id = add_redirect(target_url, 1) paste_id = add_redirect(target_url, 1)
return render_template("new_paste.html", paste_id=paste_id) return render_template("new_paste.html", paste_id=paste_id)