feat: add API compatibility aliases
这个提交存在于:
父节点
a615802ec2
当前提交
8ae18381ca
共有 7 个文件被更改,包括 61 次插入 和 2 次删除
|
|
@ -32,6 +32,7 @@ ROUTES: tuple[RouteSpec, ...] = (
|
|||
RouteSpec("GET", "profiles/{profile_id}", "backend.routes.profile_routes.get_profile", "read"),
|
||||
RouteSpec("PUT", "profiles/{profile_id}", "backend.routes.profile_routes.update_profile", "write"),
|
||||
RouteSpec("DELETE", "profiles/{profile_id}", "backend.routes.profile_routes.delete_profile", "write"),
|
||||
RouteSpec("POST", "profiles/{profile_id}/archive", "backend.routes.profile_routes.archive_profile", "write"),
|
||||
RouteSpec("GET", "profiles/{profile_id}/workflows", "backend.routes.workflow_routes.list_profile_workflows", "read"),
|
||||
RouteSpec("POST", "profiles/{profile_id}/workflows", "backend.routes.workflow_routes.create_profile_workflow", "write"),
|
||||
RouteSpec("GET", "workflows/{workflow_id}", "backend.routes.workflow_routes.get_workflow", "read"),
|
||||
|
|
@ -50,6 +51,7 @@ ROUTES: tuple[RouteSpec, ...] = (
|
|||
RouteSpec("POST", "nodes/{node_id}/generate", "backend.routes.node_routes.generate_node", "write"),
|
||||
RouteSpec("POST", "nodes/{node_id}/retry", "backend.routes.node_routes.retry_node", "write"),
|
||||
RouteSpec("POST", "nodes/{node_id}/complete", "backend.routes.node_routes.mark_node_completed", "write"),
|
||||
RouteSpec("POST", "nodes/{node_id}/mark-completed", "backend.routes.node_routes.mark_node_completed", "write"),
|
||||
RouteSpec("POST", "nodes/{node_id}/select-image", "backend.routes.node_routes.select_node_image", "write"),
|
||||
RouteSpec("POST", "nodes/{node_id}/adopt-image", "backend.routes.history_routes.adopt_node_image", "write"),
|
||||
RouteSpec("GET", "nodes/{node_id}/review", "backend.routes.review_routes.review_node", "read"),
|
||||
|
|
@ -101,15 +103,23 @@ ROUTES: tuple[RouteSpec, ...] = (
|
|||
RouteSpec("PUT", "materials/{material_id}", "backend.routes.material_routes.update_material", "materials"),
|
||||
RouteSpec("DELETE", "materials/{material_id}", "backend.routes.material_routes.delete_material", "materials"),
|
||||
RouteSpec("POST", "materials/{material_id}/recognize", "backend.routes.material_routes.recognize_material", "materials"),
|
||||
RouteSpec("POST", "materials/{material_id}/re-recognize", "backend.routes.material_routes.re_recognize_material", "materials"),
|
||||
RouteSpec("POST", "materials/{material_id}/confirm", "backend.routes.material_routes.confirm_material", "materials"),
|
||||
RouteSpec("GET", "profiles/{profile_id}/wardrobe", "backend.routes.wardrobe_routes.list_wardrobe_items", "read"),
|
||||
RouteSpec("POST", "profiles/{profile_id}/wardrobe/import-material", "backend.routes.wardrobe_routes.import_wardrobe_material", "materials"),
|
||||
RouteSpec("POST", "profiles/{profile_id}/wardrobe/items", "backend.routes.wardrobe_routes.import_wardrobe_material", "materials"),
|
||||
RouteSpec(
|
||||
"DELETE",
|
||||
"profiles/{profile_id}/wardrobe/{wardrobe_item_id}",
|
||||
"backend.routes.wardrobe_routes.delete_wardrobe_item",
|
||||
"materials",
|
||||
),
|
||||
RouteSpec(
|
||||
"DELETE",
|
||||
"profiles/{profile_id}/wardrobe/items/{wardrobe_item_id}",
|
||||
"backend.routes.wardrobe_routes.delete_wardrobe_item",
|
||||
"materials",
|
||||
),
|
||||
RouteSpec("POST", "profiles/{profile_id}/wardrobe/match", "backend.routes.wardrobe_routes.match_wardrobe", "read"),
|
||||
RouteSpec("POST", "integrations/private-companion/daily-outfit", "backend.routes.integration_routes.private_companion_daily_outfit", "read"),
|
||||
RouteSpec("GET", "integrations/logs", "backend.routes.integration_routes.list_integration_logs", "read"),
|
||||
|
|
|
|||
|
|
@ -174,6 +174,20 @@ def recognize_material(
|
|||
return handle_request(ctx, action)
|
||||
|
||||
|
||||
def re_recognize_material(
|
||||
ctx: RequestContext,
|
||||
material_id: str,
|
||||
service: MaterialService | None = None,
|
||||
) -> dict:
|
||||
material_service = service or _create_material_service()
|
||||
|
||||
def action() -> dict[str, Any]:
|
||||
require_permission(ctx, "can_manage_materials")
|
||||
return material_service.re_recognize_material(material_id, ctx).to_dict()
|
||||
|
||||
return handle_request(ctx, action)
|
||||
|
||||
|
||||
def confirm_material(
|
||||
ctx: RequestContext,
|
||||
material_id: str,
|
||||
|
|
|
|||
|
|
@ -93,6 +93,14 @@ def delete_profile(
|
|||
return handle_request(ctx, action)
|
||||
|
||||
|
||||
def archive_profile(
|
||||
ctx: RequestContext,
|
||||
profile_id: str,
|
||||
service: ProfileService | None = None,
|
||||
) -> dict:
|
||||
return delete_profile(ctx, profile_id, service)
|
||||
|
||||
|
||||
def create_quick_profile_draft(
|
||||
ctx: RequestContext,
|
||||
payload: dict[str, Any],
|
||||
|
|
|
|||
|
|
@ -199,10 +199,17 @@ class MaterialService:
|
|||
material = self.get_material(material_id)
|
||||
if material.recognition_status == "confirmed":
|
||||
return material
|
||||
return self._recognize_material(material, ctx)
|
||||
|
||||
def re_recognize_material(self, material_id: str, ctx: RequestContext) -> Material:
|
||||
material = self.get_material(material_id)
|
||||
return self._recognize_material(material, ctx)
|
||||
|
||||
def _recognize_material(self, material: Material, ctx: RequestContext) -> Material:
|
||||
generated_tags = _mock_tags(material)
|
||||
prompt = material.prompt or _mock_prompt(material)
|
||||
after = self.update_material(
|
||||
material_id,
|
||||
material.material_id,
|
||||
{
|
||||
"prompt": prompt,
|
||||
"negative_prompt": material.negative_prompt or "body, face, background, watermark",
|
||||
|
|
@ -216,7 +223,7 @@ class MaterialService:
|
|||
ctx=ctx,
|
||||
action="recognize_material",
|
||||
target_type="material",
|
||||
target_id=material_id,
|
||||
target_id=material.material_id,
|
||||
before_snapshot=material.to_dict(),
|
||||
after_snapshot=after.to_dict(),
|
||||
)
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@ from backend.routes.material_routes import (
|
|||
get_material,
|
||||
list_material_categories,
|
||||
list_materials,
|
||||
re_recognize_material,
|
||||
recognize_material,
|
||||
update_material,
|
||||
upload_material,
|
||||
|
|
@ -122,6 +123,10 @@ class MaterialServiceTests(unittest.TestCase):
|
|||
self.assertEqual(confirmed.recognition_status, "confirmed")
|
||||
self.assertEqual(confirmed.tags, ["upper", "white", "summer"])
|
||||
|
||||
re_recognized = self.material_service.re_recognize_material(uploaded.material_id, self.ctx)
|
||||
self.assertEqual(re_recognized.recognition_status, "pending_confirm")
|
||||
self.assertIn("white", re_recognized.tags)
|
||||
|
||||
def test_material_routes_wrap_responses_and_require_permission(self):
|
||||
category = create_material_category(self.ctx, {"name": "Accessory"}, self.material_service)
|
||||
self.assertTrue(category["ok"])
|
||||
|
|
@ -194,6 +199,10 @@ class MaterialServiceTests(unittest.TestCase):
|
|||
self.assertTrue(confirmed["ok"])
|
||||
self.assertEqual(confirmed["data"]["recognition_status"], "confirmed")
|
||||
|
||||
re_recognized = re_recognize_material(self.ctx, material_id, self.material_service)
|
||||
self.assertTrue(re_recognized["ok"])
|
||||
self.assertEqual(re_recognized["data"]["recognition_status"], "pending_confirm")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@ class RouteRegistryTests(unittest.TestCase):
|
|||
self.assertIn(("PUT", "material-categories/{category_id}"), keys)
|
||||
self.assertIn(("GET", "materials/{material_id}"), keys)
|
||||
self.assertIn(("DELETE", "profiles/{profile_id}/wardrobe/{wardrobe_item_id}"), keys)
|
||||
self.assertIn(("DELETE", "profiles/{profile_id}/wardrobe/items/{wardrobe_item_id}"), keys)
|
||||
self.assertIn(("GET", "integrations/logs"), keys)
|
||||
self.assertIn(("POST", "workflows/{workflow_id}/start"), keys)
|
||||
self.assertIn(("POST", "workflows/{workflow_id}/cancel"), keys)
|
||||
|
|
@ -28,6 +29,10 @@ class RouteRegistryTests(unittest.TestCase):
|
|||
self.assertIn(("GET", "workflows/{workflow_id}/review"), keys)
|
||||
self.assertIn(("POST", "nodes/{node_id}/retry"), keys)
|
||||
self.assertIn(("POST", "nodes/{node_id}/complete"), keys)
|
||||
self.assertIn(("POST", "nodes/{node_id}/mark-completed"), keys)
|
||||
self.assertIn(("POST", "materials/{material_id}/re-recognize"), keys)
|
||||
self.assertIn(("POST", "profiles/{profile_id}/archive"), keys)
|
||||
self.assertIn(("POST", "profiles/{profile_id}/wardrobe/items"), keys)
|
||||
self.assertIn(("GET", "settings/snapshots"), keys)
|
||||
self.assertIn(("GET", "settings/snapshots/{snapshot_id}"), keys)
|
||||
self.assertIn(("POST", "settings/rollback"), keys)
|
||||
|
|
|
|||
|
|
@ -30,6 +30,7 @@ from backend.routes.node_routes import (
|
|||
update_node,
|
||||
)
|
||||
from backend.routes.profile_routes import (
|
||||
archive_profile,
|
||||
create_profile,
|
||||
create_quick_profile_draft,
|
||||
delete_profile,
|
||||
|
|
@ -297,6 +298,11 @@ storage:
|
|||
self.assertFalse(missing["ok"])
|
||||
self.assertEqual(missing["error_code"], "RESOURCE_NOT_FOUND")
|
||||
|
||||
archive_target = create_profile(self.ctx, {"name": "Archive Target"}, self.profile_service)
|
||||
archived = archive_profile(self.ctx, archive_target["data"]["profile_id"], self.profile_service)
|
||||
self.assertTrue(archived["ok"])
|
||||
self.assertEqual(archived["data"]["status"], "deleted")
|
||||
|
||||
def test_profile_write_routes_require_write_permission(self):
|
||||
read_only = RequestContext.from_astrbot(username="viewer", user_id="viewer_001")
|
||||
|
||||
|
|
|
|||
正在加载…
添加表格
在新工单中引用