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
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)