| 123456789101112131415161718192021 |
- from __future__ import annotations
- from typing import Any, Optional
- from quart import jsonify
- class R:
- """统一 JSON 响应构建器。"""
- @staticmethod
- def ok(data: Any = None, message: str = "success"):
- return jsonify({"code": 0, "message": message, "data": data})
- @staticmethod
- def fail(code: int = -1, message: str = "error", data: Any = None, http_status: int = 200):
- return jsonify({"code": code, "message": message, "data": data}), http_status
- @staticmethod
- def error(message: str = "Internal Server Error", http_status: int = 500):
- return jsonify({"code": http_status, "message": message, "data": None}), http_status
|