Exemple #1
0
def new():
    if 'url' not in request.args:
        flask.abort(400)

    url = request.args['url']
    url = urllib.unquote(url)

    if not (url.startswith('http://') or url.startswith('https://')):
        flask.abort(400)

    short, long = db.get_url(long=url)
    if not short:
        short, long = db.new_url(long=url)

    return render_template('new.html', short=short)
Exemple #2
0
def redirect(short):
    short, long = db.get_url(short=short)
    return flask.redirect(long, code=301)