Document test9 tag 2026-11-02 for upload; POST config pull + WS, fixed dark home, no debug bar. Co-authored-by: Cursor <cursoragent@cursor.com>
46 lines
1.4 KiB
Python
46 lines
1.4 KiB
Python
"""微信后台 · 游民社区运营开关 admin.nomadro.cn/wechat/social"""
|
|
from __future__ import annotations
|
|
|
|
from typing import Any
|
|
|
|
from fastapi import APIRouter, Depends
|
|
from pydantic import BaseModel, Field
|
|
|
|
from ebook_svc.core.security import require_admin
|
|
from ebook_svc.services.social_ops import read_social_ops, write_social_ops
|
|
|
|
router = APIRouter(prefix="/api/admin/weapp/social", tags=["weapp-social-ops"])
|
|
|
|
|
|
class FlagsPatch(BaseModel):
|
|
pages: dict[str, bool] | None = None
|
|
sections: dict[str, bool] | None = None
|
|
features: dict[str, bool] | None = None
|
|
buttons: dict[str, bool] | None = None
|
|
|
|
|
|
class SocialOpsBody(BaseModel):
|
|
moduleEnabled: bool | None = None
|
|
flags: FlagsPatch | None = None
|
|
copy: dict[str, str] | None = None
|
|
pageCopy: dict[str, dict[str, str] | None] | None = Field(default=None)
|
|
|
|
|
|
@router.get("")
|
|
async def get_social_ops(_: str = Depends(require_admin)) -> dict[str, Any]:
|
|
return read_social_ops()
|
|
|
|
|
|
@router.put("")
|
|
async def put_social_ops(body: SocialOpsBody, _: str = Depends(require_admin)) -> dict[str, Any]:
|
|
patch: dict[str, Any] = {}
|
|
if body.moduleEnabled is not None:
|
|
patch["moduleEnabled"] = body.moduleEnabled
|
|
if body.flags is not None:
|
|
patch["flags"] = body.flags.model_dump(exclude_none=True)
|
|
if body.copy is not None:
|
|
patch["copy"] = body.copy
|
|
if body.pageCopy is not None:
|
|
patch["pageCopy"] = body.pageCopy
|
|
return write_social_ops(patch)
|