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