Exemplo n.º 1
0
def delete_url(url_id):
    #check_admin()
    url = Url.get(url_id)
    if url is None:
        raise APIResourceNotFoundError('url')
    close_url(url)
    raise seeother('/index')
Exemplo n.º 2
0
def index():
    if request.method == 'POST':
        thing = request.form.get('url')
        if thing:
            if '://' not in thing:
                thing = 'http://' + thing

            # Verify the URL
            parsed = urlparse(thing)
            if parsed.scheme not in ('http', 'https'):
                return "I only take HTTP or HTTPS URLs, dummy"

            urlhash = hashlib.sha1(thing).hexdigest()
            try:
                url = Url.get(Url.url_hash == urlhash)
            except:
                url = Url()
                url.url = thing
                url.url_hash = urlhash
                url.created = datetime.datetime.now()
                url.save()

                # hokay. got us an ID, let's make a key.
                url.key = base36_encode(url.id)
                url.save()

            return render_template('added.html', short_url="http://{0}/{1}".format(request.headers['host'], url.key))
        else:
            return "You didn't give me shit"
    else:
        return render_template('index.html')
Exemplo n.º 3
0
def get_url(b58id):
    try:
        url = Url.get(b58id)
        if url is not None:
            ret = url.real
        else:
            ret = None
    except ObjectDoesNotExist:
        ret = Var.get('default_redirect')
    return ret
Exemplo n.º 4
0
def go(key):
    result = "There's no URL with that key, dummy!"

    try:
        url = Url.get(Url.key == key)
        if url.enabled:
            result = redirect(url.url)
    except:
        pass

    return result
Exemplo n.º 5
0
def open_url(url_id):
    #check_admin()
    url = Url.get(url_id)
    if url is None:
        raise APIResourceNotFoundError('url')
    ##之前不是关闭状态
    if url.status != 0:
        raise APIResourceNotFoundError('url')
    url.status = 1
    url.update()
    raise seeother('/index')
Exemplo n.º 6
0
def unshorten(slug):
    if path.isfile(path.join("static", slug)):
        return send_from_directory("static", slug)

    try:
        id = short_url.decode_url(slug)
        url = Url.get(Url.id == id)
        return redirect(url.url)
    except:
        # invalid url or not found
        abort(404)
Exemplo n.º 7
0
def close_url(url_id):
    #check_admin()
    url = Url.get(url_id)
    if url is None:
        raise APIResourceNotFoundError('url')
    ##之前不是关闭状态
    if url.status != 1:
        raise APIResourceNotFoundError('url')
    url.status = 0

    ##todo:这里还有很多事情要做,比如关闭监听,需要删除之前抓的网页
    url.update()
    raise seeother('/index')
Exemplo n.º 8
0
def show_single_url(url_id):
    url = Url.get(url_id)
    return dict(url=url, user=ctx.request.user)