refactor(userpage): move APIs into g0v0 private API

This commit is contained in:
MingxuanGame
2025-10-04 04:57:24 +00:00
parent 2bfde24b84
commit 7c18fc5fb6
8 changed files with 186 additions and 206 deletions

View File

@@ -54,3 +54,47 @@ class ValidateBBCodeResponse(BaseModel):
valid: bool = Field(description="BBCode是否有效")
errors: list[str] = Field(default_factory=list, description="错误列表")
preview: dict[str, str] = Field(description="预览内容")
class UserpageError(Exception):
"""用户页面处理错误基类"""
def __init__(self, message: str, code: str = "userpage_error"):
self.message = message
self.code = code
super().__init__(message)
class ContentTooLongError(UserpageError):
"""内容过长错误"""
def __init__(self, current_length: int, max_length: int):
message = f"Content too long. Maximum {max_length} characters allowed, got {current_length}."
super().__init__(message, "content_too_long")
self.current_length = current_length
self.max_length = max_length
class ContentEmptyError(UserpageError):
"""内容为空错误"""
def __init__(self):
super().__init__("Content cannot be empty.", "content_empty")
class BBCodeValidationError(UserpageError):
"""BBCode验证错误"""
def __init__(self, errors: list[str]):
message = f"BBCode validation failed: {'; '.join(errors)}"
super().__init__(message, "bbcode_validation_error")
self.errors = errors
class ForbiddenTagError(UserpageError):
"""禁止标签错误"""
def __init__(self, tag: str):
message = f"Forbidden tag '{tag}' is not allowed."
super().__init__(message, "forbidden_tag")
self.tag = tag