From 8ae18381caf8a1d7f0cdf31dd32b96e91d466115 Mon Sep 17 00:00:00 2001 From: YokiiroBW Date: Sun, 5 Jul 2026 17:24:35 +0800 Subject: [PATCH] feat: add API compatibility aliases --- backend/route_registry.py | 10 ++++++++++ backend/routes/material_routes.py | 14 ++++++++++++++ backend/routes/profile_routes.py | 8 ++++++++ backend/services/material_service.py | 11 +++++++++-- tests/test_material_service.py | 9 +++++++++ tests/test_route_registry.py | 5 +++++ tests/test_s2_routes.py | 6 ++++++ 7 files changed, 61 insertions(+), 2 deletions(-) diff --git a/backend/route_registry.py b/backend/route_registry.py index c3ed164..a78dc24 100644 --- a/backend/route_registry.py +++ b/backend/route_registry.py @@ -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"), diff --git a/backend/routes/material_routes.py b/backend/routes/material_routes.py index 18512e6..5316300 100644 --- a/backend/routes/material_routes.py +++ b/backend/routes/material_routes.py @@ -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, diff --git a/backend/routes/profile_routes.py b/backend/routes/profile_routes.py index 1c8ac38..f0905d3 100644 --- a/backend/routes/profile_routes.py +++ b/backend/routes/profile_routes.py @@ -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], diff --git a/backend/services/material_service.py b/backend/services/material_service.py index 7519362..1b89108 100644 --- a/backend/services/material_service.py +++ b/backend/services/material_service.py @@ -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(), ) diff --git a/tests/test_material_service.py b/tests/test_material_service.py index 442d690..a8b3024 100644 --- a/tests/test_material_service.py +++ b/tests/test_material_service.py @@ -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() diff --git a/tests/test_route_registry.py b/tests/test_route_registry.py index 2183356..d81912d 100644 --- a/tests/test_route_registry.py +++ b/tests/test_route_registry.py @@ -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) diff --git a/tests/test_s2_routes.py b/tests/test_s2_routes.py index 8ab8f91..fd7322c 100644 --- a/tests/test_s2_routes.py +++ b/tests/test_s2_routes.py @@ -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")