This commit is contained in:
root 2025-07-12 21:17:36 +08:00
parent cc33875d16
commit 3927c4ffb7
3 changed files with 29 additions and 20 deletions

View File

@ -26,7 +26,7 @@ def register_user(
password: Optional[str] = typer.Option(None, "--password", "-p", help="密码(不提供则交互式输入)") password: Optional[str] = typer.Option(None, "--password", "-p", help="密码(不提供则交互式输入)")
): ):
"""注册新用户""" """注册新用户"""
response = create_response_handler(str(uuid4())) response = create_response_handler()
try: try:
# 获取密码 # 获取密码
if not password: if not password:
@ -52,7 +52,7 @@ def login_user(
password: Optional[str] = typer.Option(None, "--password", "-p", help="密码(不提供则交互式输入)") password: Optional[str] = typer.Option(None, "--password", "-p", help="密码(不提供则交互式输入)")
): ):
"""用户登录""" """用户登录"""
response = create_response_handler(str(uuid4())) response = create_response_handler()
try: try:
# 获取密码 # 获取密码
if not password: if not password:
@ -75,7 +75,7 @@ def verify_token(
token: str = typer.Argument(..., help="JWT token"), token: str = typer.Argument(..., help="JWT token"),
): ):
"""验证JWT token""" """验证JWT token"""
response = create_response_handler(str(uuid4())) response = create_response_handler()
try: try:
# 验证token # 验证token
result = auth_api.verify_token({ result = auth_api.verify_token({
@ -92,7 +92,7 @@ def list_users(
include_inactive: bool = typer.Option(False, "--include-inactive", "-i", help="包含非活跃用户"), include_inactive: bool = typer.Option(False, "--include-inactive", "-i", help="包含非活跃用户"),
): ):
"""列出所有用户""" """列出所有用户"""
response = create_response_handler(str(uuid4())) response = create_response_handler()
try: try:
# 获取用户列表 # 获取用户列表
users = user_table.get_all_users(include_inactive) users = user_table.get_all_users(include_inactive)
@ -105,7 +105,7 @@ def list_users(
@auth_app.command("stats") @auth_app.command("stats")
def show_stats(): def show_stats():
"""显示用户统计信息""" """显示用户统计信息"""
response = create_response_handler(str(uuid4())) response = create_response_handler()
try: try:
# 获取统计信息 # 获取统计信息
stats = user_table.get_user_count() stats = user_table.get_user_count()

View File

@ -22,7 +22,7 @@ def batch_import(
json_output: bool = typer.Option(True, "--json", help="JSON格式输出") json_output: bool = typer.Option(True, "--json", help="JSON格式输出")
): ):
"""批量导入模板""" """批量导入模板"""
response = create_progress_reporter(str(uuid4())) response = create_progress_reporter()
try: try:
# 验证源文件夹 # 验证源文件夹
source_path = Path(source_folder) source_path = Path(source_folder)
@ -69,7 +69,7 @@ def list_templates(
json_output: bool = typer.Option(True, "--json", help="JSON格式输出") json_output: bool = typer.Option(True, "--json", help="JSON格式输出")
): ):
"""列出所有模板""" """列出所有模板"""
response = create_response_handler(str(uuid4())) response = create_response_handler()
try: try:
# 创建模板管理器 # 创建模板管理器
manager = TemplateManagerCloud(user_id=user_id or "default") manager = TemplateManagerCloud(user_id=user_id or "default")
@ -107,7 +107,7 @@ def get_template(
json_output: bool = typer.Option(True, "--json", help="JSON格式输出") json_output: bool = typer.Option(True, "--json", help="JSON格式输出")
): ):
"""获取模板详情""" """获取模板详情"""
response = create_response_handler(str(uuid4())) response = create_response_handler()
try: try:
# 创建模板管理器 # 创建模板管理器
manager = TemplateManagerCloud(user_id=user_id or "default") manager = TemplateManagerCloud(user_id=user_id or "default")
@ -140,7 +140,7 @@ def delete_template(
json_output: bool = typer.Option(True, "--json", help="JSON格式输出") json_output: bool = typer.Option(True, "--json", help="JSON格式输出")
): ):
"""删除模板""" """删除模板"""
response = create_response_handler(str(uuid4())) response = create_response_handler()
try: try:
# 创建模板管理器 # 创建模板管理器
manager = TemplateManagerCloud(user_id=user_id or "default") manager = TemplateManagerCloud(user_id=user_id or "default")
@ -177,7 +177,7 @@ def search_templates(
json_output: bool = typer.Option(True, "--json", help="JSON格式输出") json_output: bool = typer.Option(True, "--json", help="JSON格式输出")
): ):
"""搜索模板""" """搜索模板"""
response = create_response_handler(str(uuid4())) response = create_response_handler()
try: try:
# 创建模板管理器 # 创建模板管理器
manager = TemplateManagerCloud(user_id=user_id or "default") manager = TemplateManagerCloud(user_id=user_id or "default")
@ -211,7 +211,7 @@ def get_template_stats(
json_output: bool = typer.Option(True, "--json", help="JSON格式输出") json_output: bool = typer.Option(True, "--json", help="JSON格式输出")
): ):
"""获取模板统计信息""" """获取模板统计信息"""
response = create_response_handler(str(uuid4())) response = create_response_handler()
try: try:
# 创建模板管理器 # 创建模板管理器
manager = TemplateManagerCloud(user_id=user_id or "default") manager = TemplateManagerCloud(user_id=user_id or "default")
@ -250,7 +250,7 @@ def get_popular_tags(
json_output: bool = typer.Option(True, "--json", help="JSON格式输出") json_output: bool = typer.Option(True, "--json", help="JSON格式输出")
): ):
"""获取热门标签""" """获取热门标签"""
response = create_response_handler(str(uuid4())) response = create_response_handler()
try: try:
# 创建模板管理器 # 创建模板管理器
manager = TemplateManagerCloud(user_id=user_id or "default") manager = TemplateManagerCloud(user_id=user_id or "default")
@ -278,7 +278,7 @@ def get_templates_by_tag(
json_output: bool = typer.Option(True, "--json", help="JSON格式输出") json_output: bool = typer.Option(True, "--json", help="JSON格式输出")
): ):
"""根据标签获取模板""" """根据标签获取模板"""
response = create_response_handler(str(uuid4())) response = create_response_handler()
try: try:
# 创建模板管理器 # 创建模板管理器
manager = TemplateManagerCloud(user_id=user_id or "default") manager = TemplateManagerCloud(user_id=user_id or "default")

View File

@ -96,8 +96,8 @@ class EnhancedJSONRPCResponse:
class EnhancedProgressReporter: class EnhancedProgressReporter:
"""增强版进度报告器""" """增强版进度报告器"""
def __init__(self, total: int = 0): def __init__(self, response_id: str, total: int = 0):
self.response = EnhancedJSONRPCResponse() self.response = EnhancedJSONRPCResponse(response_id)
self.step = 0 self.step = 0
self.total = total self.total = total
@ -131,6 +131,15 @@ class EnhancedProgressReporter:
"""调试消息""" """调试消息"""
self.response.progress("debug", -1, message, ProgressLevel.DEBUG, data) self.response.progress("debug", -1, message, ProgressLevel.DEBUG, data)
def progress(self, current: int, total: int, message: str, data: Optional[Dict[str, Any]] = None) -> None:
"""进度报告 - 兼容旧版本API"""
if total > 0:
progress_percentage = int((current / total) * 100)
else:
progress_percentage = -1
self.response.progress("progress", progress_percentage, message, ProgressLevel.INFO, data)
class JSONRPCMethodRegistry: class JSONRPCMethodRegistry:
"""JSON-RPC 方法注册器""" """JSON-RPC 方法注册器"""
@ -225,14 +234,14 @@ method_registry = JSONRPCMethodRegistry()
# 便捷函数 # 便捷函数
def create_response_handler(request_id: Optional[Union[str, int]] = None) -> EnhancedJSONRPCResponse: def create_response_handler() -> EnhancedJSONRPCResponse:
"""创建响应处理器""" """创建响应处理器"""
return EnhancedJSONRPCResponse(request_id) return EnhancedJSONRPCResponse(uuid4())
from uuid import uuid4
def create_progress_reporter(total: int = 0) -> EnhancedProgressReporter: def create_progress_reporter(total: int = 100) -> EnhancedProgressReporter:
"""创建进度报告器""" """创建进度报告器"""
return EnhancedProgressReporter(total) return EnhancedProgressReporter(uuid4(), total)
def register_method(name: Optional[str] = None): def register_method(name: Optional[str] = None):