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