(code)
return response
Resolve the short url. code=301 PERMANENT REDIRECTION
Resolve the short url. code=301 PERMANENT REDIRECTION
Resolve the short url . code = 301 PERMANENT REDIRECTION
def resolve(code):
    """Resolve the short url. code=301 PERMANENT REDIRECTION"""
    secret_key = request.headers.get('secret_key')
    try:
        # check if link is not a secret link
        if code.startswith('+') or code.endswith('+'):
            stats = link_stats(code)
            response = jsonify(stats)
            if stats is None:
                response = jsonify({'error': 'URL not found or disabled'}), 404
        else:
            long_url = resolve_short(
                code.strip('+'), request=request, secret_key=secret_key)
            response = redirect(long_url, code=301)
    except LinkExpired:
        response = jsonify(dict(error="Link has expired")), 404
    except URLAuthFailed:
        response = jsonify({'error': 'Access to URL forbidden'}), 403
    except (URLNotFound, AssertionError):
        response = jsonify({'error': 'URL not found or disabled'}), 404
    return response
def resolve ( code ) : secret_key = request . headers . get ( 'secret_key' ) try : # check if link is not a secret link if code . startswith ( '+' ) or code . endswith ( '+' ) : stats = link_stats ( code ) response = jsonify ( stats ) if stats is None : response = jsonify ( { 'error' : 'URL not found or disabled' } ) , 404 else : long_url = resolve_short ( code . strip ( '+' ) , request = request , secret_key = secret_key ) response = redirect ( long_url , code = 301 ) except LinkExpired : response = jsonify ( dict ( error = "Link has expired" ) ) , 404 except URLAuthFailed : response = jsonify ( { 'error' : 'Access to URL forbidden' } ) , 403 except ( URLNotFound , AssertionError ) : response = jsonify ( { 'error' : 'URL not found or disabled' } ) , 404 return response