fix
This commit is contained in:
parent
f7e72162ad
commit
a3fa6cbb9c
|
|
@ -12,6 +12,7 @@ from datetime import datetime
|
|||
|
||||
from python_core.config import settings
|
||||
from python_core.utils.logger import logger
|
||||
from python_core.utils.jsonrpc import create_response_handler
|
||||
|
||||
|
||||
@dataclass
|
||||
|
|
@ -202,12 +203,15 @@ resource_category_manager = ResourceCategoryManager()
|
|||
|
||||
|
||||
def main():
|
||||
"""命令行接口"""
|
||||
"""命令行接口 - 使用JSON-RPC协议"""
|
||||
import sys
|
||||
import json
|
||||
|
||||
# 创建响应处理器
|
||||
rpc = create_response_handler()
|
||||
|
||||
if len(sys.argv) < 2:
|
||||
print(json.dumps({"status": False, "msg": "No command specified"}))
|
||||
rpc.error("INVALID_REQUEST", "No command specified")
|
||||
return
|
||||
|
||||
command = sys.argv[1]
|
||||
|
|
@ -215,30 +219,30 @@ def main():
|
|||
try:
|
||||
if command == "get_all_categories":
|
||||
categories = resource_category_manager.get_all_categories()
|
||||
print(json.dumps({"status": True, "data": categories}))
|
||||
rpc.success(categories)
|
||||
|
||||
elif command == "get_category_by_id":
|
||||
if len(sys.argv) < 3:
|
||||
print(json.dumps({"status": False, "msg": "Category ID required"}))
|
||||
rpc.error("INVALID_REQUEST", "Category ID required")
|
||||
return
|
||||
category_id = sys.argv[2]
|
||||
category = resource_category_manager.get_category_by_id(category_id)
|
||||
if category:
|
||||
print(json.dumps({"status": True, "data": category}))
|
||||
rpc.success(category)
|
||||
else:
|
||||
print(json.dumps({"status": False, "msg": "Category not found"}))
|
||||
rpc.error("NOT_FOUND", "Category not found")
|
||||
|
||||
elif command == "create_category":
|
||||
if len(sys.argv) < 5:
|
||||
print(json.dumps({"status": False, "msg": "Title, prompt and color required"}))
|
||||
rpc.error("INVALID_REQUEST", "Title, prompt and color required")
|
||||
return
|
||||
title, ai_prompt, color = sys.argv[2], sys.argv[3], sys.argv[4]
|
||||
result = resource_category_manager.create_category(title, ai_prompt, color)
|
||||
print(json.dumps({"status": True, "data": result}))
|
||||
rpc.success(result)
|
||||
|
||||
elif command == "update_category":
|
||||
if len(sys.argv) < 4:
|
||||
print(json.dumps({"status": False, "msg": "Category ID and update data required"}))
|
||||
rpc.error("INVALID_REQUEST", "Category ID and update data required")
|
||||
return
|
||||
category_id = sys.argv[2]
|
||||
update_data = json.loads(sys.argv[3])
|
||||
|
|
@ -249,32 +253,32 @@ def main():
|
|||
update_data.get('color')
|
||||
)
|
||||
if result:
|
||||
print(json.dumps({"status": True, "data": result}))
|
||||
rpc.success(result)
|
||||
else:
|
||||
print(json.dumps({"status": False, "msg": "Category not found"}))
|
||||
rpc.error("NOT_FOUND", "Category not found")
|
||||
|
||||
elif command == "delete_category":
|
||||
if len(sys.argv) < 3:
|
||||
print(json.dumps({"status": False, "msg": "Category ID required"}))
|
||||
rpc.error("INVALID_REQUEST", "Category ID required")
|
||||
return
|
||||
category_id = sys.argv[2]
|
||||
success = resource_category_manager.delete_category(category_id)
|
||||
print(json.dumps({"status": True, "data": success}))
|
||||
rpc.success(success)
|
||||
|
||||
elif command == "search_categories":
|
||||
if len(sys.argv) < 3:
|
||||
print(json.dumps({"status": False, "msg": "Search keyword required"}))
|
||||
rpc.error("INVALID_REQUEST", "Search keyword required")
|
||||
return
|
||||
keyword = sys.argv[2]
|
||||
results = resource_category_manager.search_categories(keyword)
|
||||
print(json.dumps({"status": True, "data": results}))
|
||||
rpc.success(results)
|
||||
|
||||
else:
|
||||
print(json.dumps({"status": False, "msg": f"Unknown command: {command}"}))
|
||||
rpc.error("INVALID_REQUEST", f"Unknown command: {command}")
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f"Command execution failed: {e}")
|
||||
print(json.dumps({"status": False, "msg": str(e)}))
|
||||
rpc.error("INTERNAL_ERROR", str(e))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
|
|
|||
Loading…
Reference in New Issue