PRINTFILM: AI short-video marketing and AI short-drama creation platform
fix(frontend): 优化视频版权审核失败提示
yid36942363d43
diff --git a/frontend/src/components/billing/BillingErrorNotice.tsx b/frontend/src/components/billing/BillingErrorNotice.tsxindex 4238371..596370d 100644--- a/frontend/src/components/billing/BillingErrorNotice.tsx+++ b/frontend/src/components/billing/BillingErrorNotice.tsx@@ -2,6 +2,7 @@ import type { CSSProperties } from 'react'import { Link } from 'react-router-dom'import { isBillingError, PRICING_PATH } from '../../lib/billingError'import { workspaceScope } from '../../features/teams/workspaceScope'+import { formatCopyrightError, formatGenerationErrorMessage } from '../../lib/generationError'type Props = {message: string | null | undefined@@ -24,10 +25,10 @@ export default function BillingErrorNotice({const text = String(message || '').trim()if (!text) return nullconst Tag = inline ? 'span' : 'p'- if (!isBillingError(text)) {+ if (formatCopyrightError(text) || !isBillingError(text)) {return (<Tag className={className} style={style} role={inline ? undefined : 'alert'}>- {text}+ {formatGenerationErrorMessage(text)}</Tag>)}diff --git a/frontend/src/lib/dramaGenError.ts b/frontend/src/lib/dramaGenError.tsindex c8dc8ba..a4d9daa 100644--- a/frontend/src/lib/dramaGenError.ts+++ b/frontend/src/lib/dramaGenError.ts@@ -2,6 +2,7 @@import { dialog } from './dialog'import { isBillingError } from './billingError'+import { formatCopyrightError } from './generationError.ts'export type DramaGenErrorView = {/** 短标题 */@@ -31,6 +32,7 @@ function extractContentIndex(raw: string): number | null {/** 判断文案是否像「具体根因」(优先于「重试上限」等包装句) */function looksLikeRootCause(text: string): boolean {+ if (formatCopyrightError(text)) return truereturn /PrivacyInformation|InputImageSensitive|SensitiveContentDetected|参考图疑似|参考音频过短|参考音频过长|无法读取参考音频时长|may contain real person|Seedance create error|上一镜失败|无法衔接|分镜已变更|分镜上下文|InputTextSensitive|resource download failed|audio_url|audio duration|Credits insufficient|File type not supported|参考图格式不支持|invalid image format|参考图格式无效|未开通/i.test(text,)@@ -62,6 +64,8 @@ export function pickRootDramaGenError(*/export function formatDramaGenError(raw: string | null | undefined): DramaGenErrorView {const text = String(raw || '').trim()+ const copyright = formatCopyrightError(text)+ if (copyright) return copyrightif (!text) {return {title: '生成失败',diff --git a/frontend/src/lib/generationError.ts b/frontend/src/lib/generationError.tsnew file mode 100644index 0000000..7f2cd25--- /dev/null+++ b/frontend/src/lib/generationError.ts@@ -0,0 +1,29 @@+/** 视频生成版权审核错误的展示文案;原始异常继续保留在任务记录中。 */+export type CopyrightErrorView = {+ title: string+ message: string+ suggestion: string+ requestId?: string+}++/** 只识别明确的输出版权审核,避免将其他敏感内容或网络错误归为版权问题。 */+export function formatCopyrightError(raw: string | null | undefined): CopyrightErrorView | null {+ const text = String(raw || '')+ if (!/OutputVideoSensitiveContentDetected\.PolicyViolation|output\s*video[\s\S]{0,180}?copyright\s*restrictions|(?:输出|生成)(?:的)?视频[\s\S]{0,60}?版权(?:限制|保护)/i.test(text)) return null++ const match = text.match(/\brequest[\s_-]*id\b["'\s::]*([a-z0-9][a-z0-9_-]*)|请求(?:\s*(?:id|编号))?\s*[::]\s*([a-z0-9][a-z0-9_-]*)/i)+ const requestId = match?.[1] || match?.[2]+ return {+ title: '视频未通过版权审核',+ message: '视频服务提示本次生成结果可能涉及版权限制,暂时无法提供视频。'+ + (requestId ? `\n请求编号:${requestId}` : ''),+ suggestion: '请调整提示词或参考素材后重试;如素材为原创或已获授权,请联系客服核查。',+ requestId,+ }+}++/** 为通用错误区域提供版权审核说明与建议,其他错误保持原文。 */+export function formatGenerationErrorMessage(raw: string | null | undefined): string {+ const view = formatCopyrightError(raw)+ return view ? `${view.message}\n${view.suggestion}` : String(raw || '')+}diff --git a/frontend/src/lib/toolRunDetails.ts b/frontend/src/lib/toolRunDetails.tsindex 774049d..42c4bf2 100644--- a/frontend/src/lib/toolRunDetails.ts+++ b/frontend/src/lib/toolRunDetails.ts@@ -1,5 +1,6 @@import type { ToolRunRecord } from '../api/tools.ts'import type { AssetDetailRecord } from './assetDetails.ts'+import { formatGenerationErrorMessage } from './generationError.ts'/** 只接收参数标量,忽略请求引用、对象和内部追踪信息。 */function scalar(value: unknown): string | number | boolean | undefined {@@ -21,7 +22,7 @@ export function toolRunDetailAsset(record: ToolRunRecord, resultIndex = 0): Asseconst duration = seconds(params.duration_sec ?? params.duration)const labels: Record<string, string> = { video: '视频生成', image: '图片生成', audio: '音频生成', text: '文字生成' }const statuses: Record<string, string> = { queued: '任务正在排队,结果会自动更新。', running: '任务正在生成,结果会自动更新。', succeeded: '任务已完成,暂无可预览的媒体结果。', failed: '生成失败。', cancelled: '任务已取消。' }- const textContent = record.text_content || record.error || statuses[record.status] || `任务状态:${record.status}`+ const textContent = record.text_content || formatGenerationErrorMessage(record.error) || statuses[record.status] || `任务状态:${record.status}`return {id: record.id,diff --git a/frontend/src/pages/GenerationPage.tsx b/frontend/src/pages/GenerationPage.tsxindex 12d0d86..ed12cd7 100644--- a/frontend/src/pages/GenerationPage.tsx+++ b/frontend/src/pages/GenerationPage.tsx@@ -10,6 +10,7 @@ import PromptMentionPopover from '../components/tools/PromptMentionPopover'import { AssetDetailDialog } from '../components/assets/AssetDetailDialog'import { useToolRunDetail } from '../hooks/useToolRunDetail'import { mediaIcons, type MediaKind, useGenerationText } from '../lib/generationMedia'+import { formatGenerationErrorMessage } from '../lib/generationError'import { fetchMediaBlob, triggerBlobDownload } from '../lib/clientDownload'import { useMediaModelsCatalog } from '../hooks/useMediaModelsCatalog'import { MediaCostNotice } from '../components/billing/MediaCostNotice'@@ -287,7 +288,7 @@ function GenerationWorkspace({ kind }: { kind: MediaKind }) {{detail && detailAsset && <AssetDetailDialog asset={detailAsset} onClose={closeDetail}notice={<section className="pf-asset-detail-prompt"><div className="pf-asset-detail-text"><p role="status">{text(detail.status === 'succeeded' ? '已完成' : detail.status === 'failed' ? '生成失败' : detail.status === 'cancelled' ? '已取消' : '正在生成,结果会自动更新。', detail.status === 'succeeded' ? 'Completed' : detail.status === 'failed' ? 'Generation failed' : detail.status === 'cancelled' ? 'Cancelled' : 'Generating. Results will update automatically.')}</p>- {(detail.error || detailError) && <p role="alert">{detail.error || detailError}</p>}+ {(detail.error || detailError) && <p role="alert">{formatGenerationErrorMessage(detail.error || detailError)}</p>}</div></section>}actions={detail.urls.length > 1 && <div className="pf-asset-detail-utilities" role="group" aria-label={text('生成结果', 'Generation results')}>{detail.urls.map((url, index) => <button type="button" key={url} className="pf-btn pf-btn-sm" aria-pressed={resultIndex === index} onClick={() => selectResult(index)}>{text(`结果 ${index + 1}`, `Result ${index + 1}`)}</button>)}diff --git a/frontend/src/pages/GenerationTasksPage.tsx b/frontend/src/pages/GenerationTasksPage.tsxindex 9ad1824..a284547 100644--- a/frontend/src/pages/GenerationTasksPage.tsx+++ b/frontend/src/pages/GenerationTasksPage.tsx@@ -9,6 +9,7 @@ import GenerationSelect from '../components/tools/GenerationSelect'import { AssetDetailDialog } from '../components/assets/AssetDetailDialog'import { useToolRunDetail } from '../hooks/useToolRunDetail'import { mediaIcons, useGenerationText } from '../lib/generationMedia'+import { formatGenerationErrorMessage } from '../lib/generationError'import { generationBillingState, generationRecordKey, generationTaskKind, generationTaskKinds as taskKinds, type GenerationTaskKind as TaskKind } from '../lib/generationTaskHistory'import { subscribeWorkspace, workspaceScope } from '../features/teams/workspaceScope'import Pagination from '../components/ui/Pagination'@@ -112,6 +113,8 @@ function TaskHistoryContent() {return seconds < 60 ? `${seconds}s` : `${Math.floor(seconds / 60)}m ${seconds % 60}s`}function errorSummary(error: string) {+ const friendlyMessage = formatGenerationErrorMessage(error)+ if (friendlyMessage !== error) return friendlyMessageif (/sensitive|policyviolation|content.?filter|审核/i.test(error)) return text('内容未通过审核,请调整描述后重试', 'Content review failed. Try adjusting your prompt.')if (/余额不足|insufficient.*balance/i.test(error)) return text('余额不足,请充值后重试', 'Insufficient balance. Please top up.')if (/timeout|timed out|超时/i.test(error)) return text('生成超时,请稍后重试', 'Generation timed out. Please try again.')@@ -170,7 +173,7 @@ function TaskHistoryContent() {{item.kind === 'image' && (item.preview_url || item.urls[0]) ? <img src={resolveToolMediaUrl(item.preview_url || item.urls[0])} alt="" /> : item.kind === 'video' && item.preview_url ? <img src={resolveToolMediaUrl(item.preview_url)} alt="" /> : item.kind === 'video' && item.urls[0] ? <video src={resolveToolMediaUrl(item.urls[0])} preload="metadata" muted /> : <RowIcon size={28} />}<span className="gen-cover-overlay"><Eye size={18} /></span></button>- <div className="gen-task-description"><button type="button" className="gen-task-title" onClick={() => openDetail(item)} title={title}>{title}</button><div className="gen-task-metadata"><span className="gen-task-tag">{kindLabels[item.kind as TaskKind] || 'AI'}</span>{shortVideoImage && <span className="gen-task-tag">{text('AI短视频', 'AI short video')}</span>}{item.kind === 'image' && item.urls.length > 1 && <span className="gen-task-tag">{text(`${item.urls.length} 张图片`, `${item.urls.length} images`)}</span>}{ratio && <span className="gen-task-tag">{ratio}</span>}</div>{item.error && <button type="button" className="gen-task-error" onClick={() => openDetail(item)} title={item.error}><AlertCircle size={12} /><span>{errorSummary(item.error)}</span><ArrowUpRight size={12} /></button>}</div>+ <div className="gen-task-description"><button type="button" className="gen-task-title" onClick={() => openDetail(item)} title={title}>{title}</button><div className="gen-task-metadata"><span className="gen-task-tag">{kindLabels[item.kind as TaskKind] || 'AI'}</span>{shortVideoImage && <span className="gen-task-tag">{text('AI短视频', 'AI short video')}</span>}{item.kind === 'image' && item.urls.length > 1 && <span className="gen-task-tag">{text(`${item.urls.length} 张图片`, `${item.urls.length} images`)}</span>}{ratio && <span className="gen-task-tag">{ratio}</span>}</div>{item.error && <button type="button" className="gen-task-error" onClick={() => openDetail(item)} title={formatGenerationErrorMessage(item.error)}><AlertCircle size={12} /><span>{errorSummary(item.error)}</span><ArrowUpRight size={12} /></button>}</div><div className="gen-task-state"><span className={`gen-state is-${item.status}`}><RowStatusIcon size={13} />{labels[item.status] || item.status}</span><small>{formatLabel}</small></div><div className="gen-task-cost"><strong>{billingState === 'hidden' ? '—' : `¥${((item.billing_charged_fen || 0) / 100).toFixed(2)}`}</strong><small>{billingLabels[billingState]}</small></div><div className="gen-task-time"><span>{when(item.created_at)}</span><small>{text('耗时', 'Duration')} {elapsed(item)}</small></div>@@ -184,7 +187,7 @@ function TaskHistoryContent() {{detail && detailAsset && <AssetDetailDialog key={generationRecordKey(detail)} asset={detailAsset} onClose={closeDetail}notice={<section className="pf-asset-detail-prompt"><div className="pf-asset-detail-text"><p role="status">{labels[detail.status] || detail.status}{(detail.status === 'queued' || detail.status === 'running') && text(',结果会自动更新。', '. Results will update automatically.')}</p>- {(detail.error || detailError) && <p role="alert">{detail.error || detailError}</p>}+ {(detail.error || detailError) && <p role="alert">{formatGenerationErrorMessage(detail.error || detailError)}</p>}</div></section>}actions={detail.urls.length > 1 && <div className="pf-asset-detail-utilities" role="group" aria-label={text('生成结果', 'Generation results')}>{detail.urls.map((url, index) => <button type="button" key={url} className="pf-btn pf-btn-sm" aria-pressed={resultIndex === index} onClick={() => selectResult(index)}>{text(`结果 ${index + 1}`, `Result ${index + 1}`)}</button>)}diff --git a/frontend/src/pages/HistoryPage.tsx b/frontend/src/pages/HistoryPage.tsxindex 498d205..b877dfe 100644--- a/frontend/src/pages/HistoryPage.tsx+++ b/frontend/src/pages/HistoryPage.tsx@@ -27,6 +27,7 @@ import { hasActiveTasks, isRunning, STATUS_CN } from '../lib/status'import { pageCountOf } from '../lib/pagination'import { SHORT_VIDEO_CREATE_PATH, shortVideoProjectPath } from '../lib/shortVideoRoutes'import { withReturn } from '../features/marketplace/ui'+import { formatGenerationErrorMessage } from '../lib/generationError'import { formatDateTime, useI18n } from '../i18n'import './drama/project-list.css'import './shortVideoList.css'@@ -357,7 +358,7 @@ export default function HistoryPage() {status={{ label: STATUS_CN[p.status] || p.status, tone: p.status === 'DONE' ? 'completed' : running ? 'producing' : p.status === 'DRAFT' ? 'draft' : 'neutral' }}description={p.source_text || t('history.workflowHint')}progress={running ? { label: t('history.progress'), value: Math.max(0, Math.min(100, p.progress)), total: 100 } : undefined}- meta={p.error_msg ? <span className="pf-error" role="status">{p.error_msg}</span> : undefined}+ meta={p.error_msg ? <span className="pf-error" role="status">{formatGenerationErrorMessage(p.error_msg)}</span> : undefined}footer={<><span>{p.published ? t('history.published') : (p.pipeline_mode === 'image_text' ? t('history.typeImageText') : t('history.typeFull'))}</span><time dateTime={p.updated_at || p.created_at}>{formatDateTime(p.updated_at || p.created_at, locale)}</time>diff --git a/frontend/src/pages/drama/canvas/CanvasWorkspace.tsx b/frontend/src/pages/drama/canvas/CanvasWorkspace.tsxindex 97e1ce7..cfa6b5a 100644--- a/frontend/src/pages/drama/canvas/CanvasWorkspace.tsx+++ b/frontend/src/pages/drama/canvas/CanvasWorkspace.tsx@@ -10,6 +10,7 @@ import { CanvasTopBar } from './CanvasTopBar'import { getViewportCenterNodePosition } from './canvasNormalize'import { CANVAS_NODE_SIZE, type CanvasNodeKind } from './canvasTypes'import { FreeCanvasFlow } from './FreeCanvasFlow'+import { formatGenerationErrorMessage } from '../../../lib/generationError'import './canvas.css'type CanvasWorkspaceProps = {@@ -77,7 +78,7 @@ function CanvasWorkspaceContent({{showNodeSelector ? <CanvasNodeSelector onSelect={handleSelectNode} /> : null}{errorMessage ? (<p className="fc-error-toast" role="alert" onAnimationEnd={() => setErrorMessage('')}>- {errorMessage}+ {formatGenerationErrorMessage(errorMessage)}</p>) : null}{loading ? (diff --git a/frontend/tests/generation-error.test.mjs b/frontend/tests/generation-error.test.mjsnew file mode 100644index 0000000..3421233--- /dev/null+++ b/frontend/tests/generation-error.test.mjs@@ -0,0 +1,51 @@+import test from 'node:test'+import assert from 'node:assert/strict'+import { formatCopyrightError, formatGenerationErrorMessage } from '../src/lib/generationError.ts'++const requestId = '02179317708119300000000000000000000ffffac182c4fcb7e6'+const raw = `RuntimeError: The request failed because the output video may be related to copyright restrictions. Request id: ${requestId}`++test('版权审核失败显示中文原因和处理建议,并保留完整请求编号', () => {+ const view = formatCopyrightError(raw)+ assert.equal(view.title, '视频未通过版权审核')+ assert.match(view.message, /可能涉及版权限制/)+ assert.equal(view.requestId, requestId)+ assert.ok(view.message.includes(requestId))+ assert.match(view.suggestion, /提示词|参考素材/)+ assert.match(view.suggestion, /客服/)+ assert.doesNotMatch(formatGenerationErrorMessage(raw), /RuntimeError|The request failed|Request id:/)+ assert.doesNotMatch(formatGenerationErrorMessage(raw), /已退款|不扣费|确认侵权|参考图疑似真人/)+})++test('识别复制时丢空格、换行和紧贴冒号的上游文案', () => {+ const pasted = `RuntimeError: The request failed because the outputvideo may be related to copyright restrictions. Request\nid:\n${requestId}`+ assert.equal(formatCopyrightError(pasted).requestId, requestId)+ assert.equal(formatCopyrightError(pasted).title, '视频未通过版权审核')+})++test('上游版权错误码优先于泛化的敏感内容或网络描述', () => {+ const view = formatCopyrightError(`TokenFree https://www.tokenfree.com/v1/videos: OutputVideoSensitiveContentDetected.PolicyViolation RequestID:${requestId}`)+ assert.equal(view.title, '视频未通过版权审核')+ assert.equal(view.requestId, requestId)+})++test('兼容已翻译的版权文案和结构化请求编号', () => {+ assert.equal(formatCopyrightError(`请求失败,因为输出视频可能涉及版权限制。请求编号:${requestId}`).requestId, requestId)+ assert.equal(formatCopyrightError(JSON.stringify({ code: 'OutputVideoSensitiveContentDetected.PolicyViolation', request_id: requestId })).requestId, requestId)+})++test('未记录请求编号时仍提供完整建议,不生成占位编号', () => {+ const view = formatCopyrightError('OutputVideoSensitiveContentDetected.PolicyViolation')+ assert.equal(view.requestId, undefined)+ assert.doesNotMatch(view.message, /undefined|null|请求编号/)+ assert.match(formatGenerationErrorMessage('OutputVideoSensitiveContentDetected.PolicyViolation'), /联系客服/)+})++test('非版权审核、网络、计费与普通错误继续使用原文', () => {+ for (const message of ['OutputVideoSensitiveContentDetected', 'InputImageSensitiveContentDetected.PrivacyInformation', 'ConnectTimeout', '余额不足,请先充值', ' 模型暂不可用 ', 'copyright notice']) {+ assert.equal(formatCopyrightError(message), null)+ assert.equal(formatGenerationErrorMessage(message), message)+ }+ assert.equal(formatGenerationErrorMessage(null), '')+ assert.equal(formatGenerationErrorMessage(undefined), '')+})diff --git a/frontend/tests/generation-task-history.test.mjs b/frontend/tests/generation-task-history.test.mjsindex 0070d54..5f20798 100644--- a/frontend/tests/generation-task-history.test.mjs+++ b/frontend/tests/generation-task-history.test.mjs@@ -57,6 +57,18 @@ test('尚未产出媒体的任务详情显示可读状态或错误', () => {assert.equal(failed.params.textContent, '模型暂不可用')})+test('版权审核失败详情显示中文建议并保留请求编号,不修改原始错误', () => {+ const requestId = '02179317708119300000000000000000000ffffac182c4fcb7e6'+ const error = `RuntimeError: The request failed because the outputvideo may be related to copyright restrictions. Request id: ${requestId}`+ const failedRecord = { ...record, kind: 'video', status: 'failed', error }+ const failed = toolRunDetailAsset(failedRecord)+ assert.match(failed.params.textContent, /版权/)+ assert.match(failed.params.textContent, /调整|更换|修改/)+ assert.ok(failed.params.textContent.includes(requestId))+ assert.doesNotMatch(failed.params.textContent, /RuntimeError|The request failed/)+ assert.equal(failedRecord.error, error)+})+test('成功媒体仍按所选结果预览,视频首帧不能作为成片地址', () => {const asset = toolRunDetailAsset({ ...record, kind: 'video', urls: ['/static/a.mp4', '/static/b.mp4'], preview_url: '/static/frame.png' }, 1)assert.equal(asset.type, 'video')