46 lines
1.5 KiB
Python
46 lines
1.5 KiB
Python
"""API服务相关路由 - 支持 Nano Banana API 代理"""
|
|
from flask import Blueprint, request, jsonify, current_app
|
|
from flask_jwt_extended import jwt_required, get_jwt_identity
|
|
from services.api_proxy_service import ApiProxyService
|
|
|
|
api_bp = Blueprint('api_service', __name__)
|
|
|
|
@api_bp.route('/text-to-image', methods=['POST'])
|
|
@jwt_required()
|
|
def text_to_image():
|
|
"""
|
|
通用 API 代理 (支持文生图和对话)
|
|
"""
|
|
current_user_id = get_jwt_identity()
|
|
data = request.get_json()
|
|
|
|
result, status_code = ApiProxyService.handle_api_request(current_user_id, data)
|
|
|
|
if status_code == 200 and data.get('stream', False):
|
|
return current_app.response_class(result, mimetype='text/event-stream')
|
|
|
|
return jsonify(result), status_code
|
|
|
|
@api_bp.route('/models', methods=['GET'])
|
|
@jwt_required()
|
|
def get_models():
|
|
"""
|
|
获取可用的模型列表
|
|
"""
|
|
result, status_code = ApiProxyService.get_models()
|
|
return jsonify(result), status_code
|
|
|
|
@api_bp.route('/pricing', methods=['GET'])
|
|
def get_pricing():
|
|
"""获取价格信息(公开接口)"""
|
|
result, status_code = ApiProxyService.get_pricing()
|
|
return jsonify(result), status_code
|
|
|
|
@api_bp.route('/call/<int:call_id>', methods=['GET'])
|
|
@jwt_required()
|
|
def get_api_call(call_id):
|
|
"""获取API调用详情"""
|
|
current_user_id = get_jwt_identity()
|
|
result, status_code = ApiProxyService.get_api_call(current_user_id, call_id)
|
|
return jsonify(result), status_code
|