예제 #1
0
def create_code():
    '''创建代码'''
    if not g.current_user:
        return BaseResponse.return_unauthorized('请先登录')
    args = request.json
    item = Code.create_or_update(**args)
    return BaseResponse.return_success(item.format())
예제 #2
0
def register():
    '''注册'''
    args = request.json
    s, item = User.register(**args)
    if s != 200:
        return BaseResponse.return_response(status=s, message=item)
    return BaseResponse.return_response(
        data=item, headers={BaseConfig.HEAD_AUTHORIZATION: item.authorization})
예제 #3
0
def create_visitor_log():
    '''生成访问记录'''
    args = request.json
    headers = request.headers
    ua = headers.get('user_agent')
    args['user_agent'] = ua
    res = VisitorLog.visit(**args)
    return BaseResponse.return_success(res.format())
예제 #4
0
 def _wrapped(*args, **kwargs):
     _args = request.headers
     diff = [item[0].upper() + item[1:] for item in params
             ] - dict.fromkeys(list(_args.keys())).keys()
     if diff:
         return BaseResponse.return_forbidden(
             '{} is necessary'.format(diff))
     return func(*args, **kwargs)
예제 #5
0
def wapi_test():
    '''测试'''
    res = {}
    res.update(dict(path=request.path))
    res.update(dict(method=request.method))
    res.update(dict(args=request.args))
    res.update(dict(json=request.json))
    res.update(dict(form=request.form))
    res.update(dict(headers=dict(request.headers)))
    return BaseResponse.return_success(res)
예제 #6
0
 def _wrapped(*args, **kwargs):
     content_type = request.content_type
     _args = None
     if content_type == 'application/x-www-form-urlencoded':
         _args = request.form
     elif content_type == 'application/json':
         _args = request.json
     else:
         _args = request.args
     diff = list(params) - dict.fromkeys(list(_args.keys())).keys()
     if diff:
         return BaseResponse.return_forbidden(
             '{} is necessary'.format(diff))
     return func(*args, **kwargs)
예제 #7
0
def test():
    ''''''
    return BaseResponse.return_success()
예제 #8
0
def code_detail(id):
    '''获取详情'''

    item = Code.query_by_id(id)
    print(item)
    return BaseResponse.return_success(item.format())
예제 #9
0
def app_error_handler(e):
    app.logger.error(traceback.format_exc())
    return BaseResponse.return_internal_server_error(str(e))
예제 #10
0
def upload():
    '''创建代码'''
    logger.debug(request.files)
    return BaseResponse.return_success()
예제 #11
0
def crawler_article():
    '''创建'''
    args = request.json
    url = args['url']
    res = Article.crawler(url=url)
    return BaseResponse.return_success(res.format())
예제 #12
0
def update_article(id):
    '''更新文章'''
    res = Article.query_by_id(id)
    res.crawler_self()
    return BaseResponse.return_success(res.format())
예제 #13
0
def create_auto_id(shard_id, item_id):
    '''生成id'''
    id = AutoId.generate_id(shard_id, item_id)
    return BaseResponse.return_success({"id": id})
예제 #14
0
 def decorated_function(*args, **kwargs):
     if g.user is None:
         return BaseResponse.return_unauthorized()
     return f(*args, **kwargs)