diff --git a/backend/app/api/distribution.py b/backend/app/api/distribution.py index 4361e68..73372d0 100644 --- a/backend/app/api/distribution.py +++ b/backend/app/api/distribution.py @@ -91,6 +91,7 @@ async def validate_content(req: ContentValidateRequest): content=req.content, title=req.title, platform=req.platform, + tags=req.tags, ) return ContentValidateResponse( diff --git a/backend/app/api/platform_rules.py b/backend/app/api/platform_rules.py index dc1452a..a6af305 100644 --- a/backend/app/api/platform_rules.py +++ b/backend/app/api/platform_rules.py @@ -335,6 +335,7 @@ async def validate_content_for_platform( content=req.content, title=req.title, platform_id=platform_id, + tags=req.tags, ) issues = [ diff --git a/backend/app/schemas/distribution.py b/backend/app/schemas/distribution.py index df08c82..5f759f4 100644 --- a/backend/app/schemas/distribution.py +++ b/backend/app/schemas/distribution.py @@ -45,6 +45,7 @@ class ContentValidateRequest(BaseModel): content: str = Field(min_length=1) title: str = Field(min_length=1) platform: str + tags: list[str] | None = Field(default=None, description="内容标签列表") class ValidationIssue(BaseModel): diff --git a/backend/app/schemas/platform_rule.py b/backend/app/schemas/platform_rule.py index 9f871c3..dcb2d22 100644 --- a/backend/app/schemas/platform_rule.py +++ b/backend/app/schemas/platform_rule.py @@ -266,6 +266,7 @@ class ContentValidateRequest(BaseModel): content: str = Field(..., description="待验证内容") title: str = Field(..., description="标题") platform: str = Field(..., description="平台ID") + tags: list[str] | None = Field(default=None, description="内容标签列表") # ============================================================ diff --git a/backend/app/services/distribution/platform_rules.py b/backend/app/services/distribution/platform_rules.py index b199c78..31df2ce 100644 --- a/backend/app/services/distribution/platform_rules.py +++ b/backend/app/services/distribution/platform_rules.py @@ -942,7 +942,7 @@ class PlatformRuleEngine: "publish_rules", ] - def validate_content(self, content: str, title: str, platform: str) -> dict: + def validate_content(self, content: str, title: str, platform: str, tags: list[str] | str | None = None) -> dict: """ 校验内容是否符合平台规则 @@ -1012,7 +1012,29 @@ class PlatformRuleEngine: tag_rules = rules.get("tag_rules", {}) min_tags = tag_rules.get("min_tags", 0) max_tags = tag_rules.get("max_tags", 10) - # TODO: 需要传入标签数据进行验证 + + # 解析标签数量 + if tags is None: + tag_count = 0 + elif isinstance(tags, str): + tag_count = len([t.strip() for t in tags.split(",") if t.strip()]) + else: + tag_count = len(tags) + + if min_tags > 0 and tag_count < min_tags: + issues.append({ + "severity": "medium", + "message": f"标签数量 {tag_count} 低于最低要求 {min_tags}", + "category": "tag_count", + }) + elif max_tags > 0 and tag_count > max_tags: + issues.append({ + "severity": "high", + "message": f"标签数量 {tag_count} 超过限制 {max_tags}", + "category": "tag_count", + }) + else: + passed.append(f"标签数量合规({tag_count})") # --- AI敏感度检测 --- ai_sensitivity = rules.get("ai_sensitivity", {}) diff --git a/backend/app/services/distribution/rule_service.py b/backend/app/services/distribution/rule_service.py index 09837ee..a3aab4d 100644 --- a/backend/app/services/distribution/rule_service.py +++ b/backend/app/services/distribution/rule_service.py @@ -59,7 +59,7 @@ class PlatformRuleService: return self._engine.get_platform_rule(platform_id, rule_category) def validate_content( - self, content: str, title: str, platform_id: str + self, content: str, title: str, platform_id: str, tags: list[str] | str | None = None ) -> dict: """验证内容是否符合平台规则 @@ -67,11 +67,12 @@ class PlatformRuleService: content: 内容正文 title: 标题 platform_id: 平台标识 + tags: 内容标签列表 Returns: 验证结果 """ - return self._engine.validate_content(content, title, platform_id) + return self._engine.validate_content(content, title, platform_id, tags=tags) def detect_ai_patterns(self, content: str, platform_id: str) -> list[dict]: """检测内容中的AI写作模式 diff --git a/backend/pyproject.toml b/backend/pyproject.toml index cf5339b..b1830fe 100644 --- a/backend/pyproject.toml +++ b/backend/pyproject.toml @@ -15,3 +15,21 @@ testpaths = ["tests"] python_files = ["test_*.py"] python_classes = ["Test*"] python_functions = ["test_*"] +addopts = "--cov=app --cov-report=term-missing --cov-report=html" + +[tool.coverage.run] +omit = [ + "tests/*", + "migrations/*", + "*/__pycache__/*", + "app/conftest.py", +] + +[tool.coverage.report] +exclude_lines = [ + "pragma: no cover", + "if __name__ == .__main__.:", + "pass", + "raise NotImplementedError", + "except ImportError:", +]