示例#1
0
def shorten(url):
    """Simple shorten logic.
    `original-short` + url will store the short id.
    `short-original` + short_id will store the corresponding original url.

    :param url: The original url you want to shorten.
    """
    short_id = db.get('original-short:' + url)
    if short_id is not None:
        return short_id
    num = db.incr('url-autoincr-id')
    short_id = base52_encode(num)
    db.set('original-short:' + url, short_id)
    db.set('short-original:' + short_id, url)
    return short_id
示例#2
0
文件: views.py 项目: bearzk/shortly
def shorten(url):
    """Simple shorten logic.
    `original-short` + url will store the short id.
    `short-original` + short_id will store the corresponding original url.

    :param url: The original url you want to shorten.
    """
    short_id = db.get('original-short:' + url)
    if short_id is not None:
        return short_id
    num = db.incr('url-autoincr-id')
    short_id = base52_encode(num)
    db.set('original-short:' + url, short_id)
    db.set('short-original:' + short_id, url)
    return short_id
示例#3
0
def original(short_id):
    original_url = db.get('short-original:' + short_id)
    if original_url is None:
        abort(404)
    db.incr('shortly-count')
    return redirect(original_url)
示例#4
0
文件: views.py 项目: bearzk/shortly
def original(short_id):
    original_url = db.get('short-original:' + short_id)
    if original_url is None:
        abort(404)
    db.incr('shortly-count')
    return redirect(original_url)