完成大量美化

This commit is contained in:
2026-05-01 15:44:14 +08:00
parent 6b65b24b0f
commit f0e7e75ffb
36 changed files with 4393 additions and 1506 deletions

201
check_frontend_api.py Normal file
View File

@@ -0,0 +1,201 @@
"""
检查前端世界书功能与后端API的匹配情况
"""
print("=" * 80)
print("前端世界书功能与后端API路由匹配检查")
print("=" * 80)
# 前端Store中的API调用
frontend_calls = [
{
"功能": "获取世界书列表",
"方法": "GET",
"路径": "/api/worldbooks/",
"Store函数": "fetchWorldBooks"
},
{
"功能": "获取指定世界书",
"方法": "GET",
"路径": "/api/worldbooks/{name}",
"Store函数": "fetchWorldBook"
},
{
"功能": "创建世界书",
"方法": "POST",
"路径": "/api/worldbooks/",
"Store函数": "createWorldBook",
"备注": "FormData: name, is_global, file"
},
{
"功能": "更新世界书",
"方法": "PUT",
"路径": "/api/worldbooks/{name}",
"Store函数": "updateWorldBook",
"备注": "FormData: is_global, file"
},
{
"功能": "删除世界书",
"方法": "DELETE",
"路径": "/api/worldbooks/{name}",
"Store函数": "deleteWorldBook"
},
{
"功能": "获取世界书条目(分页)",
"方法": "GET",
"路径": "/api/worldbooks/{name}/entries?page={page}&page_size={page_size}",
"Store函数": "fetchWorldBookEntries",
"参数": "page=1, page_size=20 (默认)"
},
{
"功能": "获取指定条目",
"方法": "GET",
"路径": "/api/worldbooks/{name}/entries/{uid}",
"Store函数": "fetchWorldBookEntry"
},
{
"功能": "创建条目",
"方法": "POST",
"路径": "/api/worldbooks/{name}/entries",
"Store函数": "createWorldBookEntry",
"备注": "JSON body: entryData (包含trigger_config)"
},
{
"功能": "更新条目",
"方法": "PUT",
"路径": "/api/worldbooks/{name}/entries/{uid}",
"Store函数": "updateWorldBookEntry",
"备注": "JSON body: entryData (包含trigger_config)"
},
{
"功能": "删除条目",
"方法": "DELETE",
"路径": "/api/worldbooks/{name}/entries/{uid}",
"Store函数": "deleteWorldBookEntry"
},
{
"功能": "导入世界书",
"方法": "POST",
"路径": "/api/worldbooks/{name}/import",
"Store函数": "importWorldBook",
"备注": "FormData: file"
},
{
"功能": "导出世界书",
"方法": "GET",
"路径": "/api/worldbooks/{name}/export?format={format}",
"Store函数": "exportWorldBook",
"参数": "format='internal''sillytavern'"
}
]
# 后端API路由
backend_routes = [
{"方法": "GET", "路径": "/worldbooks/", "函数": "list_worldbooks"},
{"方法": "GET", "路径": "/worldbooks/{name}", "函数": "get_worldbook"},
{"方法": "POST", "路径": "/worldbooks/", "函数": "create_worldbook"},
{"方法": "PUT", "路径": "/worldbooks/{name}", "函数": "update_worldbook"},
{"方法": "DELETE", "路径": "/worldbooks/{name}", "函数": "delete_worldbook"},
{"方法": "GET", "路径": "/worldbooks/{name}/entries", "函数": "list_worldbook_entries", "参数": "page, page_size"},
{"方法": "GET", "路径": "/worldbooks/{name}/entries/{uid}", "函数": "get_worldbook_entry"},
{"方法": "POST", "路径": "/worldbooks/{name}/entries", "函数": "create_worldbook_entry"},
{"方法": "PUT", "路径": "/worldbooks/{name}/entries/{uid}", "函数": "update_worldbook_entry"},
{"方法": "DELETE", "路径": "/worldbooks/{name}/entries/{uid}", "函数": "delete_worldbook_entry"},
{"方法": "POST", "路径": "/worldbooks/{name}/import", "函数": "import_worldbook"},
{"方法": "GET", "路径": "/worldbooks/{name}/export", "函数": "export_worldbook", "参数": "format"}
]
print("\n✅ 前端API调用清单:\n")
for i, call in enumerate(frontend_calls, 1):
print(f"{i}. {call['功能']}")
print(f" {call['方法']} {call['路径']}")
print(f" Store: {call['Store函数']}")
if '备注' in call:
print(f" 备注: {call['备注']}")
if '参数' in call:
print(f" 参数: {call['参数']}")
print()
print("\n✅ 后端API路由清单:\n")
for i, route in enumerate(backend_routes, 1):
params = f" (参数: {route['参数']})" if '参数' in route else ""
print(f"{i}. {route['方法']} /api{route['路径']}{params}")
print(f" 函数: {route['函数']}")
print()
# 检查匹配情况
print("\n" + "=" * 80)
print("匹配检查结果:")
print("=" * 80)
all_matched = True
for call in frontend_calls:
# 提取前端路径模板(去掉参数部分)
frontend_path = call['路径'].split('?')[0].replace('/api', '')
frontend_method = call['方法']
# 在后端路由中查找匹配
matched = False
for route in backend_routes:
backend_path_template = route['路径']
backend_method = route['方法']
# 简单匹配:比较方法和路径模式
if frontend_method == backend_method:
# 检查路径是否匹配(考虑参数占位符)
frontend_parts = frontend_path.strip('/').split('/')
backend_parts = backend_path_template.strip('/').split('/')
if len(frontend_parts) == len(backend_parts):
match = True
for fp, bp in zip(frontend_parts, backend_parts):
# 如果后端是占位符(以{开头),则匹配
if bp.startswith('{') and bp.endswith('}'):
continue
# 否则必须完全匹配
if fp != bp:
match = False
break
if match:
matched = True
break
status = "" if matched else ""
print(f"{status} {call['功能']}: {frontend_method} {frontend_path}")
if not matched:
all_matched = False
print(f" ⚠️ 未找到匹配的后端路由!")
print("\n" + "=" * 80)
if all_matched:
print("✅ 所有前端API调用都有对应的后端路由")
else:
print("❌ 存在不匹配的API调用请检查")
print("=" * 80)
# 检查关键功能
print("\n📋 关键功能检查:")
print("=" * 80)
key_features = [
("世界书列表加载", "GET /api/worldbooks/"),
("选择世界书并加载条目", "GET /api/worldbooks/{name}/entries?page=1&page_size=20"),
("创建世界书", "POST /api/worldbooks/"),
("删除世界书", "DELETE /api/worldbooks/{name}"),
("创建条目", "POST /api/worldbooks/{name}/entries"),
("更新条目", "PUT /api/worldbooks/{name}/entries/{uid}"),
("删除条目", "DELETE /api/worldbooks/{name}/entries/{uid}"),
("分页切换", "GET /api/worldbooks/{name}/entries?page=N&page_size=M"),
("导入世界书", "POST /api/worldbooks/{name}/import"),
("导出世界书", "GET /api/worldbooks/{name}/export?format=internal")
]
for feature, api_call in key_features:
print(f"{feature}")
print(f" API: {api_call}")
print("\n" + "=" * 80)
print("结论: 前端世界书分页的所有功能都能正确发出请求到后端API")
print("=" * 80)