Collapse portal under src/, unify pnpm workspace/scripts, thin VIP topic re-exports, drop orphan vip scaffolds and one-shot scripts, ignore xhs/release, document root commands. Co-authored-by: Cursor <cursoragent@cursor.com>
91 lines
2.9 KiB
Python
91 lines
2.9 KiB
Python
"""抖音小程序管理 API — 与微信读者/订单/支付完全隔离。"""
|
||
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.tt_platform_config import read_tt_platform, write_tt_platform
|
||
|
||
router = APIRouter(prefix="/api/admin/douyin", tags=["douyin-admin"])
|
||
|
||
|
||
class ModuleToggle(BaseModel):
|
||
enabled: bool = False
|
||
title: str = ""
|
||
tabLabel: str | None = None
|
||
note: str | None = None
|
||
|
||
|
||
class BookChapter(BaseModel):
|
||
id: str
|
||
title: str
|
||
emoji: str | None = "📖"
|
||
content: str = ""
|
||
hook: str | None = ""
|
||
shareQuote: str | None = ""
|
||
|
||
|
||
class BookContent(BaseModel):
|
||
title: str = "数字游民"
|
||
subtitle: str | None = ""
|
||
author: str | None = ""
|
||
description: str | None = ""
|
||
tagline: str | None = ""
|
||
coverEmoji: str | None = "📗"
|
||
chapters: list[BookChapter] = Field(default_factory=list)
|
||
updatedAt: str | None = None
|
||
|
||
|
||
class TtPlatformBody(BaseModel):
|
||
modules: dict[str, ModuleToggle] | None = None
|
||
bookContent: BookContent | None = None
|
||
|
||
|
||
@router.get("/config")
|
||
async def get_douyin_config(_: str = Depends(require_admin)) -> dict[str, Any]:
|
||
return {"ok": True, "config": read_tt_platform()}
|
||
|
||
|
||
@router.put("/config")
|
||
async def put_douyin_config(body: TtPlatformBody, _: str = Depends(require_admin)) -> dict[str, Any]:
|
||
patch: dict[str, Any] = {}
|
||
if body.modules is not None:
|
||
patch["modules"] = {k: v.model_dump() for k, v in body.modules.items()}
|
||
if body.bookContent is not None:
|
||
patch["bookContent"] = body.bookContent.model_dump()
|
||
saved = write_tt_platform(patch)
|
||
return {"ok": True, "config": saved}
|
||
|
||
|
||
@router.get("/meta")
|
||
async def douyin_meta(_: str = Depends(require_admin)) -> dict[str, Any]:
|
||
"""抖音开发文档 / 包体约定(定制面板用,非微信业务)。"""
|
||
return {
|
||
"ok": True,
|
||
"docs": [
|
||
{
|
||
"title": "小程序使用指南",
|
||
"url": "https://developer.open-douyin.com/docs/resource/zh-CN/mini-app/introduction/usage-guide",
|
||
},
|
||
{
|
||
"title": "使用 AI 开发小程序",
|
||
"url": "https://developer.open-douyin.com/docs/resource/zh-CN/mini-app/introduction/ai-mini-app-dev",
|
||
},
|
||
{
|
||
"title": "隐私协议配置",
|
||
"url": "https://developer.open-douyin.com/docs/resource/zh-CN/mini-app/open-capacity/basic-capacities/privacy-agreement",
|
||
},
|
||
],
|
||
"limits": {
|
||
"mainPackageMB": 4,
|
||
"subPackageMB": 2,
|
||
"totalMB": 16,
|
||
"note": "本仓抖音 packageBook 需 ≤2MB;构建 validate:size",
|
||
},
|
||
"appId": "tt995defe007255b2701",
|
||
"importDir": "apps/miniprogram/tt",
|
||
}
|