Example #1
0
def shorten():
    url = request.form.get('url')

    if url is None:
        error = 'missing required param'
        signals.link_refused.send(g.sender(), error=error)
        return jsonify(error=error), 400
    elif len(url) >= 2000:
        error = 'url too long'
        signals.link_refused.send(g.sender(), error=error)
        return jsonify(error=error), 400

    elif not re.match(url_re, url):
        error = 'invalid url'
        signals.link_refused.send(g.sender(), error=error)
        return jsonify(error=error), 400

    elif canonical_url(url) in app.config['DOMAIN_BLACKLIST']:
        error = 'blacklisted domain'
        signals.link_refused.send(g.sender(), error=error)
        return jsonify(error=error), 403

    id36 = Links.new(url, request.remote_addr)
    if id36 is None:
        return jsonify(error='server error'), 500

    short_url = url_for('shortened', id=id36, _external=True)
    return jsonify(url=short_url)
Example #2
0
def shortened(id):
    link = Links.get(id)

    if link is None:
        abort(404)
    elif not link['active']:
        signals.disabled_link_visited.send(g.sender(), request=request)
        return render_template('disabled.html'), 410

    signals.link_visited.send(g.sender(), request=request)
    return redirect(link['target']), 301
Example #3
0
def increment_clicks(sender, request):
    id36 = request.view_args['id']
    Links.increment_clicks(id36)
    print 'visited signal received'
Example #4
0
def disable(id36):
    """
    Disables link with matching id36
    """
    Links.disable(id36)