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())
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})
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())
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)
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)
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)
def test(): '''''' return BaseResponse.return_success()
def code_detail(id): '''获取详情''' item = Code.query_by_id(id) print(item) return BaseResponse.return_success(item.format())
def app_error_handler(e): app.logger.error(traceback.format_exc()) return BaseResponse.return_internal_server_error(str(e))
def upload(): '''创建代码''' logger.debug(request.files) return BaseResponse.return_success()
def crawler_article(): '''创建''' args = request.json url = args['url'] res = Article.crawler(url=url) return BaseResponse.return_success(res.format())
def update_article(id): '''更新文章''' res = Article.query_by_id(id) res.crawler_self() return BaseResponse.return_success(res.format())
def create_auto_id(shard_id, item_id): '''生成id''' id = AutoId.generate_id(shard_id, item_id) return BaseResponse.return_success({"id": id})
def decorated_function(*args, **kwargs): if g.user is None: return BaseResponse.return_unauthorized() return f(*args, **kwargs)