All checks were successful
Test / test (push) Successful in 1m45s
- Migrate SQLModel base classes, mixins, and database management to external sqlmodel-ext package; remove sqlmodels/base/, sqlmodels/mixin/, and sqlmodels/database.py - Add file viewer/editor system with WOPI protocol support for collaborative editing (OnlyOffice, Collabora) - Add enterprise edition license verification module (ee/) - Add Dockerfile multi-stage build with Cython compilation support - Add new dependencies: sqlmodel-ext, cryptography, whatthepatch Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
70 lines
1.6 KiB
Python
70 lines
1.6 KiB
Python
"""
|
||
Pro 版本状态端点
|
||
|
||
提供许可证状态查询,需管理员权限。
|
||
"""
|
||
from datetime import datetime
|
||
|
||
from fastapi import APIRouter, Depends
|
||
|
||
from ee.service import LicensePayload
|
||
from ee.service.license_service import get_cached_license
|
||
from middleware.auth import admin_required
|
||
from sqlmodel_ext import SQLModelBase
|
||
|
||
router = APIRouter(prefix="/pro")
|
||
|
||
|
||
class ProStatusResponse(SQLModelBase):
|
||
"""Pro 版本状态响应"""
|
||
|
||
is_active: bool
|
||
"""许可证是否有效"""
|
||
|
||
domain: str
|
||
"""授权域名"""
|
||
|
||
expires_at: datetime
|
||
"""过期时间"""
|
||
|
||
max_users: int
|
||
"""最大用户数(0 = 无限制)"""
|
||
|
||
features: list[str]
|
||
"""已授权的功能列表"""
|
||
|
||
|
||
@router.get(
|
||
'/status',
|
||
dependencies=[Depends(admin_required)],
|
||
)
|
||
async def get_pro_status() -> ProStatusResponse:
|
||
"""
|
||
查询 Pro 版本许可证状态
|
||
|
||
认证:
|
||
- JWT token in Authorization header
|
||
- 需要管理员权限
|
||
|
||
响应:
|
||
- ProStatusResponse: 当前许可证信息
|
||
|
||
错误处理:
|
||
- HTTPException 401: 未授权
|
||
- HTTPException 403: 非管理员
|
||
- HTTPException 500: 许可证缓存异常
|
||
"""
|
||
payload: LicensePayload | None = get_cached_license()
|
||
if not payload:
|
||
# init_ee 成功后 payload 一定存在,此处做防御性编程
|
||
from utils.http.http_exceptions import raise_internal_error
|
||
raise_internal_error()
|
||
|
||
return ProStatusResponse(
|
||
is_active=True,
|
||
domain=payload.domain,
|
||
expires_at=payload.expires_at,
|
||
max_users=payload.max_users,
|
||
features=payload.features,
|
||
)
|