Compare commits

..

3 Commits

Author SHA1 Message Date
saas-frontend 941e590067 chore: 注释格式微调,触发 CI
CI/CD Pipeline / Check push changed paths (pull_request) Has been skipped
CI/CD Pipeline / Dedup Check - skip PR tests when covered by push pipeline (pull_request) Successful in 1s
CI/CD Pipeline / Check if frontend-only change (pull_request) Successful in 1s
CI/CD Pipeline / PR Build API Image (pull_request) Failing after 1m21s
CI/CD Pipeline / Build Staging API Image (pull_request) Has been skipped
CI/CD Pipeline / Build Staging Web Image (pull_request) Has been skipped
CI/CD Pipeline / Build Staging Worker Image (pull_request) Has been skipped
CI/CD Pipeline / Retag skipped Staging API Image (pull_request) Has been skipped
CI/CD Pipeline / Retag skipped Staging Web Image (pull_request) Has been skipped
CI/CD Pipeline / Retag skipped Staging Worker Image (pull_request) Has been skipped
CI/CD Pipeline / Deploy Staging (Watchtower auto-deploy) (pull_request) Has been skipped
CI/CD Pipeline / Staging E2E Tests (pull_request) Has been skipped
CI/CD Pipeline / Staging API Integration Tests (pull_request) Has been skipped
CI/CD Pipeline / ACR Image Cleanup (pull_request) Has been skipped
CI/CD Pipeline / PR Build Web Image (pull_request) Successful in 1m37s
CI/CD Pipeline / Frontend Unit Tests (pull_request) Successful in 1m43s
PR Automation / Auto Approve on CI Green (pull_request) Successful in 3m6s
CI/CD Pipeline / Frontend Lint (pull_request) Successful in 3m43s
Preview Deploy / Deploy Preview Environment (pull_request) Successful in 4m14s
CI/CD Pipeline / Integration Tests (pull_request) Successful in 6m8s
CI/CD Pipeline / Unit Tests (pull_request) Successful in 6m13s
CI/CD Pipeline / Validate - Style (pull_request) Successful in 6m40s
AI Code Review / AI Code Review (pull_request) Successful in 6m52s
CI/CD Pipeline / Validate - Python (mypy + alembic) (pull_request) Successful in 7m10s
PR Automation / Auto Merge on CI Green + Approved (pull_request) Successful in 10m37s
CI/CD Pipeline / Validate - Security (pull_request) Successful in 16m38s
CI/CD Pipeline / Build Production API Image (pull_request) Has been skipped
CI/CD Pipeline / Build Production Worker Image (pull_request) Has been skipped
CI/CD Pipeline / Build Production Web Image (pull_request) Has been skipped
CI/CD Pipeline / Deploy Production (pull_request) Has been skipped
CI/CD Pipeline / Production Browser E2E (pull_request) Has been skipped
CI/CD Pipeline / Canary Release to Production (pull_request) Has been skipped
CI/CD Pipeline / PR Build Worker Image (pull_request) Failing after 31m20s
CI/CD Pipeline / CI Gate (pull_request) Failing after 1s
2026-09-17 01:09:28 +08:00
CI Bot 40a9040dc5 style: auto-format with black + isort + ruff + prettier [skip ci-format-check]
CI/CD Pipeline / Check push changed paths (pull_request) Has been skipped
CI/CD Pipeline / Dedup Check - skip PR tests when covered by push pipeline (pull_request) Successful in 2s
CI/CD Pipeline / Check if frontend-only change (pull_request) Successful in 3s
CI/CD Pipeline / Frontend Lint (pull_request) Successful in 1m16s
Preview Deploy / Deploy Preview Environment (pull_request) Successful in 2m7s
CI/CD Pipeline / PR Build API Image (pull_request) Failing after 1m2s
CI/CD Pipeline / Build Staging API Image (pull_request) Has been skipped
CI/CD Pipeline / Build Staging Web Image (pull_request) Has been skipped
CI/CD Pipeline / Build Staging Worker Image (pull_request) Has been skipped
CI/CD Pipeline / Retag skipped Staging API Image (pull_request) Has been skipped
CI/CD Pipeline / Retag skipped Staging Web Image (pull_request) Has been skipped
CI/CD Pipeline / Retag skipped Staging Worker Image (pull_request) Has been skipped
CI/CD Pipeline / Deploy Staging (Watchtower auto-deploy) (pull_request) Has been skipped
CI/CD Pipeline / Staging E2E Tests (pull_request) Has been skipped
CI/CD Pipeline / Staging API Integration Tests (pull_request) Has been skipped
CI/CD Pipeline / ACR Image Cleanup (pull_request) Has been skipped
CI/CD Pipeline / PR Build Web Image (pull_request) Successful in 1m2s
PR Automation / Auto Approve on CI Green (pull_request) Successful in 3m15s
CI/CD Pipeline / Validate - Style (pull_request) Successful in 3m23s
CI/CD Pipeline / Frontend Unit Tests (pull_request) Successful in 2m41s
CI/CD Pipeline / Unit Tests (pull_request) Successful in 5m2s
CI/CD Pipeline / Integration Tests (pull_request) Successful in 5m7s
CI/CD Pipeline / Validate - Python (mypy + alembic) (pull_request) Successful in 6m38s
AI Code Review / AI Code Review (pull_request) Successful in 7m0s
CI/CD Pipeline / Build Production API Image (pull_request) Has been cancelled
CI/CD Pipeline / Build Production Web Image (pull_request) Has been cancelled
CI/CD Pipeline / Build Production Worker Image (pull_request) Has been cancelled
CI/CD Pipeline / Deploy Production (pull_request) Has been cancelled
CI/CD Pipeline / Production Browser E2E (pull_request) Has been cancelled
CI/CD Pipeline / Canary Release to Production (pull_request) Has been cancelled
CI/CD Pipeline / CI Gate (pull_request) Has been cancelled
CI/CD Pipeline / Validate - Security (pull_request) Has been cancelled
CI/CD Pipeline / PR Build Worker Image (pull_request) Has been cancelled
PR Automation / Auto Merge on CI Green + Approved (pull_request) Has been cancelled
2026-09-16 16:56:33 +00:00
saas-frontend 741eaca358 fix(ux): #1894 文案/标题数据源全面切到 /api/v1/scripts
CI/CD Pipeline / Check push changed paths (pull_request) Has been skipped
CI/CD Pipeline / Dedup Check - skip PR tests when covered by push pipeline (pull_request) Successful in 1s
CI/CD Pipeline / Check if frontend-only change (pull_request) Successful in 1s
CI/CD Pipeline / Build Staging API Image (pull_request) Has been skipped
CI/CD Pipeline / Build Staging Web Image (pull_request) Has been skipped
CI/CD Pipeline / Build Staging Worker Image (pull_request) Has been skipped
CI/CD Pipeline / Unit Tests (pull_request) Has been skipped
CI/CD Pipeline / Integration Tests (pull_request) Has been skipped
CI/CD Pipeline / PR Build API Image (pull_request) Has been skipped
CI/CD Pipeline / PR Build Worker Image (pull_request) Has been skipped
CI/CD Pipeline / Retag skipped Staging API Image (pull_request) Has been skipped
CI/CD Pipeline / Retag skipped Staging Web Image (pull_request) Has been skipped
CI/CD Pipeline / Retag skipped Staging Worker Image (pull_request) Has been skipped
CI/CD Pipeline / Deploy Staging (Watchtower auto-deploy) (pull_request) Has been skipped
CI/CD Pipeline / Staging E2E Tests (pull_request) Has been skipped
CI/CD Pipeline / Staging API Integration Tests (pull_request) Has been skipped
CI/CD Pipeline / ACR Image Cleanup (pull_request) Has been skipped
CI/CD Pipeline / Frontend Lint (pull_request) Successful in 1m40s
PR Automation / Auto Approve on CI Green (pull_request) Successful in 1m47s
CI/CD Pipeline / PR Build Web Image (pull_request) Successful in 1m46s
Preview Deploy / Deploy Preview Environment (pull_request) Successful in 2m3s
CI/CD Pipeline / Frontend Unit Tests (pull_request) Successful in 2m51s
CI/CD Pipeline / Build Production API Image (pull_request) Has been cancelled
CI/CD Pipeline / Build Production Web Image (pull_request) Has been cancelled
CI/CD Pipeline / Build Production Worker Image (pull_request) Has been cancelled
CI/CD Pipeline / Deploy Production (pull_request) Has been cancelled
CI/CD Pipeline / Production Browser E2E (pull_request) Has been cancelled
CI/CD Pipeline / Canary Release to Production (pull_request) Has been cancelled
CI/CD Pipeline / CI Gate (pull_request) Has been cancelled
CI/CD Pipeline / Validate - Security (pull_request) Has been cancelled
CI/CD Pipeline / Validate - Python (mypy + alembic) (pull_request) Has been cancelled
CI/CD Pipeline / Validate - Style (pull_request) Has been cancelled
AI Code Review / AI Code Review (pull_request) Has been cancelled
PR Automation / Auto Merge on CI Green + Approved (pull_request) Has been cancelled
根因:
1. api/scripts 中 SCRIPTS_API_MOCK 被硬编码为 true,文案库/AI数字人/智能剪辑
   都拿 mock 数据,用户在文案库新建的文案、AI数字人手动输入的文案在其他
   页面选不到。
2. AI数字人页(PanelTitleConfig)、智能剪辑 step4(useStep4Title)仍在
   调已废弃的 @/api/titles,标题下拉为空。
3. AI数字人页自维护一份 getScripts 本地实现,返回类型/字段与共享
   @/api/scripts 不一致,且未共享 mock 开关。

修复:
- api/scripts/scripts.ts: SCRIPTS_API_MOCK 改为 env 开关(同 POINTS_API_MOCK
  模式,默认 false 走真实 API)。
- 删除废弃 api/titles/ 整个目录 + 相关单测(test/api/titles.test.ts、
  ai-avatar/components/TitleLibraryModal.tsx 孤儿组件)。
- ai-avatar/api/aiAvatar.ts: 文案库相关方法(getScripts/createScript/
  getScript/deleteScript)统一 re-export from @/api/scripts,不再
  本地重复实现。
- ai-avatar/types.ts: Script 类型改为 import("@/api/scripts").ScriptItem
  别名,保证字段对齐。
- ai-avatar/AiAvatarPage.tsx 内 ScriptSelectModalLazy: getScripts 适配
  { items, total } 分页结构,传 page_size:200 一次拿全。
- ai-avatar/components/PanelScript.tsx: 手动输入 tab 下增加「💾 保存到文案库」
  按钮,一键把当前口播文案以正文前20字为默认标题自动入库,解决主人反馈
  「历史文案在新文案库找不到」的问题;保存成功 toast 1s 自动关闭。
- ai-avatar/components/PanelTitleConfig.tsx: 标题 AutoComplete 数据源改为
  getScripts(),取 scripts[].title 去重作为候选,文案从「📚 标题库」
  改为「📚 文案库标题」。
- generate/hooks/useStep4Title/index.ts: userTitles 数据源改为 getScripts(),
  映射为 { content: s.title },复用下游消费逻辑(ut.content)。
- test/pages/GeneratePage.test.tsx: 把 @/api/titles mock 替换为
  @/api/scripts mock。

待跟进:
- P2 抖音错误提示友好化(等后端 #1963 合入后联调)。
2026-09-17 00:50:12 +08:00
14 changed files with 102 additions and 412 deletions
+6 -2
View File
@@ -11,8 +11,12 @@ import type {
ScriptCategory,
} from "./types"
/** 是否启用 mock(后端合入后改为 false */
export const SCRIPTS_API_MOCK = true
/**
* 是否启用 mock。
* #1894:文案库接口已上线,默认 false 走真实 API;
* 通过 SCRIPTS_API_MOCK=true 环境变量可本地开启 mock 调试(行为同 POINTS_API_MOCK)。
*/
export const SCRIPTS_API_MOCK = (process.env.SCRIPTS_API_MOCK as string | undefined) === "true"
// ==================== Mock 数据 ====================
-19
View File
@@ -1,19 +0,0 @@
/**
* 标题相关 API — 目录化入口
* 保持与原 titles.ts 相同导出,向后兼容
*/
// 类型
export type {
TitleItem,
BackendTitleResponse,
BackendCreateTitleRequest,
BackendUpdateTitleRequest,
CreateTitleRequest,
} from "./types"
// 工具函数
export { toTitleItem } from "./utils"
// API 函数
export { getTitles, createTitle, updateTitle, deleteTitle, batchImportTitles } from "./titles"
-65
View File
@@ -1,65 +0,0 @@
/**
* 标题相关 API 函数
* Phase 1 新增:全局标题库
* 注意:后端 schema 使用 name + text 字段,前端 UI 用 content 展示
*/
import apiClient from "../client"
import type {
BackendCreateTitleRequest,
BackendTitleResponse,
BackendUpdateTitleRequest,
CreateTitleRequest,
TitleItem,
} from "./types"
import { toTitleItem } from "./utils"
/** 获取当前用户的所有标题 */
export const getTitles = async (): Promise<TitleItem[]> => {
const response = await apiClient.get<{ items: BackendTitleResponse[] } | BackendTitleResponse[]>(
"/titles",
)
// 兼容两种后端返回格式:{ items: [...] } 或直接 [...]
const items = Array.isArray(response.data) ? response.data : response.data.items || []
return items.map(toTitleItem)
}
/** 创建标题 */
export const createTitle = async (data: CreateTitleRequest): Promise<TitleItem> => {
// 后端要求 name(≤255)和 text(≤500),name 从 content 截取
const payload: BackendCreateTitleRequest = {
name: data.content.slice(0, 255),
text: data.content.slice(0, 500),
category: data.category || "default",
}
const response = await apiClient.post<BackendTitleResponse>("/titles", payload)
return toTitleItem(response.data)
}
/** 更新标题 */
export const updateTitle = async (
titleId: string,
data: Partial<CreateTitleRequest>,
): Promise<TitleItem> => {
const payload: BackendUpdateTitleRequest = {}
if (data.content !== undefined) {
payload.name = data.content.slice(0, 255)
payload.text = data.content.slice(0, 500)
}
if (data.category !== undefined) {
payload.category = data.category
}
// 后端用 PUT,非 PATCH
const response = await apiClient.put<BackendTitleResponse>(`/titles/${titleId}`, payload)
return toTitleItem(response.data)
}
/** 删除标题 */
export const deleteTitle = async (titleId: string): Promise<void> => {
await apiClient.delete(`/titles/${titleId}`)
}
/** 批量导入标题 */
export const batchImportTitles = async (titles: string[]): Promise<{ imported_count: number }> => {
const response = await apiClient.post("/titles/batch-import", { titles })
return response.data
}
-54
View File
@@ -1,54 +0,0 @@
/**
* 标题相关类型定义
*/
/** 标题条目(前端展示用) */
export interface TitleItem {
id: string
content: string
category?: string
source?: string
word_count?: number
is_favorite?: boolean
created_at?: string
updated_at?: string
}
/** 后端标题响应格式 */
export interface BackendTitleResponse {
id: string
user_id: string
name: string
text: string
category: string
description: string
tags: string[]
usage_count: number
is_active: boolean
created_at: string
updated_at: string
}
/** 后端创建标题请求格式 */
export interface BackendCreateTitleRequest {
name: string
text: string
category: string
description?: string
tags?: string[]
}
/** 后端更新标题请求格式 */
export interface BackendUpdateTitleRequest {
name?: string
text?: string
category?: string
description?: string
tags?: string[]
}
/** 创建标题请求(前端接口,保持向后兼容) */
export interface CreateTitleRequest {
content: string
category?: string
}
-14
View File
@@ -1,14 +0,0 @@
/**
* 标题数据转换工具函数
*/
import type { BackendTitleResponse, TitleItem } from "./types"
/** 将后端响应映射为前端 TitleItem */
export const toTitleItem = (item: BackendTitleResponse): TitleItem => ({
id: item.id,
content: item.text,
category: item.category,
word_count: item.text?.length || 0,
created_at: item.created_at,
updated_at: item.updated_at,
})
@@ -619,6 +619,7 @@ const AiAvatarPage: React.FC = () => {
scriptText={state.scriptText}
onScriptTextChange={state.setScriptText}
onOpenScriptModal={() => state.setShowScriptModal(true)}
onScriptCreated={(s) => state.selectScript(s as import("./types").Script)}
/>
<div className="aa-step-btn-row">
<button
@@ -1146,8 +1147,9 @@ const ScriptSelectModalLazy: React.FC<{
useEffect(() => {
if (!open) return
setLoading(true)
getScripts()
.then((items) => setScripts(Array.isArray(items) ? items : []))
// #1894: getScripts 返回 { items, total } 分页结构,取 items 即可
getScripts({ page_size: 200 })
.then((res) => setScripts(Array.isArray(res) ? res : (res.items ?? [])))
.catch(() => setScripts([]))
.finally(() => setLoading(false))
}, [open])
+8 -24
View File
@@ -2,31 +2,15 @@
* AI数字人 — API 封装(#1822 契约对齐)
*/
import apiClient from "@/api/client"
import type { Script, LipsyncJob, RenderJob, BRollSegment, SentenceTiming } from "../types"
// #1894: Script 类型统一从 @/api/scripts 取(ai-avatar 本地 Script 仅保留渲染/对口型等自有类型)
import type { LipsyncJob, RenderJob, BRollSegment, SentenceTiming } from "../types"
/* ── 文案库 ── */
export const getScripts = async (): Promise<Script[]> => {
const response = await apiClient.get<{ items?: Script[] } | Script[]>("/scripts")
// 后端列表返回 { items, total } 分页对象,做兼容解包 + 数组防御(#1809 白屏修复)
const data = response.data as unknown
if (Array.isArray(data)) return data
const items = (data as { items?: Script[] })?.items
return Array.isArray(items) ? items : []
}
export const getScriptById = async (id: string): Promise<Script> => {
const response = await apiClient.get<Script>(`/scripts/${id}`)
return response.data
}
export const createScript = async (data: { title: string; content: string }): Promise<Script> => {
const response = await apiClient.post<Script>("/scripts", data)
return response.data
}
export const deleteScript = async (id: string): Promise<void> => {
await apiClient.delete(`/scripts/${id}`)
}
/* ── 文案库 ──
* #1894: 统一走 @/api/scripts 的 getScripts,不再各自封装;
* 这样 mock 开关、分页/搜索参数、字段对齐都和文案库页面保持一致。
*/
// #1894: 统一复用文案库 API,不再在 ai-avatar 里重复实现
export { getScripts, getScript as getScriptById, createScript, deleteScript } from "@/api/scripts"
/* ── 素材单查(拿到 file_url 作为对口型的 video_url ── */
export const getAssetById = async (id: string): Promise<{ file_url?: string; id: string }> => {
@@ -1,13 +1,17 @@
/**
* AI数字人 — 文案面板(步骤1用)
* 文案库选择 / 手动输入 + 字数统计
* #1894: 文案库选择走 @/api/scripts;手动输入支持一键「保存到文案库」
*/
import { useState } from "react"
import { message } from "antd"
import { createScript } from "../api/aiAvatar"
interface PanelScriptProps {
scriptText: string
onScriptTextChange: (text: string) => void
onOpenScriptModal: () => void
/** 手动保存到文案库后回调(把新脚本传入,父组件可更新 selectedScript */
onScriptCreated?: (script: { id: string; title: string; content: string }) => void
}
type ScriptTab = "library" | "manual"
@@ -16,8 +20,30 @@ export function PanelScript({
scriptText,
onScriptTextChange,
onOpenScriptModal,
onScriptCreated,
}: PanelScriptProps) {
const [scriptTab, setScriptTab] = useState<ScriptTab>("library")
const [saving, setSaving] = useState(false)
const handleSaveToLibrary = async () => {
const text = scriptText.trim()
if (!text) {
message.warning("请先输入文案内容")
return
}
// 用正文前 20 字作为默认标题
const autoTitle = text.slice(0, 20).replace(/\n+/g, " ").trim() || "手动输入文案"
setSaving(true)
try {
const created = await createScript({ title: autoTitle, content: text, tags: [] })
message.success({ content: "已保存到文案库", duration: 1 })
onScriptCreated?.(created)
} catch {
message.error("保存到文案库失败,请稍后重试")
} finally {
setSaving(false)
}
}
return (
<div className="aa-script-lipsync">
@@ -59,7 +85,20 @@ export function PanelScript({
}
onChange={(e) => onScriptTextChange(e.target.value)}
/>
<div className="aa-char-count">{scriptText.length} </div>
<div style={{ display: "flex", justifyContent: "space-between", alignItems: "center" }}>
<div className="aa-char-count">{scriptText.length} </div>
{scriptTab === "manual" && scriptText.trim().length > 0 && (
<button
type="button"
className="aa-btn aa-btn--text"
disabled={saving}
onClick={handleSaveToLibrary}
style={{ fontSize: 12, padding: "2px 8px" }}
>
{saving ? "保存中..." : "💾 保存到文案库"}
</button>
)}
</div>
</div>
)
}
@@ -15,7 +15,8 @@ import type { TitleOption } from "@/pages/generate/components/title/TitleLibrary
import type { TitleSettings } from "@/pages/generate/types"
import { POSITION_OPTIONS, FONT_OPTIONS, TITLE_PRESETS } from "@/pages/generate/constants"
import type { AiAvatarTitleConfig } from "../types"
import { getTitles } from "@/api/titles"
// #1894: 标题数据源切换到文案库,取 script.title 作为候选
import { getScripts } from "@/api/scripts"
const { TextArea } = Input
@@ -28,11 +29,23 @@ const PanelTitleConfig: React.FC<PanelTitleConfigProps> = ({ titleConfig, onUpda
/** TitleStylePanel 内部高亮的预设 key(面板本地状态) */
const [activePreset, setActivePreset] = useState<string | null>(null)
/** 标题库选项(复用智能剪辑的标题库 */
/** 标题库选项(#1894:从文案库 scripts[].title 取候选 */
const [titleOptions, setTitleOptions] = useState<TitleOption[]>([])
useEffect(() => {
getTitles()
.then((items) => setTitleOptions(items.map((t) => ({ label: t.content, value: t.content }))))
getScripts({ page_size: 200 })
.then((res) => {
const items = Array.isArray(res) ? res : (res.items ?? [])
// 去重 + 过滤空标题
const seen = new Set<string>()
const opts: TitleOption[] = []
for (const s of items) {
const t = (s.title || "").trim()
if (!t || seen.has(t)) continue
seen.add(t)
opts.push({ label: t, value: t })
}
setTitleOptions(opts)
})
.catch(() => setTitleOptions([]))
}, [])
@@ -84,10 +97,12 @@ const PanelTitleConfig: React.FC<PanelTitleConfigProps> = ({ titleConfig, onUpda
style={{ fontSize: 15 }}
/>
<div style={{ marginTop: 8, display: "flex", alignItems: "center", gap: 8 }}>
<span style={{ fontSize: 12, color: "#8c8ca1", whiteSpace: "nowrap" }}>📚 </span>
<span style={{ fontSize: 12, color: "#8c8ca1", whiteSpace: "nowrap" }}>
📚
</span>
<TitleLibraryAutoComplete
key={titleConfig.title}
placeholder="选择标题填入上方"
placeholder="从文案库选择标题"
value=""
onChange={(val) => {
if (val) onUpdate({ title: val })
@@ -1,97 +0,0 @@
/**
* AI数字人 — 标题库选择弹窗
* 复用智能剪辑的标题库 API,选择标题后填入输入框
*/
import React, { useEffect, useState } from "react"
import { getTitles } from "@/api/titles"
import type { TitleItem } from "@/api/titles/types"
interface TitleLibraryModalProps {
open: boolean
onClose: () => void
onSelect: (title: string) => void
}
const TitleLibraryModal: React.FC<TitleLibraryModalProps> = ({ open, onClose, onSelect }) => {
const [titles, setTitles] = useState<TitleItem[]>([])
const [loading, setLoading] = useState(false)
const [search, setSearch] = useState("")
useEffect(() => {
if (!open) return
setLoading(true)
getTitles()
.then((items) => setTitles(items))
.catch(() => setTitles([]))
.finally(() => setLoading(false))
}, [open])
const filtered = titles.filter(
(t) => !search || t.content.toLowerCase().includes(search.toLowerCase()),
)
if (!open) return null
return (
<div className="aa-modal-overlay" onClick={onClose}>
<div className="aa-modal" onClick={(e) => e.stopPropagation()} style={{ maxWidth: 600 }}>
<div className="aa-modal__header">
<span className="aa-modal__title"></span>
<button className="aa-modal__close" onClick={onClose}></button>
</div>
<div className="aa-modal__body">
<div style={{ marginBottom: 12 }}>
<input
className="aa-input"
placeholder="搜索标题..."
value={search}
onChange={(e) => setSearch(e.target.value)}
/>
</div>
{loading ? (
<div style={{ textAlign: "center", padding: 40, color: "#8c8ca1" }}>...</div>
) : filtered.length === 0 ? (
<div style={{ textAlign: "center", padding: 40, color: "#8c8ca1" }}>
</div>
) : (
<div style={{ maxHeight: 400, overflowY: "auto" }}>
{filtered.map((t) => (
<div
key={t.id}
style={{
padding: "12px 16px",
marginBottom: 8,
background: "#f8f8fc",
borderRadius: 8,
cursor: "pointer",
transition: "background 0.2s",
}}
onMouseEnter={(e) => (e.currentTarget.style.background = "#eef0ff")}
onMouseLeave={(e) => (e.currentTarget.style.background = "#f8f8fc")}
onClick={() => {
onSelect(t.content)
onClose()
}}
>
<div style={{ fontSize: 14, color: "#1a1a2e", marginBottom: 4 }}>{t.content}</div>
<div style={{ fontSize: 12, color: "#8c8ca1" }}>
{t.word_count ?? t.content.length} ·{" "}
{t.created_at ? new Date(t.created_at).toLocaleDateString() : ""}
</div>
</div>
))}
</div>
)}
</div>
<div className="aa-modal__footer">
<button className="aa-btn" onClick={onClose}>
</button>
</div>
</div>
</div>
)
}
export default TitleLibraryModal
+5 -9
View File
@@ -56,15 +56,11 @@ export interface TtsPreviewResult {
error: string | null
}
/* ── 文案 ── */
export interface Script {
id: string
title: string
content: string
char_count: number
created_at: string
updated_at?: string
}
/* ── 文案 ──
* #1894: 直接复用文案库的 ScriptItem 类型,保证字段(title/content/tags/...)一致;
* 个别 ai-avatar 专属属性如有需要再在此处扩展。
*/
export type Script = import("@/api/scripts").ScriptItem
/* ── 对口型任务 ── */
export interface LipsyncJob {
@@ -1,6 +1,7 @@
import { useEffect, useRef } from "react"
import { useQuery } from "@tanstack/react-query"
import { getTitles } from "@/api/titles"
// #1894: 标题候选从文案库 scripts[].title 获取,不再调用废弃的 /api/titles
import { getScripts } from "@/api/scripts"
import type { TitleSettings } from "../../types"
import { useAiTitleGenerator } from "./useAiTitleGenerator"
import { useTitleStyleUpdaters } from "./useTitleStyleUpdaters"
@@ -22,10 +23,14 @@ export function useStep4Title({
onTitleSettingsChange,
selectedTemplate,
}: UseStep4TitleProps) {
// 标题库数据
// 标题候选(#1894:统一从文案库取 scripts[].title,去重)
const { data: userTitles = [] } = useQuery({
queryKey: ["titles"],
queryFn: () => getTitles(),
queryKey: ["scripts", "titles-source"],
queryFn: async () => {
const res = await getScripts({ page_size: 200 })
const items = Array.isArray(res) ? res : (res.items ?? [])
return items.map((s) => ({ content: (s.title || "").trim() })).filter((s) => !!s.content)
},
staleTime: 30_000,
})
-112
View File
@@ -1,112 +0,0 @@
import { describe, expect, it, vi, beforeEach } from "vitest"
import { getTitles, createTitle, updateTitle, deleteTitle, batchImportTitles } from "@/api/titles"
const mockGet = vi.fn()
const mockPost = vi.fn()
const mockPut = vi.fn()
const mockDelete = vi.fn()
const mockPatch = vi.fn()
vi.mock("@/api/client", () => ({
default: {
get: (...args: unknown[]) => mockGet(...args),
post: (...args: unknown[]) => mockPost(...args),
put: (...args: unknown[]) => mockPut(...args),
delete: (...args: unknown[]) => mockDelete(...args),
patch: (...args: unknown[]) => mockPatch(...args),
},
}))
vi.mock("antd", () => ({ message: { error: vi.fn(), success: vi.fn() } }))
vi.mock("@/store/authStore", () => ({ useAuthStore: { getState: vi.fn(() => ({})) } }))
describe("titles API", () => {
beforeEach(() => {
vi.clearAllMocks()
mockGet.mockResolvedValue({ data: { success: true, items: [] } })
mockPost.mockResolvedValue({ data: { success: true, items: [] } })
mockPut.mockResolvedValue({ data: { success: true, items: [] } })
mockDelete.mockResolvedValue({ data: { success: true, items: [] } })
mockPatch.mockResolvedValue({ data: { success: true, items: [] } })
})
describe("getTitles", () => {
it("should resolve successfully", async () => {
await expect(getTitles()).resolves.not.toThrow()
})
it("should reject on API error", async () => {
mockGet.mockRejectedValue(new Error("Network error"))
mockPost.mockRejectedValue(new Error("Network error"))
mockPut.mockRejectedValue(new Error("Network error"))
mockDelete.mockRejectedValue(new Error("Network error"))
mockPatch.mockRejectedValue(new Error("Network error"))
await expect(getTitles()).rejects.toThrow()
})
})
describe("createTitle", () => {
it("should resolve successfully", async () => {
await expect(createTitle({ title: "测试标题", content: "测试内容" })).resolves.not.toThrow()
})
it("should reject on API error", async () => {
mockGet.mockRejectedValue(new Error("Network error"))
mockPost.mockRejectedValue(new Error("Network error"))
mockPut.mockRejectedValue(new Error("Network error"))
mockDelete.mockRejectedValue(new Error("Network error"))
mockPatch.mockRejectedValue(new Error("Network error"))
await expect(createTitle({ name: "test-item" })).rejects.toThrow()
})
})
describe("updateTitle", () => {
it("should resolve successfully", async () => {
await expect(updateTitle("test-titleId", { title: "新标题" })).resolves.not.toThrow()
})
it("should reject on API error", async () => {
mockGet.mockRejectedValue(new Error("Network error"))
mockPost.mockRejectedValue(new Error("Network error"))
mockPut.mockRejectedValue(new Error("Network error"))
mockDelete.mockRejectedValue(new Error("Network error"))
mockPatch.mockRejectedValue(new Error("Network error"))
await expect(updateTitle("test-titleId")).rejects.toThrow()
})
})
describe("deleteTitle", () => {
it("should resolve successfully", async () => {
await expect(deleteTitle("test-titleId")).resolves.not.toThrow()
})
it("should reject on API error", async () => {
mockGet.mockRejectedValue(new Error("Network error"))
mockPost.mockRejectedValue(new Error("Network error"))
mockPut.mockRejectedValue(new Error("Network error"))
mockDelete.mockRejectedValue(new Error("Network error"))
mockPatch.mockRejectedValue(new Error("Network error"))
await expect(deleteTitle("test-titleId")).rejects.toThrow()
})
})
describe("batchImportTitles", () => {
it("should resolve successfully", async () => {
await expect(batchImportTitles("test-titles")).resolves.not.toThrow()
})
it("should reject on API error", async () => {
mockGet.mockRejectedValue(new Error("Network error"))
mockPost.mockRejectedValue(new Error("Network error"))
mockPut.mockRejectedValue(new Error("Network error"))
mockDelete.mockRejectedValue(new Error("Network error"))
mockPatch.mockRejectedValue(new Error("Network error"))
await expect(batchImportTitles("test-titles")).rejects.toThrow()
})
})
})
@@ -215,8 +215,14 @@ vi.mock("@/api/editing-planner", () => ({
MODE_LABELS: { pip: "画中画" },
}))
vi.mock("@/api/titles", () => ({
getTitles: vi.fn().mockResolvedValue({ items: [] }),
// #1894: 标题数据源已切到 @/api/scriptsmock scripts 返回空数组作为默认
vi.mock("@/api/scripts", () => ({
getScripts: vi.fn().mockResolvedValue({ items: [], total: 0, page: 1, page_size: 20 }),
aiRewriteScript: vi.fn(),
aiGenerateTitles: vi.fn(),
SCRIPTS_API_MOCK: false,
SCRIPT_CATEGORY_LABEL: {},
REWRITE_STYLE_OPTIONS: [],
}))
vi.mock("@/api/template-editor", () => ({