Exemplo n.º 1
0
def create_url2():
    # path = request.json['path']
    length = 4
    attempt = 0
    path = None
    while length<=MAX_URL_LENGTH:
        path = shortuuid.ShortUUID().random(length=length)
        if ShortURL.count(path):
            attempt = attempt + 1
            if attempt >= MAX_RETRY:
                length = length + 1
                attempt = 0
        else:
            break
    if length > MAX_URL_LENGTH:
        return jsonify(success=False), 500
    redirect_url = unquote(request.args.get('redirect_url'))
    # webhook = request.json.get('webhook', None)
    ShortURL(url=path, redirection_url=redirect_url, webhook=None).save()
    return jsonify(success=True,path=path), 200