Compare commits
9
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d60b30e7d6 | ||
|
|
6917b6faf3 | ||
|
|
c00db123f7 | ||
|
|
087e74a025 | ||
|
|
59e6af3877 | ||
|
|
adf10afda5 | ||
|
|
dde45fb4e9 | ||
|
|
c312ac9aba | ||
|
|
a85f7b7bbc |
No files matched your search
@@ -4,6 +4,37 @@
|
||||
|
||||
---
|
||||
|
||||
## 2026-11-17
|
||||
|
||||
### ✨ AI 一键出片:按标题和图片自动生成视频封面
|
||||
|
||||
- 新增 `generateQuickVideoCover()`(`src/utils/aiQuickVideo.ts`):根据用户输入的**标题 + 素材图片 + 正文**自动生成一张封面图
|
||||
- 提示词三级降级:视觉模型看图写英文生图提示词 → 纯文本模型按标题/正文写 → 标题拼模板提示词,保证封面永远能出
|
||||
- 生图两级降级:先试 16:9(1280x720),失败回退网关默认尺寸;再失败由调用方用本地 `makeTitleCover()` 标题封面兜底(界面明确提示「AI 生图失败,已用本地封面代替」)
|
||||
- 远程生图链接自动转 data URL,避免工程保存后链接过期导致封面裂图;转不动则保持原地址
|
||||
- 向导流程改动(`QuickVideo.tsx`):
|
||||
- 第 1 步「生成文案」时**文案与封面并行生成**(封面只依赖标题/图片/正文,不必等文案),loading 文案改为「正在识别图片写文案、生成封面…」
|
||||
- 第 4 步确认页新增封面预览行:缩略图 + 状态(AI 生成 / 本地标题封面 / 生成中 / 失败原因);「预计成片」与页脚「总长约」计入封面 3 秒
|
||||
- 「确认生成视频」在封面未就绪时拦截提示;封面插到**时间轴最前面 3 秒**(无配音无字幕,与后续画面同轨道,吃同样的转场/运镜设置)
|
||||
- 收尾 Toast 带「封面 +」前缀;`resetAll` 清理封面状态
|
||||
- 样式:`quickvideo.module.less` 新增 `.coverRow/.coverThumb/.coverInfo`(132×74 缩略图 + 虚线分隔)
|
||||
- 第 1 步说明文案同步提及「根据标题和图片自动生成视频封面(片头 3 秒)」
|
||||
|
||||
---
|
||||
|
||||
## 2026-11-14
|
||||
|
||||
### 🛡️ MCP 每 IP 每日 5 次限流(防刷爆)
|
||||
|
||||
- `_AuthMiddleware` 新增按客户端 IP 的日配额:只对 `POST /mcp`(真正工具调用)计数,优先取 `X-Forwarded-For` 第一段(反代场景仍按真实客户端 IP),按北京时间 00:00 日期键重置,计数存内存、容器重启清零,默认 **5 次/天/IP**(env `MCP_DAILY_LIMIT` 可调)
|
||||
- 超限返回 `429 Too Many Requests`,响应体带 `{"error":"rate_limited","limit":5,"used":5,"ip":...}` 中文提示,头带 `Retry-After: 86400`
|
||||
- 鉴权在前(未带/错令牌 401 且不消耗配额)、限流在后;`/health`、`/mcp-health`、`/out/*` 下载直链不参与计数
|
||||
- 教程同步:`mcp-guide.md` 端点小节新增「限流规则」小块(5 次/天、429、重置时间、可调参数、只计 POST /mcp),常见问题新增第 9 条「调用提示 429 rate_limited」
|
||||
- 验证:线上同 IP 带令牌连发 7 次——第 1~5 次放行进入协议层(400 Missing session ID 属正常未握手响应),第 6、7 次 429 + Retry-After: 86400;验毕重启容器清零计数;教程 `/articles/mcp-guide.md` 线上 12590B 与源码逐字节一致
|
||||
- Release:`v1.0.2-mcp-rate-limit`(Gitea #811,无附件)
|
||||
|
||||
---
|
||||
|
||||
## 2026-11-12
|
||||
|
||||
### ✨ 教程页三栏重排版(/article/* 可读性优化)
|
||||
|
||||
@@ -49,7 +49,7 @@
|
||||
| 开源入口 | 编辑器右上角新增「开源地址」按钮,一键直达源码仓库 gitee.com/jinghui111/unicut |
|
||||
| AI 面板瘦身 | 左侧「AI创作」移除「AI 视频生成 / AI 图片生成」页签,保留一键出片与生成结果;生图 / 生视频走 AI 助手对话 |
|
||||
| 首页去背书 | 移除首页「受到众多大品牌信赖」与 UCAP / 圆通 / 中国电信 / 中国移动 品牌 logo 背书区 |
|
||||
| AI 一键出片 | 添加图片 → AI 生成口播文案 → 13 种人声配音试听 → 一键排入时间轴,转场 / 动效 / 字幕样式可调 |
|
||||
| AI 一键出片 | 添加图片 → AI 生成口播文案 + 按标题和图片自动生成视频封面(片头 3 秒)→ 13 种人声配音试听 → 一键排入时间轴,转场 / 动效 / 字幕样式可调 |
|
||||
| 模板导入修复 | 修复"导入第一个模板后,再导入会把浏览器拖崩"的问题,支持连续换模板 |
|
||||
| 品牌与首页 | 产品名改为米剪,首页新增导航站 / 开源地址入口,移除收费栏目与账号类外链 |
|
||||
| 接入授权中心 | 版本号、公告、检查更新(授权中心不可达时静默降级,绝不拦功能) |
|
||||
|
||||
@@ -135,6 +135,8 @@ def classify(url, relpath, allow_rules):
|
||||
return 'doc', '文档里写的本机示例地址,不会发起请求'
|
||||
return 'local', '本机地址(残留的开发期配置)'
|
||||
if re.match(r'^(192\.168\.\d+|10\.\d+|172\.(1[6-9]|2\d|3[01])|169\.254)\.\d+$', host):
|
||||
if ext in DOC_EXT:
|
||||
return 'doc', '文档里写的内网示例地址,不会发起请求'
|
||||
return 'lan', '内网地址,仍会发起网络请求'
|
||||
if ext in DOC_EXT:
|
||||
return 'doc', '文档/Source Map 文件'
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
^http://\$$ allow pdf.worker 模板字面量 http://${A} 的提取截断产物,仅 new URL() 构造不发起请求
|
||||
^https://ai\.88531\.cn(/.*)?$ allow 自有域名:官方 AI 网关默认接口地址与「获取 Key」引导链接(产品默认配置本体,删掉功能即失效;断网时静默降级不拦功能)
|
||||
^https://nav\.88531\.cn(/.*)?$ allow 自有域名:首页导航站入口链接(纯跳转,断网时点击打不开但不影响编辑器功能)
|
||||
^https://doc\.88531\.cn(/.*)?$ allow 自有域名:素材下载文档站入口链接(window.open 纯跳转,断网时点击打不开但不影响编辑器功能)
|
||||
github\.com allow vendored 依赖(pixi/semi/opencv 等)压缩产物里的项目主页与许可证链接,仅字符串
|
||||
gist\.github\.com allow vendored 依赖 README 片段里的示例链接,仅字符串
|
||||
raw\.githubusercontent\.com allow vendored 依赖 README 片段里的源码链接,仅字符串
|
||||
|
||||
+93
-21
@@ -843,12 +843,53 @@ class _AuthMiddleware:
|
||||
- /health 监控探针(nginx /mcp-health 转发,无法附带鉴权头)
|
||||
- /out/* 工具产物下载直链(zip/mp3 交人浏览器点开,无法附带鉴权头)
|
||||
其余路径(含 MCP 协议端点 /mcp 与全部未知路径)必须携带
|
||||
Authorization: Bearer <MCP_AUTH_TOKEN>。
|
||||
Authorization: Bearer ***
|
||||
额外:对 POST /mcp 按客户端 IP 做每日调用上限(默认 5 次/天/IP,env MCP_DAILY_LIMIT 可调),
|
||||
超限返回 429 Too Many Requests。
|
||||
"""
|
||||
|
||||
OPEN_EXACT = ("/health",)
|
||||
OPEN_PREFIX = ("/out/",)
|
||||
|
||||
# ---- 每 IP 每日调用计数(内存,容器重启清零;按 UTC+8 日期键重置)
|
||||
DAILY_LIMIT = int(os.getenv("MCP_DAILY_LIMIT", "5"))
|
||||
_rate_lock = None # 延迟初始化(事件循环启动后)
|
||||
_rate_store: dict = {}
|
||||
|
||||
@classmethod
|
||||
def _get_lock(cls):
|
||||
import asyncio
|
||||
if cls._rate_lock is None:
|
||||
cls._rate_lock = asyncio.Lock()
|
||||
return cls._rate_lock
|
||||
|
||||
@classmethod
|
||||
async def _check_rate(cls, ip: str) -> tuple[bool, int]:
|
||||
"""返回 (allowed, used_count_after)。超限返回 (False, current_count)。"""
|
||||
import asyncio
|
||||
lock = cls._get_lock()
|
||||
from datetime import datetime, timezone, timedelta
|
||||
today = (datetime.now(timezone(timedelta(hours=8))).date().isoformat())
|
||||
async with lock:
|
||||
entry = cls._rate_store.setdefault(ip, {})
|
||||
# 清理旧日期键
|
||||
for d in [k for k in entry if k != today]:
|
||||
del entry[d]
|
||||
used = entry.get(today, 0)
|
||||
if used >= cls.DAILY_LIMIT:
|
||||
return False, used
|
||||
entry[today] = used + 1
|
||||
return True, entry[today]
|
||||
|
||||
@staticmethod
|
||||
def _client_ip(scope) -> str:
|
||||
headers = {k.decode("latin-1").lower(): v.decode("latin-1") for k, v in scope.get("headers", [])}
|
||||
xff = headers.get("x-forwarded-for", "")
|
||||
if xff:
|
||||
return xff.split(",")[0].strip()
|
||||
client = scope.get("client")
|
||||
return client[0] if client else "unknown"
|
||||
|
||||
def __init__(self, app):
|
||||
self.app = app
|
||||
|
||||
@@ -858,6 +899,7 @@ class _AuthMiddleware:
|
||||
return
|
||||
|
||||
path = scope.get("path", "")
|
||||
|
||||
if path in self.OPEN_EXACT or path.startswith(self.OPEN_PREFIX):
|
||||
await self.app(scope, receive, send)
|
||||
return
|
||||
@@ -869,28 +911,58 @@ class _AuthMiddleware:
|
||||
and got.startswith("Bearer ")
|
||||
and hmac.compare_digest(got[7:].strip(), AUTH_TOKEN) # 恒定时间比较,防时序侧信道
|
||||
)
|
||||
if authorized:
|
||||
await self.app(scope, receive, send)
|
||||
if not authorized:
|
||||
detail = (
|
||||
"MCP_AUTH_TOKEN not configured on server (fail-closed)"
|
||||
if not AUTH_TOKEN
|
||||
else "missing or invalid bearer token"
|
||||
)
|
||||
body = json.dumps({"ok": False, "error": "unauthorized", "detail": detail}, ensure_ascii=False).encode()
|
||||
await send(
|
||||
{
|
||||
"type": "http.response.start",
|
||||
"status": 401,
|
||||
"headers": [
|
||||
(b"content-type", b"application/json"),
|
||||
(b"content-length", str(len(body)).encode("ascii")),
|
||||
(b"www-authenticate", b'Bearer realm="unicut-mcp", charset="UTF-8"'),
|
||||
],
|
||||
}
|
||||
)
|
||||
await send({"type": "http.response.body", "body": body})
|
||||
return
|
||||
|
||||
detail = (
|
||||
"MCP_AUTH_TOKEN not configured on server (fail-closed)"
|
||||
if not AUTH_TOKEN
|
||||
else "missing or invalid bearer token"
|
||||
)
|
||||
body = json.dumps({"ok": False, "error": "unauthorized", "detail": detail}, ensure_ascii=False).encode()
|
||||
await send(
|
||||
{
|
||||
"type": "http.response.start",
|
||||
"status": 401,
|
||||
"headers": [
|
||||
(b"content-type", b"application/json"),
|
||||
(b"content-length", str(len(body)).encode("ascii")),
|
||||
(b"www-authenticate", b'Bearer realm="unicut-mcp", charset="UTF-8"'),
|
||||
],
|
||||
}
|
||||
)
|
||||
await send({"type": "http.response.body", "body": body})
|
||||
# ---- 每 IP 每日调用限流(仅 MCP 协议端点 /mcp 的 POST 计数)
|
||||
if path in ("/mcp", "/mcp/") and scope.get("method", "GET").upper() == "POST":
|
||||
ip = self._client_ip(scope)
|
||||
allowed, used = await self._check_rate(ip)
|
||||
if not allowed:
|
||||
body = json.dumps(
|
||||
{
|
||||
"ok": False,
|
||||
"error": "rate_limited",
|
||||
"detail": f"该 IP 今日 MCP 调用已达上限({self.DAILY_LIMIT} 次/天),明日 00:00 重置",
|
||||
"limit": self.DAILY_LIMIT,
|
||||
"used": used,
|
||||
"ip": ip,
|
||||
},
|
||||
ensure_ascii=False,
|
||||
).encode()
|
||||
await send(
|
||||
{
|
||||
"type": "http.response.start",
|
||||
"status": 429,
|
||||
"headers": [
|
||||
(b"content-type", b"application/json"),
|
||||
(b"content-length", str(len(body)).encode("ascii")),
|
||||
(b"retry-after", b"86400"),
|
||||
],
|
||||
}
|
||||
)
|
||||
await send({"type": "http.response.body", "body": body})
|
||||
return
|
||||
|
||||
await self.app(scope, receive, send)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "aacut",
|
||||
"private": true,
|
||||
"version": "1.0.1",
|
||||
"version": "1.0.6",
|
||||
"scripts": {
|
||||
"dev": "vite",
|
||||
"build": "yarn clean && node scripts/patch-sdk-offline.mjs && yarn build:worker && vite build",
|
||||
|
||||
@@ -70,7 +70,9 @@
|
||||
- **标题**(最多 30 字,例:三步搞定一张海报)——它决定文案的主题方向,别留空
|
||||
- **文案风格**五选一:口播解说(自然口语)/ 教程讲解(步骤清晰)/ 种草安利(卖点前置)/ 情感旁白(文艺留白)/ 新闻播报(客观密度高)
|
||||
|
||||
底部实时显示「素材池 N/8 张图片 · 正文 X 字」。素材齐了点右下角主按钮——按钮文案随方式变化:**「① 识别图片 · 生成文案」/「① 读取文档 · 生成文案」/「① 分析网页 · 生成文案」**。没选素材就点,会提示「请先添加图片」/「请先上传 Word / PDF 文档」/「请先抓取网址内容」。
|
||||
底部实时显示「素材池 N/8 张图片 · 正文 X 字」。素材齐了点右下角主按钮——按钮文案随方式变化:**「① 识别图片 · 生成文案」/「① 读取文档 · 生成文案」/「① 分析网页 · 生成文案」**(生成时按钮会变成「正在识别图片写文案、生成封面…」,文案和封面是并行生成的)。没选素材就点,会提示「请先添加图片」/「请先上传 Word / PDF 文档」/「请先抓取网址内容」。
|
||||
|
||||
点下去之后 AI 会做两件事:按素材写口播文案,同时**根据你输入的标题和图片自动生成一张视频封面**(片头 3 秒,确认页可预览;生图失败会自动换成本地标题封面兜底)。
|
||||
|
||||

|
||||
*图:第 1 步:选素材类型、上传图片、填标题、挑文案风格*
|
||||
@@ -122,7 +124,8 @@
|
||||
|
||||
下方信息栏逐项汇总你要生成的东西:
|
||||
|
||||
- 图片 N 张 · 口播 M 段 · **预计成片 X 秒**
|
||||
- **视频封面**:缩略图 + 状态(「AI 按标题和图片生成」/「本地标题封面」;还在生成时显示转圈「AI 正在根据标题和图片生成封面…」)
|
||||
- 图片 N 张 · 口播 M 段 · **预计成片 X 秒**(已含封面 3 秒)
|
||||
- 转场 / 动效选择 · 共 N-1 个转场
|
||||
- 字幕位置 · 大小 · 配色 · 入场
|
||||
- 人声 · 情绪 · 语速
|
||||
@@ -130,9 +133,9 @@
|
||||
|
||||
⚠ **注意红字提示:「生成字幕会覆盖当前工程已有的字幕。」**——如果你在时间轴上已有手动字幕,先想清楚再继续(建议新工程做一键出片)。
|
||||
|
||||
确认无误点 **「③ 确认生成视频(总长约 X 秒)」**(某段配音没就绪时按钮灰色)。成功提示:
|
||||
确认无误点 **「③ 确认生成视频(总长约 X 秒)」**(某段配音没就绪、或封面还在生成时按钮会拦截提示)。成功提示:
|
||||
|
||||
> 已生成 N 段:图片(带动效)、配音、字幕已就位,X 个转场
|
||||
> 封面 + 已生成 N 段:图片(带动效)、配音、字幕已就位,X 个转场
|
||||
|
||||
弹窗自动关闭。失败时显示「生成失败:原因」,按提示处理后重来。
|
||||
|
||||
@@ -144,6 +147,7 @@
|
||||
回到时间轴,你会看到:
|
||||
|
||||
- **图片**按顺序排在同一条轨道(转场要求同轨道相邻,别挪散)
|
||||
- **视频封面**在最前面单独 3 秒(AI 按标题和图片生成,无配音无字幕)
|
||||
- **配音**在另一条独立轨道,与图片错开避免撞车
|
||||
- **字幕**已按段生成
|
||||
- 图片带运镜动效(推近 / 拉远 / 平移的关键帧)
|
||||
@@ -176,7 +180,10 @@
|
||||
**7. 传的纯文档没有一张图怎么办?**
|
||||
不用管:无配图时自动生成一张标题封面兜底,时间轴一定有画面;想要更好效果就在第 1 步补传图片。
|
||||
|
||||
**8. 生成的文案太书面 / 太长?**
|
||||
**8. 封面是 AI 生成的吗?能换吗?**
|
||||
封面根据你输入的标题和素材图片自动生成,放在片头 3 秒。如果提示「AI 生图失败,已用本地封面代替」,一般是 Key 额度或网关生图接口的问题——回第 1 步重新点生成即可重试。
|
||||
|
||||
**9. 生成的文案太书面 / 太长?**
|
||||
第 2 步整段随便改,或回第 1 步换「文案风格」重新生成;段落之间换图、删段都很方便。
|
||||
|
||||
## 十、相关链接
|
||||
|
||||
@@ -29,6 +29,9 @@
|
||||
- 令牌错误或没带 → 返回 `401 {"error":"unauthorized"}`,客户端里表现为「连接失败 / 401」
|
||||
- **健康检查**:`https://cut.88531.cn/mcp-health`(返回容器健康状态 JSON)
|
||||
- ⚠ `/mcp/health` **不是**端点——它会被前端回退成首页 HTML,别拿它测
|
||||
- **限流**:每个客户端 IP 每天最多调用 **5 次**(按北京时间 00:00 重置,`env MCP_DAILY_LIMIT` 可调)——这是为了防止被刷爆;超限返回 `429 {"error":"rate_limited"}`,响应头带 `Retry-After: 86400`,等次日即可恢复
|
||||
- 限流只计 **POST /mcp**(真正的工具调用),`/mcp-health`、`/mcp-out/*` 下载链接不受限
|
||||
- 限流按 IP 识别(优先 `X-Forwarded-For`,反代场景下仍按真实客户端 IP 计);容器重启清零计数
|
||||
|
||||
## 三、接入你的 AI 客户端(四选一)
|
||||
|
||||
@@ -226,6 +229,9 @@ docker compose up -d --build unicut-mcp
|
||||
**8. AI 说「找不到 unicut 这组工具」?**
|
||||
客户端没加载成功:确认配置文件路径、URL、令牌后**重启客户端**;命令行客户端可用第六节 curl 先验证服务本身是通的。
|
||||
|
||||
**9. 调用提示 `429 rate_limited`(每天每 IP 5 次上限)?**
|
||||
服务端对每个客户端 IP 每天最多放行 5 次 MCP 调用(按北京时间 00:00 重置)。超限后等次日再试,或让站点管理员调高 `MCP_DAILY_LIMIT` 环境变量并重建容器。注意 `/mcp-health` 与下载链接不受限。
|
||||
|
||||
## 九、相关链接
|
||||
|
||||
- [AI 一键出片新手教程](/article/about) —— 站内四步出片的完整操作
|
||||
|
||||
@@ -0,0 +1,128 @@
|
||||
#!/usr/bin/env python3
|
||||
"""复现:项目列表卡片改名是否真正落库/刷新后是否保留。
|
||||
用法: python3 scripts/dbg_rename.py
|
||||
"""
|
||||
import sys, asyncio, json
|
||||
|
||||
BASE = "https://127.0.0.1:3005"
|
||||
|
||||
|
||||
async def main():
|
||||
from playwright.async_api import async_playwright
|
||||
async with async_playwright() as p:
|
||||
browser = await p.chromium.launch(args=["--ignore-certificate-errors"])
|
||||
ctx = await browser.new_context(ignore_https_errors=True,
|
||||
viewport={"width": 1600, "height": 900})
|
||||
page = await ctx.new_page()
|
||||
errs = []
|
||||
page.on("pageerror", lambda e: errs.append(str(e)))
|
||||
|
||||
await page.goto(f"{BASE}/workspace/draft", wait_until="domcontentloaded", timeout=120000)
|
||||
await page.wait_for_timeout(5000)
|
||||
|
||||
# 预置本地存储文件夹句柄(与 e2e_quickvideo_cover.py 的 GUARD 一致)
|
||||
GUARD = """async () => {
|
||||
try {
|
||||
const root = await navigator.storage.getDirectory();
|
||||
const db = await new Promise((res, rej) => {
|
||||
const rq = indexedDB.open('H5VideoLocalDB');
|
||||
rq.onupgradeneeded = () => rq.result.createObjectStore('folderHandles');
|
||||
rq.onsuccess = () => res(rq.result);
|
||||
rq.onerror = () => rej(rq.error);
|
||||
});
|
||||
const done = await new Promise((res, rej) => {
|
||||
const tx = db.transaction('folderHandles', 'readwrite');
|
||||
const st = tx.objectStore('folderHandles');
|
||||
const rec = { id: 'root', handle: root };
|
||||
if (st.keyPath) st.put(rec); else st.put(rec, 'root');
|
||||
tx.oncomplete = () => res(true);
|
||||
tx.onerror = () => rej(tx.error);
|
||||
});
|
||||
db.close();
|
||||
return done;
|
||||
} catch (e) { return String(e); }
|
||||
}"""
|
||||
print("GUARD:", await page.evaluate(GUARD))
|
||||
await page.reload(wait_until="domcontentloaded")
|
||||
await page.wait_for_timeout(6000)
|
||||
|
||||
print("URL:", page.url)
|
||||
print("TITLE:", await page.title())
|
||||
|
||||
# 若无项目,先创建一个
|
||||
if await page.locator("input[class*='__name__']").count() == 0:
|
||||
btn = page.get_by_text("创建项目", exact=True).first
|
||||
if await btn.count():
|
||||
await btn.click()
|
||||
await page.wait_for_timeout(6000)
|
||||
# 创建后可能跳进编辑器,返回列表
|
||||
if "workspace/draft" not in page.url:
|
||||
await page.goto(f"{BASE}/workspace/draft", wait_until="domcontentloaded", timeout=120000)
|
||||
await page.wait_for_timeout(5000)
|
||||
print("创建后 name input count:", await page.locator("input[class*='__name__']").count())
|
||||
|
||||
# 列表卡片名输入框
|
||||
inputs = page.locator("input[class*='__name__']")
|
||||
n = await inputs.count()
|
||||
print("input.title count:", n)
|
||||
if n == 0:
|
||||
# 打印可见输入框与页面骨架
|
||||
allin = page.locator("input")
|
||||
print("all input count:", await allin.count())
|
||||
for i in range(min(await allin.count(), 8)):
|
||||
el = allin.nth(i)
|
||||
print(" input", i, await el.get_attribute("class"),
|
||||
repr(await el.get_attribute("value")),
|
||||
"visible=", await el.is_visible())
|
||||
print("BODY:", (await page.inner_text("body"))[:600])
|
||||
await browser.close()
|
||||
return 1
|
||||
|
||||
old = await inputs.first.get_attribute("value")
|
||||
print("原名:", repr(old))
|
||||
|
||||
# 聚焦 + 全选 + 输入 + 失焦
|
||||
await inputs.first.click()
|
||||
await page.keyboard.press("Control+a")
|
||||
await page.keyboard.type("RENAME_TEST_001")
|
||||
await page.keyboard.press("Tab")
|
||||
await page.wait_for_timeout(2000)
|
||||
|
||||
val_after = await inputs.first.input_value()
|
||||
print("失焦后输入框:", repr(val_after))
|
||||
|
||||
# 读 IndexedDB projects 表
|
||||
async def read_meta():
|
||||
return await page.evaluate("""async () => {
|
||||
try {
|
||||
const rq = indexedDB.open('H5VideoLocalDB');
|
||||
const db = await new Promise((res, rej) => { rq.onsuccess=()=>res(rq.result); rq.onerror=()=>rej(rq.error); });
|
||||
const tx = db.transaction('projects','readonly');
|
||||
const all = await new Promise((res, rej) => {
|
||||
const r = tx.objectStore('projects').getAll();
|
||||
r.onsuccess=()=>res(r.result); r.onerror=()=>rej(r.error);
|
||||
});
|
||||
return all.map(x => ({id:x.id, name:x.name, updatedAt:x.updatedAt}));
|
||||
} catch(e){ return 'ERR:'+e; }
|
||||
}""")
|
||||
|
||||
meta1 = await read_meta()
|
||||
print("失焦后 IndexedDB:", json.dumps(meta1, ensure_ascii=False))
|
||||
|
||||
# 刷新
|
||||
await page.reload(wait_until="domcontentloaded")
|
||||
await page.wait_for_timeout(5000)
|
||||
inputs2 = page.locator("input[class*='__name__']")
|
||||
n2 = await inputs2.count()
|
||||
print("刷新后 input.title count:", n2)
|
||||
if n2:
|
||||
print("刷新后输入框值:", repr(await inputs2.first.input_value()))
|
||||
meta2 = await read_meta()
|
||||
print("刷新后 IndexedDB:", json.dumps(meta2, ensure_ascii=False))
|
||||
|
||||
print("JS errors:", errs[:5])
|
||||
await browser.close()
|
||||
return 0
|
||||
|
||||
|
||||
sys.exit(asyncio.run(main()))
|
||||
@@ -0,0 +1,112 @@
|
||||
#!/usr/bin/env python3
|
||||
"""复现用户路径: ①改名按回车 ②改名后立即点开项目再返回列表 ③改名后失焦点空白处"""
|
||||
import sys, asyncio, json
|
||||
|
||||
BASE = "https://127.0.0.1:3005"
|
||||
|
||||
GUARD = """async () => {
|
||||
try {
|
||||
const root = await navigator.storage.getDirectory();
|
||||
const db = await new Promise((res, rej) => {
|
||||
const rq = indexedDB.open('H5VideoLocalDB');
|
||||
rq.onupgradeneeded = () => rq.result.createObjectStore('folderHandles');
|
||||
rq.onsuccess = () => res(rq.result);
|
||||
rq.onerror = () => rej(rq.error);
|
||||
});
|
||||
await new Promise((res, rej) => {
|
||||
const tx = db.transaction('folderHandles', 'readwrite');
|
||||
const st = tx.objectStore('folderHandles');
|
||||
const rec = { id: 'root', handle: root };
|
||||
if (st.keyPath) st.put(rec); else st.put(rec, 'root');
|
||||
tx.oncomplete = () => res(true);
|
||||
tx.onerror = () => rej(tx.error);
|
||||
});
|
||||
db.close();
|
||||
return 'ok';
|
||||
} catch (e) { return String(e); }
|
||||
}"""
|
||||
|
||||
READ_META = """async () => {
|
||||
try {
|
||||
const rq = indexedDB.open('H5VideoLocalDB');
|
||||
const db = await new Promise((res, rej) => { rq.onsuccess=()=>res(rq.result); rq.onerror=()=>rej(rq.error); });
|
||||
const tx = db.transaction('projects','readonly');
|
||||
const all = await new Promise((res, rej) => {
|
||||
const r = tx.objectStore('projects').getAll();
|
||||
r.onsuccess=()=>res(r.result); r.onerror=()=>rej(r.error);
|
||||
});
|
||||
return all.map(x => ({id:x.id, name:x.name, dtitle:(x.data&&x.data.title)||null}));
|
||||
} catch(e){ return 'ERR:'+e; }
|
||||
}"""
|
||||
|
||||
|
||||
async def main():
|
||||
from playwright.async_api import async_playwright
|
||||
async with async_playwright() as p:
|
||||
browser = await p.chromium.launch(args=["--ignore-certificate-errors"])
|
||||
ctx = await browser.new_context(ignore_https_errors=True,
|
||||
viewport={"width": 1600, "height": 900})
|
||||
page = await ctx.new_page()
|
||||
errs = []
|
||||
page.on("pageerror", lambda e: errs.append(str(e)))
|
||||
|
||||
await page.goto(f"{BASE}/workspace/draft", wait_until="domcontentloaded", timeout=120000)
|
||||
await page.wait_for_timeout(4000)
|
||||
await page.evaluate(GUARD)
|
||||
await page.reload(wait_until="domcontentloaded")
|
||||
await page.wait_for_timeout(6000)
|
||||
|
||||
inputs = page.locator("input[class*='__name__']")
|
||||
if await inputs.count() == 0:
|
||||
btn = page.get_by_text("创建项目", exact=True).first
|
||||
await btn.click()
|
||||
await page.wait_for_timeout(6000)
|
||||
if "workspace/draft" not in page.url:
|
||||
await page.goto(f"{BASE}/workspace/draft", wait_until="domcontentloaded")
|
||||
await page.wait_for_timeout(5000)
|
||||
inputs = page.locator("input[class*='__name__']")
|
||||
|
||||
print("卡片数:", await inputs.count())
|
||||
print("初始:", json.dumps(await page.evaluate(READ_META), ensure_ascii=False))
|
||||
|
||||
# ① 改名 + 按回车(不点别处)
|
||||
await inputs.first.click()
|
||||
await page.keyboard.press("Control+a")
|
||||
await page.keyboard.type("VIA_ENTER_KEY")
|
||||
await page.keyboard.press("Enter")
|
||||
await page.wait_for_timeout(2500)
|
||||
print("①回车后 input:", repr(await inputs.first.input_value()))
|
||||
print("①回车后 DB:", json.dumps(await page.evaluate(READ_META), ensure_ascii=False))
|
||||
|
||||
# ② 改名后立即点开第一张卡片(打开项目)
|
||||
await inputs.first.click()
|
||||
await page.keyboard.press("Control+a")
|
||||
await page.keyboard.type("VIA_OPEN_PROJECT")
|
||||
await page.keyboard.press("Tab")
|
||||
await page.wait_for_timeout(1500)
|
||||
print("②失焦后 DB:", json.dumps(await page.evaluate(READ_META), ensure_ascii=False))
|
||||
# 点卡片标题区打开项目
|
||||
card_a = page.locator("a[href*='/editor/']").first
|
||||
if await card_a.count():
|
||||
await card_a.click()
|
||||
await page.wait_for_timeout(8000)
|
||||
print("②打开后 URL:", page.url)
|
||||
# 编辑器顶栏标题
|
||||
t = await page.evaluate("""() => {
|
||||
const el = document.querySelector('input[placeholder]');
|
||||
return el ? el.value : null;
|
||||
}""")
|
||||
print("②编辑器标题输入框:", repr(t))
|
||||
print("②DB(编辑器内):", json.dumps(await page.evaluate(READ_META), ensure_ascii=False))
|
||||
# 返回列表
|
||||
await page.goto(f"{BASE}/workspace/draft", wait_until="domcontentloaded")
|
||||
await page.wait_for_timeout(6000)
|
||||
inputs = page.locator("input[class*='__name__']")
|
||||
print("②返回列表 input:", repr(await inputs.first.input_value()) if await inputs.count() else "N/A")
|
||||
print("②返回后 DB:", json.dumps(await page.evaluate(READ_META), ensure_ascii=False))
|
||||
|
||||
print("JS errors:", errs[:5])
|
||||
await browser.close()
|
||||
|
||||
|
||||
sys.exit(asyncio.run(main()))
|
||||
@@ -0,0 +1,102 @@
|
||||
#!/usr/bin/env python3
|
||||
"""反向同步验证:列表卡片改名 -> 打开编辑器顶栏显示新名 -> 再改顶栏 -> 回列表"""
|
||||
import sys, asyncio, json
|
||||
|
||||
BASE = "https://127.0.0.1:3005"
|
||||
|
||||
GUARD = """async () => {
|
||||
try {
|
||||
const root = await navigator.storage.getDirectory();
|
||||
const db = await new Promise((res, rej) => {
|
||||
const rq = indexedDB.open('H5VideoLocalDB');
|
||||
rq.onupgradeneeded = () => rq.result.createObjectStore('folderHandles');
|
||||
rq.onsuccess = () => res(rq.result);
|
||||
rq.onerror = () => rej(rq.error);
|
||||
});
|
||||
await new Promise((res, rej) => {
|
||||
const tx = db.transaction('folderHandles', 'readwrite');
|
||||
const st = tx.objectStore('folderHandles');
|
||||
const rec = { id: 'root', handle: root };
|
||||
if (st.keyPath) st.put(rec); else st.put(rec, 'root');
|
||||
tx.oncomplete = () => res(true);
|
||||
tx.onerror = () => rej(tx.error);
|
||||
});
|
||||
db.close();
|
||||
return 'ok';
|
||||
} catch (e) { return String(e); }
|
||||
}"""
|
||||
|
||||
READ_META = """async () => {
|
||||
try {
|
||||
const rq = indexedDB.open('H5VideoLocalDB');
|
||||
const db = await new Promise((res, rej) => { rq.onsuccess=()=>res(rq.result); rq.onerror=()=>rej(rq.error); });
|
||||
const tx = db.transaction('projects','readonly');
|
||||
const all = await new Promise((res, rej) => {
|
||||
const r = tx.objectStore('projects').getAll();
|
||||
r.onsuccess=()=>res(r.result); r.onerror=()=>rej(r.error);
|
||||
});
|
||||
return all.map(x => ({id:x.id, name:x.name, dtitle:(x.data&&x.data.title)||null}));
|
||||
} catch(e){ return 'ERR:'+e; }
|
||||
}"""
|
||||
|
||||
|
||||
async def main():
|
||||
from playwright.async_api import async_playwright
|
||||
async with async_playwright() as p:
|
||||
browser = await p.chromium.launch(args=["--ignore-certificate-errors"])
|
||||
ctx = await browser.new_context(ignore_https_errors=True,
|
||||
viewport={"width": 1600, "height": 900})
|
||||
page = await ctx.new_page()
|
||||
errs = []
|
||||
page.on("pageerror", lambda e: errs.append(str(e)))
|
||||
|
||||
await page.goto(f"{BASE}/workspace/draft", wait_until="domcontentloaded", timeout=120000)
|
||||
await page.wait_for_timeout(4000)
|
||||
await page.evaluate(GUARD)
|
||||
await page.reload(wait_until="domcontentloaded")
|
||||
await page.wait_for_timeout(6000)
|
||||
|
||||
inputs = page.locator("input[class*='__name__']")
|
||||
if await inputs.count() == 0:
|
||||
btn = page.get_by_text("创建项目", exact=True).first
|
||||
await btn.click()
|
||||
await page.wait_for_timeout(6000)
|
||||
if "workspace/draft" not in page.url:
|
||||
await page.goto(f"{BASE}/workspace/draft", wait_until="domcontentloaded")
|
||||
await page.wait_for_timeout(5000)
|
||||
inputs = page.locator("input[class*='__name__']")
|
||||
|
||||
# ① 列表改名
|
||||
await inputs.first.click()
|
||||
await page.keyboard.press("Control+a")
|
||||
await page.keyboard.type("LIST_RENAME_X")
|
||||
await page.keyboard.press("Tab")
|
||||
await page.wait_for_timeout(2500)
|
||||
print("①列表改名后 DB:", json.dumps(await page.evaluate(READ_META), ensure_ascii=False))
|
||||
|
||||
# ② 打开项目,看顶栏
|
||||
await page.locator("div[class*='__item__'] a").first.click()
|
||||
await page.wait_for_timeout(10000)
|
||||
inp = page.locator("#projectName")
|
||||
top = await inp.input_value() if await inp.count() else "N/A"
|
||||
print("②顶栏显示:", repr(top), "PASS" if top == "LIST_RENAME_X" else "FAIL")
|
||||
|
||||
# ③ 顶栏再改 -> 回列表
|
||||
await inp.click()
|
||||
await page.keyboard.press("Control+a")
|
||||
await page.keyboard.type("TOPBAR_RENAME_Y")
|
||||
await inp.press("Tab") # 触发失焦即时同步
|
||||
await page.wait_for_timeout(2500)
|
||||
print("③顶栏改后 DB:", json.dumps(await page.evaluate(READ_META), ensure_ascii=False))
|
||||
|
||||
await page.goto(f"{BASE}/workspace/draft", wait_until="domcontentloaded")
|
||||
await page.wait_for_timeout(6000)
|
||||
inputs2 = page.locator("input[class*='__name__']")
|
||||
v = await inputs2.first.input_value() if await inputs2.count() else "N/A"
|
||||
print("④回列表卡片名:", repr(v), "PASS" if v == "TOPBAR_RENAME_Y" else "FAIL")
|
||||
print("④DB:", json.dumps(await page.evaluate(READ_META), ensure_ascii=False))
|
||||
print("JS errors:", errs[:5])
|
||||
await browser.close()
|
||||
|
||||
|
||||
sys.exit(asyncio.run(main()))
|
||||
@@ -0,0 +1,119 @@
|
||||
#!/usr/bin/env python3
|
||||
"""复现:编辑器顶栏项目名输入框修改是否有效(即时值/落库/刷新/列表名)"""
|
||||
import sys, asyncio, json
|
||||
|
||||
BASE = "https://127.0.0.1:3005"
|
||||
GUID = None # 用现有第一个项目
|
||||
|
||||
GUARD = """async () => {
|
||||
try {
|
||||
const root = await navigator.storage.getDirectory();
|
||||
const db = await new Promise((res, rej) => {
|
||||
const rq = indexedDB.open('H5VideoLocalDB');
|
||||
rq.onupgradeneeded = () => rq.result.createObjectStore('folderHandles');
|
||||
rq.onsuccess = () => res(rq.result);
|
||||
rq.onerror = () => rej(rq.error);
|
||||
});
|
||||
await new Promise((res, rej) => {
|
||||
const tx = db.transaction('folderHandles', 'readwrite');
|
||||
const st = tx.objectStore('folderHandles');
|
||||
const rec = { id: 'root', handle: root };
|
||||
if (st.keyPath) st.put(rec); else st.put(rec, 'root');
|
||||
tx.oncomplete = () => res(true);
|
||||
tx.onerror = () => rej(tx.error);
|
||||
});
|
||||
db.close();
|
||||
return 'ok';
|
||||
} catch (e) { return String(e); }
|
||||
}"""
|
||||
|
||||
READ_META = """async () => {
|
||||
try {
|
||||
const rq = indexedDB.open('H5VideoLocalDB');
|
||||
const db = await new Promise((res, rej) => { rq.onsuccess=()=>res(rq.result); rq.onerror=()=>rej(rq.error); });
|
||||
const tx = db.transaction('projects','readonly');
|
||||
const all = await new Promise((res, rej) => {
|
||||
const r = tx.objectStore('projects').getAll();
|
||||
r.onsuccess=()=>res(r.result); r.onerror=()=>rej(r.error);
|
||||
});
|
||||
return all.map(x => ({id:x.id, name:x.name, dtitle:(x.data&&x.data.title)||null}));
|
||||
} catch(e){ return 'ERR:'+e; }
|
||||
}"""
|
||||
|
||||
|
||||
async def main():
|
||||
from playwright.async_api import async_playwright
|
||||
async with async_playwright() as p:
|
||||
browser = await p.chromium.launch(args=["--ignore-certificate-errors"])
|
||||
ctx = await browser.new_context(ignore_https_errors=True,
|
||||
viewport={"width": 1600, "height": 900})
|
||||
page = await ctx.new_page()
|
||||
errs = []
|
||||
page.on("pageerror", lambda e: errs.append(str(e)))
|
||||
|
||||
# 首页 → 列表
|
||||
await page.goto(f"{BASE}/workspace/draft", wait_until="domcontentloaded", timeout=120000)
|
||||
await page.wait_for_timeout(4000)
|
||||
await page.evaluate(GUARD)
|
||||
await page.reload(wait_until="domcontentloaded")
|
||||
await page.wait_for_timeout(6000)
|
||||
|
||||
inputs = page.locator("input[class*='__name__']")
|
||||
if await inputs.count() == 0:
|
||||
btn = page.get_by_text("创建项目", exact=True).first
|
||||
await btn.click()
|
||||
await page.wait_for_timeout(6000)
|
||||
if "workspace/draft" not in page.url:
|
||||
await page.goto(f"{BASE}/workspace/draft", wait_until="domcontentloaded")
|
||||
await page.wait_for_timeout(5000)
|
||||
inputs = page.locator("input[class*='__name__']")
|
||||
|
||||
print("列表初始:", json.dumps(await page.evaluate(READ_META), ensure_ascii=False))
|
||||
|
||||
# 打开第一个项目(卡片是无 href 的 a[onClick],内部 .pic 区域)
|
||||
a = page.locator("div[class*='__item__'] a").first
|
||||
if await a.count() == 0:
|
||||
a = page.locator("a").filter(has=page.locator("div[class*='__pic__']")).first
|
||||
await a.click()
|
||||
await page.wait_for_timeout(10000)
|
||||
print("URL:", page.url)
|
||||
|
||||
inp = page.locator("#projectName")
|
||||
print("顶栏输入框存在:", await inp.count())
|
||||
if await inp.count():
|
||||
print("顶栏初始值:", repr(await inp.input_value()))
|
||||
await inp.click()
|
||||
await page.keyboard.press("Control+a")
|
||||
await page.keyboard.type("TOPBAR_RENAME_001")
|
||||
await page.wait_for_timeout(1500)
|
||||
print("输入后立即读:", repr(await inp.input_value()))
|
||||
# 等待自动保存(10s周期)+ 主动点云保存
|
||||
cloud = page.locator("a").filter(has=page.locator("svg")).first
|
||||
try:
|
||||
await page.locator("#projectName").press("Control+s")
|
||||
except Exception:
|
||||
pass
|
||||
await page.wait_for_timeout(12000)
|
||||
print("12s后读:", repr(await inp.input_value()))
|
||||
print("DB(编辑器内):", json.dumps(await page.evaluate(READ_META), ensure_ascii=False))
|
||||
|
||||
# 刷新页面看是否保留
|
||||
await page.reload(wait_until="domcontentloaded")
|
||||
await page.wait_for_timeout(10000)
|
||||
inp2 = page.locator("#projectName")
|
||||
if await inp2.count():
|
||||
print("刷新后顶栏:", repr(await inp2.input_value()))
|
||||
print("DB(刷新后):", json.dumps(await page.evaluate(READ_META), ensure_ascii=False))
|
||||
|
||||
# 回列表看卡片名
|
||||
await page.goto(f"{BASE}/workspace/draft", wait_until="domcontentloaded")
|
||||
await page.wait_for_timeout(6000)
|
||||
inputs2 = page.locator("input[class*='__name__']")
|
||||
if await inputs2.count():
|
||||
print("列表卡片名:", repr(await inputs2.first.input_value()))
|
||||
|
||||
print("JS errors:", errs[:6])
|
||||
await browser.close()
|
||||
|
||||
|
||||
sys.exit(asyncio.run(main()))
|
||||
@@ -0,0 +1,348 @@
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
"""AI 一键出片「自动封面」端到端:mock 掉对话/生图网关(无需真实 Key),
|
||||
真实跑完向导 4 步,断言:
|
||||
1. 确认页出现封面预览行且状态为「AI 封面文案 · 大字发光」
|
||||
2. 生成后时间轴第一个元素是「视频封面」图片、时长 3 秒、在片头
|
||||
3. 字幕从封面之后才开始(第一条字幕 BeginTime >= 3000ms)
|
||||
|
||||
用法:python3 scripts/e2e_quickvideo_cover.py
|
||||
"""
|
||||
import sys, time, json, base64
|
||||
from playwright.sync_api import sync_playwright
|
||||
|
||||
BASE = "https://127.0.0.1:3005"
|
||||
APPID = "qv_cover_%d" % int(time.time())
|
||||
STAMP = time.strftime("%H:%M:%S")
|
||||
|
||||
|
||||
def log(msg):
|
||||
print("[%s] %s" % (STAMP, msg), flush=True)
|
||||
|
||||
|
||||
GUARD = """async () => {
|
||||
try {
|
||||
const root = await navigator.storage.getDirectory();
|
||||
const db = await new Promise((res, rej) => {
|
||||
const rq = indexedDB.open('H5VideoLocalDB');
|
||||
rq.onupgradeneeded = () => rq.result.createObjectStore('folderHandles');
|
||||
rq.onsuccess = () => res(rq.result);
|
||||
rq.onerror = () => rej(rq.error);
|
||||
});
|
||||
const done = await new Promise((res, rej) => {
|
||||
const tx = db.transaction('folderHandles', 'readwrite');
|
||||
const st = tx.objectStore('folderHandles');
|
||||
const rec = { id: 'root', handle: root };
|
||||
if (st.keyPath) st.put(rec); else st.put(rec, 'root');
|
||||
tx.oncomplete = () => res(true);
|
||||
tx.onerror = () => rej(tx.error);
|
||||
});
|
||||
db.close();
|
||||
return done;
|
||||
} catch (e) { return String(e); }
|
||||
}"""
|
||||
|
||||
# 1280x720 纯色 PNG(mock 生图返回 b64_json)
|
||||
def make_cover_png_b64():
|
||||
from PIL import Image
|
||||
import io
|
||||
im = Image.new("RGB", (1280, 720), (30, 90, 200))
|
||||
buf = io.BytesIO()
|
||||
im.save(buf, format="PNG")
|
||||
return base64.b64encode(buf.getvalue()).decode()
|
||||
|
||||
|
||||
COPY_JSON = json.dumps({
|
||||
"segments": [
|
||||
{"text": "第一段测试口播内容,介绍这张封面", "image": 1},
|
||||
{"text": "第二段测试口播内容继续讲下去", "image": 2},
|
||||
{"text": "第三段测试口播内容收尾总结一下", "image": 3},
|
||||
]
|
||||
}, ensure_ascii=False)
|
||||
# 封面文案请求(prompt 带固定标记「生成短视频封面文案」),渲染由本地 canvas 完成
|
||||
COVER_COPY_JSON = json.dumps({
|
||||
"main": "三步搞定封面",
|
||||
"sub": "AI 文案加大字发光描边",
|
||||
"tag": "实测有效",
|
||||
}, ensure_ascii=False)
|
||||
|
||||
|
||||
def install_mock(page, cover_b64):
|
||||
"""对话/生图网关全部本地 mock:按请求内容区分文案请求与封面提示词请求"""
|
||||
def handler(route):
|
||||
req = route.request
|
||||
url = req.url
|
||||
if req.method == "OPTIONS":
|
||||
return route.fulfill(status=204, headers={
|
||||
"access-control-allow-origin": "*",
|
||||
"access-control-allow-methods": "POST, OPTIONS",
|
||||
"access-control-allow-headers": "content-type, authorization",
|
||||
})
|
||||
body = req.post_data or ""
|
||||
headers = {"access-control-allow-origin": "*", "content-type": "application/json"}
|
||||
if "chat/completions" in url:
|
||||
# 封面文案请求带固定标记「生成短视频封面文案」,其余是口播文案请求
|
||||
if "生成短视频封面文案" in body:
|
||||
content = COVER_COPY_JSON
|
||||
else:
|
||||
content = COPY_JSON
|
||||
payload = json.dumps({"choices": [{"message": {"content": content}}]})
|
||||
return route.fulfill(status=200, headers=headers, body=payload)
|
||||
if "images/generations" in url:
|
||||
payload = json.dumps({"data": [{"b64_json": cover_b64}]})
|
||||
return route.fulfill(status=200, headers=headers, body=payload)
|
||||
return route.fulfill(status=404, headers=headers, body="{}")
|
||||
|
||||
page.route("**/v1/chat/completions", handler)
|
||||
page.route("**/v1/images/generations", handler)
|
||||
|
||||
|
||||
def js_click(page, expr, desc):
|
||||
ok = page.evaluate("() => { const e = %s; if (e) { e.click(); return true; } return false; }" % expr)
|
||||
log("点 %s: %s" % (desc, ok))
|
||||
return ok
|
||||
|
||||
|
||||
def wait_text(page, text, seconds=120, label=""):
|
||||
for _ in range(seconds):
|
||||
page.wait_for_timeout(1000)
|
||||
if page.evaluate("() => document.body.innerText.includes(%s)" % json.dumps(text)):
|
||||
log("到位[%s]: %s" % (label, text))
|
||||
return True
|
||||
log("等待超时[%s]: %s" % (label, text))
|
||||
return False
|
||||
|
||||
|
||||
def make_images():
|
||||
from PIL import Image, ImageDraw
|
||||
out = []
|
||||
for i, color in enumerate([(200, 60, 60), (60, 140, 200), (80, 170, 90)], 1):
|
||||
p = "/tmp/qvc_img%d.png" % i
|
||||
im = Image.new("RGB", (960, 720), color)
|
||||
d = ImageDraw.Draw(im)
|
||||
d.text((40, 40), "COVER TEST %d" % i, fill=(255, 255, 255))
|
||||
im.save(p)
|
||||
out.append(p)
|
||||
return out
|
||||
|
||||
|
||||
def main():
|
||||
imgs = make_images()
|
||||
cover_b64 = make_cover_png_b64()
|
||||
log("测试图片: %s" % imgs)
|
||||
with sync_playwright() as p:
|
||||
browser = p.chromium.launch(
|
||||
executable_path="/usr/bin/chromium",
|
||||
headless=True,
|
||||
args=["--no-sandbox", "--disable-gpu", "--disable-dev-shm-usage", "--mute-audio",
|
||||
"--autoplay-policy=no-user-gesture-required"],
|
||||
)
|
||||
ctx = browser.new_context(ignore_https_errors=True)
|
||||
page = ctx.new_page()
|
||||
errors = []
|
||||
page.on("pageerror", lambda e: errors.append(str(e)))
|
||||
page.on("console", lambda m: errors.append("console:" + m.text[:200]) if m.type == "error" else None)
|
||||
page.on("console", lambda m: log("页面日志 %s" % m.text[:220]) if "[qv]" in m.text else None)
|
||||
|
||||
# 预置 AI 配置(Key 是假的,所有请求都被 route mock 掉)
|
||||
page.add_init_script("""
|
||||
localStorage.setItem('micut.ai.config.v1', JSON.stringify({
|
||||
baseUrl: 'https://ai.88531.cn/v1',
|
||||
apiKey: 'e2e-mock-key',
|
||||
model: 'mock-model',
|
||||
}));
|
||||
""")
|
||||
install_mock(page, cover_b64)
|
||||
|
||||
log("打开工程 %s" % APPID)
|
||||
page.goto("%s/editor/%s" % (BASE, APPID), wait_until="domcontentloaded", timeout=120000)
|
||||
page.wait_for_timeout(4000)
|
||||
log("守卫: %s" % page.evaluate(GUARD))
|
||||
page.reload(wait_until="domcontentloaded")
|
||||
page.wait_for_selector("#h5dsCanvas", timeout=90000)
|
||||
try:
|
||||
page.wait_for_function("() => document.body.innerText.includes('AI创作')", timeout=90000)
|
||||
log("侧栏已就绪")
|
||||
except Exception as e:
|
||||
log("侧栏等待超时: %s" % e)
|
||||
page.wait_for_timeout(3000)
|
||||
|
||||
js_click(page, """(() => {
|
||||
const w = document.createTreeWalker(document.body, NodeFilter.SHOW_TEXT);
|
||||
let n;
|
||||
while (n = w.nextNode()) {
|
||||
const t = (n.textContent || '').trim();
|
||||
if (t === 'AI创作' && n.parentElement) return n.parentElement;
|
||||
}
|
||||
return null;
|
||||
})()""", "AI创作")
|
||||
page.wait_for_timeout(2500)
|
||||
js_click(page, "[...document.querySelectorAll('button')].find(x => (x.innerText||'').includes('一键出片'))",
|
||||
"开始一键出片")
|
||||
page.wait_for_timeout(3000)
|
||||
|
||||
# 步骤1:3 张图 + 标题
|
||||
fi = page.query_selector("div.semi-modal input[type=file]")
|
||||
if not fi:
|
||||
fi = page.query_selector("input[type=file][accept='image/*']")
|
||||
if not fi:
|
||||
log("ERROR: 找不到向导的图片输入框")
|
||||
print(json.dumps({"ok": False, "why": "no-file-input"}, ensure_ascii=False))
|
||||
return 1
|
||||
fi.set_input_files(imgs)
|
||||
page.wait_for_timeout(2500)
|
||||
page.fill("input[placeholder*='三步搞定']", "封面功能端到端验证")
|
||||
page.wait_for_timeout(500)
|
||||
|
||||
js_click(page, "[...document.querySelectorAll('button')].find(x=>(x.innerText||'').includes('① 识别图片'))", "生成文案")
|
||||
got = wait_text(page, "下一步:配置声音", 180, "第2步")
|
||||
log("文案生成完成: %s" % got)
|
||||
if not got:
|
||||
print(json.dumps({"ok": False, "why": "copy-timeout", "errors": errors[-6:]}, ensure_ascii=False))
|
||||
return 1
|
||||
|
||||
js_click(page, "[...document.querySelectorAll('button')].find(x=>(x.innerText||'').includes('下一步:配置声音'))", "下一步")
|
||||
page.wait_for_timeout(2000)
|
||||
|
||||
# 步骤3:合成全部配音(真实 edge-tts)
|
||||
js_click(page, "[...document.querySelectorAll('button')].find(x=>(x.innerText||'').includes('合成全部配音'))", "合成全部配音")
|
||||
done = wait_text(page, "图片转场", 300, "第4步效果面板")
|
||||
log("配音合成完成: %s" % done)
|
||||
if not done:
|
||||
print(json.dumps({"ok": False, "why": "synth-timeout", "errors": errors[-6:]}, ensure_ascii=False))
|
||||
return 1
|
||||
page.wait_for_timeout(1500)
|
||||
|
||||
# 断言 1:确认页封面预览行
|
||||
body = page.inner_text(".semi-modal-body")
|
||||
has_cover_row = ("视频封面" in body) and ("AI 封面文案" in body) and ("大字发光" in body)
|
||||
has_cover_thumb = page.evaluate("""() => {
|
||||
const img = [...document.querySelectorAll('.semi-modal img')].find(i => (i.alt||'') === '视频封面');
|
||||
return !!(img && img.src && img.src.startsWith('data:image/png'));
|
||||
}""")
|
||||
has_total = "预计成片" in body
|
||||
log("确认页封面行: %s, 缩略图 dataURL: %s" % (has_cover_row, has_cover_thumb))
|
||||
page.screenshot(path="/tmp/qvc_step4.png", full_page=False)
|
||||
|
||||
# 生成
|
||||
js_click(page, "[...document.querySelectorAll('button')].find(x=>(x.innerText||'').includes('③ 确认生成视频'))", "确认生成视频")
|
||||
page.wait_for_timeout(12000)
|
||||
|
||||
# 断言 2/3:时间轴数据
|
||||
res = page.evaluate("""() => {
|
||||
const ed = window.__editor && window.__editor.movie;
|
||||
if (!ed) return {err:'no-editor'};
|
||||
const d = ed.data || {};
|
||||
const els = (d.elements || []).slice().sort((a,b) => (a.startTime||0) - (b.startTime||0));
|
||||
const imgs = els.filter(e => e.type === 'image');
|
||||
const caps = d.captions || [];
|
||||
const f = els[0] || null;
|
||||
// 元素本身不存 url,资源经 resourceManage.getResouceById(resourceId) 取
|
||||
let resUrl = '';
|
||||
const rid = f && f.resourceId;
|
||||
if (rid) {
|
||||
const mgr = window.__editor.movie.resourceManage;
|
||||
try {
|
||||
const r = mgr && mgr.getResouceById && mgr.getResouceById(rid);
|
||||
if (r) resUrl = r.url || (r.urls && r.urls.url) || '';
|
||||
} catch (e) { resUrl = 'ERR:' + e; }
|
||||
}
|
||||
return {
|
||||
title: d.title,
|
||||
first: f,
|
||||
coverResourceUrl: resUrl.slice(0, 40),
|
||||
imgCount: imgs.length,
|
||||
elements: els.map(e => ({ name: e.name, type: e.type, t: e.startTime, d: e.duration })),
|
||||
captionCount: caps.length,
|
||||
caption0: caps[0] ? JSON.parse(JSON.stringify(caps[0])) : null,
|
||||
canvas: { w: d.width, h: d.height },
|
||||
};
|
||||
}""")
|
||||
log("工程数据: " + json.dumps(res, ensure_ascii=False)[:2000])
|
||||
|
||||
f = res.get("first") or {}
|
||||
cap0 = res.get("caption0") or {}
|
||||
# 字幕在元素数据里以秒存 startTime(addCaptions 的 BeginTime 输入被 SDK 归一化)
|
||||
cap_begin = cap0.get("startTime", cap0.get("BeginTime", cap0.get("beginTime")))
|
||||
url = res.get("coverResourceUrl") or ((f.get("urls") or {}).get("url") or f.get("url") or "")
|
||||
checks = {
|
||||
"cover_row_on_step4": has_cover_row,
|
||||
"cover_thumb_dataurl": has_cover_thumb,
|
||||
"first_is_cover": f.get("name") == "视频封面" and f.get("type") == "image",
|
||||
"cover_at_head": (f.get("startTime") is not None) and abs(float(f.get("startTime"))) < 0.01,
|
||||
"cover_dur_3": abs(float(f.get("duration") or 0) - 3) < 0.01,
|
||||
"cover_has_url": bool(url),
|
||||
"cover_url_is_dataurl": str(url).startswith("data:image"),
|
||||
# 字幕从封面结束(第 3 秒)起接续
|
||||
"caption_after_cover": (cap_begin or 0) >= 3,
|
||||
"caption_count_3": res.get("captionCount") == 3,
|
||||
}
|
||||
log("原始首元素: " + json.dumps({k: v for k, v in f.items() if k in ('name','type','startTime','duration','urls','url','trackIndex')}, ensure_ascii=False)[:800])
|
||||
log("原始字幕0: " + json.dumps(cap0, ensure_ascii=False)[:400])
|
||||
log("断言: " + json.dumps(checks, ensure_ascii=False))
|
||||
log("JS 错误: %s" % (errors[-5:] if errors else "无"))
|
||||
|
||||
# 播一下确认渲染
|
||||
page.evaluate("""() => {
|
||||
const m = window.__editor && window.__editor.movie;
|
||||
if (m && m.pause) m.pause();
|
||||
const st = window.__editor;
|
||||
if (st && st.updateMovie) st.updateMovie(1.0);
|
||||
}""")
|
||||
page.wait_for_timeout(2500)
|
||||
page.screenshot(path="/tmp/qvc_playing.png", full_page=False)
|
||||
log("截图: /tmp/qvc_step4.png /tmp/qvc_playing.png")
|
||||
|
||||
# 刷新确认封面持久化
|
||||
saved = page.evaluate("""() => {
|
||||
const s = window.__editor;
|
||||
if (typeof s.saveApp === 'function') { s.saveApp(() => {}); return 'saveApp 已调用'; }
|
||||
return '没有 saveApp';
|
||||
}""")
|
||||
log("手动保存: %s" % saved)
|
||||
page.wait_for_timeout(8000)
|
||||
page.reload(wait_until="domcontentloaded")
|
||||
page.wait_for_selector("#h5dsCanvas", timeout=90000)
|
||||
page.wait_for_timeout(12000)
|
||||
after = page.evaluate("""() => {
|
||||
const d = (window.__editor && window.__editor.movie && window.__editor.movie.data) || {};
|
||||
const els = (d.elements || []).slice().sort((a,b) => (a.startTime||0) - (b.startTime||0));
|
||||
const f = els[0] || {};
|
||||
return { title: d.title, firstName: f.name, firstT: f.startTime, firstD: f.duration,
|
||||
els: els.length, caps: (d.captions||[]).length };
|
||||
}""")
|
||||
log("刷新后: " + json.dumps(after, ensure_ascii=False))
|
||||
checks["cover_persist_after_reload"] = (
|
||||
after.get("firstName") == "视频封面"
|
||||
and after.get("firstT") is not None and abs(float(after.get("firstT"))) < 0.01
|
||||
)
|
||||
|
||||
# 断言:用户输入的标题 → 项目文件名(顶栏 title + 刷新后持久化)
|
||||
res_title = res.get("title")
|
||||
log("构建后 title: %s" % res_title)
|
||||
# AI 出片项目文件名须带【AI】前缀
|
||||
checks["title_applied_after_build"] = res_title == "【AI】封面功能端到端验证"
|
||||
checks["title_persist_after_reload"] = after.get("title") == "【AI】封面功能端到端验证"
|
||||
# 项目列表卡片名(meta.name)
|
||||
meta_name = page.evaluate("""async () => {
|
||||
try {
|
||||
const rq = indexedDB.open('H5VideoLocalDB');
|
||||
const db = await new Promise((res, rej) => { rq.onsuccess = () => res(rq.result); rq.onerror = () => rej(rq.error); });
|
||||
const id = window.__editor && window.__editor.appid;
|
||||
const tx = db.transaction('projects', 'readonly');
|
||||
const g = tx.objectStore('projects').get(id);
|
||||
const rec = await new Promise((res, rej) => { g.onsuccess = () => res(g.result); g.onerror = () => rej(g.error); });
|
||||
return (rec && rec.name) || '';
|
||||
} catch (e) { return 'ERR:' + e; }
|
||||
}""")
|
||||
log("项目卡片名: %s" % meta_name)
|
||||
checks["project_card_name"] = meta_name == "【AI】封面功能端到端验证"
|
||||
|
||||
ok = all(checks.values())
|
||||
print(json.dumps({"ok": ok, "checks": checks, "errors": errors[-5:]}, ensure_ascii=False))
|
||||
browser.close()
|
||||
return 0 if ok else 2
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(main())
|
||||
@@ -20,7 +20,7 @@ import Project from './Project';
|
||||
import { language, Intl } from '@language/index';
|
||||
import KeyboardModal from './KeyboardModal';
|
||||
import { stores } from '@stores/index';
|
||||
import { saveProject, canUseLocalSave } from '@services/localStorageService';
|
||||
import { saveProject, canUseLocalSave, updateLocalProjectMeta } from '@services/localStorageService';
|
||||
import HubStatus from '@components/hub';
|
||||
import { AiSettingsButton } from '@components/ai-settings';
|
||||
import { reURL } from '@utils/util';
|
||||
@@ -242,6 +242,18 @@ function Header(props: IProps) {
|
||||
editor.data.title = e.target.value;
|
||||
forceUpdate();
|
||||
}}
|
||||
/* 顶栏改名即项目文件名:失焦立刻写入列表(不等自动保存),
|
||||
否则用户改完名回列表看不到变化,会以为"修改无效" */
|
||||
onBlur={async () => {
|
||||
const t = (editor.data.title || '').trim();
|
||||
if (!t || !editor.appid) return;
|
||||
if (!String(editor.appid).startsWith('local_')) return; // 远程项目由保存链路处理
|
||||
try {
|
||||
await updateLocalProjectMeta(editor.appid, { name: t });
|
||||
} catch (e) {
|
||||
console.warn('同步项目文件名失败:', e);
|
||||
}
|
||||
}}
|
||||
/>
|
||||
</section>
|
||||
{/* <section className={styles.center}></section> */}
|
||||
|
||||
@@ -24,8 +24,10 @@ import {
|
||||
EMOTIONS,
|
||||
VoiceOption,
|
||||
QvSegment,
|
||||
QvCover,
|
||||
fetchTtsVoices,
|
||||
generateQuickVideoCopy,
|
||||
generateQuickVideoCover,
|
||||
synthesizeSegment,
|
||||
decodeAudio,
|
||||
} from '@utils/aiQuickVideo';
|
||||
@@ -62,11 +64,13 @@ const GEN_LABEL: Record<SrcMode, string> = {
|
||||
url: '① 分析网页 · 生成文案',
|
||||
};
|
||||
const GEN_LOADING: Record<SrcMode, string> = {
|
||||
image: '正在识别图片写文案…',
|
||||
doc: '正在读取文档写文案…',
|
||||
url: '正在分析网页写文案…',
|
||||
image: '正在识别图片写文案、生成封面…',
|
||||
doc: '正在读取文档写文案、生成封面…',
|
||||
url: '正在分析网页写文案、生成封面…',
|
||||
};
|
||||
const MAX_IMAGES = 8;
|
||||
/** 视频封面在片头占的时长(秒) */
|
||||
const COVER_DUR = 3;
|
||||
|
||||
const { Option } = Select;
|
||||
|
||||
@@ -342,6 +346,11 @@ export default function QuickVideo({
|
||||
const [segs, setSegs] = useState<Seg[]>([]);
|
||||
const [genLoading, setGenLoading] = useState(false);
|
||||
|
||||
/* AI 封面:第 1 步与文案并行生成,第 4 步预览,确认时插到片头 */
|
||||
const [cover, setCover] = useState<QvCover | null>(null);
|
||||
const [coverErr, setCoverErr] = useState<string | null>(null);
|
||||
const [coverLoading, setCoverLoading] = useState(false);
|
||||
|
||||
const [voices, setVoices] = useState<VoiceOption[]>([]);
|
||||
const [voice, setVoice] = useState('zh-CN-XiaoxiaoNeural');
|
||||
const [rate, setRate] = useState(0);
|
||||
@@ -519,6 +528,17 @@ export default function QuickVideo({
|
||||
}
|
||||
if (!title.trim()) return Toast.warning('请填写标题');
|
||||
setGenLoading(true);
|
||||
setCover(null);
|
||||
setCoverErr(null);
|
||||
// 文案与封面并行生成:封面只依赖标题/图片/正文,不必等文案出结果
|
||||
setCoverLoading(true);
|
||||
const coverTask = generateQuickVideoCover({
|
||||
title: title.trim(),
|
||||
images: images.map(i => i.url),
|
||||
sourceText: bodyText || undefined,
|
||||
})
|
||||
.then(r => r)
|
||||
.catch((e): [null, string] => [null, e?.message || String(e)]);
|
||||
const [res, err] = await generateQuickVideoCopy({
|
||||
title: title.trim(),
|
||||
style,
|
||||
@@ -526,17 +546,36 @@ export default function QuickVideo({
|
||||
sourceText: bodyText || undefined,
|
||||
});
|
||||
setGenLoading(false);
|
||||
if (err || !res) return Toast.error(err || '文案生成失败');
|
||||
if (err || !res) {
|
||||
// 文案失败也要把封面任务收掉,避免悬挂的 loading
|
||||
const [cv, cerr] = await coverTask;
|
||||
setCoverLoading(false);
|
||||
return Toast.error(err || '文案生成失败');
|
||||
}
|
||||
// 纯文档 / 纯文字素材没有配图时,自动生成一张标题封面,保证时间轴有画面可用
|
||||
if (!images.length) {
|
||||
const cover = makeTitleCover(title.trim());
|
||||
setImages([{ id: util.randomID(), url: cover.url, name: '标题封面', w: cover.w, h: cover.h }]);
|
||||
const cover0 = makeTitleCover(title.trim());
|
||||
setImages([{ id: util.randomID(), url: cover0.url, name: '标题封面', w: cover0.w, h: cover0.h }]);
|
||||
}
|
||||
const list = res.segments.map(s => newSeg(s.text, s.image));
|
||||
setSegs(list);
|
||||
setAudio({});
|
||||
setStep(1);
|
||||
Toast.success(`已生成 ${list.length} 段文案`);
|
||||
// 封面还没好就继续等(AI 文案 + 本地渲染通常几秒),文案失败则用标题模板兜底
|
||||
const [cv, cerr] = await coverTask;
|
||||
setCoverLoading(false);
|
||||
if (cv) {
|
||||
setCover(cv);
|
||||
setCoverErr(cerr || null);
|
||||
if (cv.local) Toast.warning(`AI 封面文案未成功(${cerr || '未知原因'}),已用标题模板渲染`);
|
||||
else Toast.success('封面已生成(AI 文案 · 大字发光描边)');
|
||||
} else {
|
||||
const fb = makeTitleCover(title.trim());
|
||||
setCover({ url: fb.url, w: fb.w, h: fb.h, local: true });
|
||||
setCoverErr(cerr || '封面文案生成失败');
|
||||
Toast.warning(`封面渲染失败,已用本地标题封面代替:${cerr || ''}`);
|
||||
}
|
||||
};
|
||||
|
||||
const editSegText = (uid: string, text: string) =>
|
||||
@@ -619,6 +658,7 @@ export default function QuickVideo({
|
||||
const build = async () => {
|
||||
const { editor } = stores;
|
||||
if (!editor.data) return Toast.error('没有打开的视频项目');
|
||||
if (coverLoading) return Toast.warning('封面还在生成中,稍等几秒再确认');
|
||||
const missing = segs.filter(s => !audio[s.uid]?.url);
|
||||
if (missing.length) return Toast.warning(`还有 ${missing.length} 段没有配音,请先合成`);
|
||||
|
||||
@@ -637,6 +677,29 @@ export default function QuickVideo({
|
||||
let imgTrack: number | undefined;
|
||||
const captions: any[] = [];
|
||||
|
||||
// 片头封面:AI 按标题/图片生成的封面图放最前面 3 秒(无配音无字幕)
|
||||
if (cover) {
|
||||
const coverItem: any = {
|
||||
id: util.randomID(),
|
||||
name: '视频封面',
|
||||
convert_status: -1,
|
||||
app_id: editor.appid,
|
||||
type: 'image',
|
||||
urls: { url: cover.url },
|
||||
attrs: { duration: COVER_DUR, naturalWidth: cover.w, naturalHeight: cover.h },
|
||||
};
|
||||
const cEl: any = await addImageVideoAudioItem(coverItem, t, undefined, true);
|
||||
if (cEl) {
|
||||
cEl.startTime = t;
|
||||
cEl.duration = COVER_DUR;
|
||||
if (editor.checkTrackElementOverlap(cEl.trackIndex)) cEl.trackIndex += 0.5;
|
||||
imgTrack = cEl.trackIndex;
|
||||
// 封面也吃运镜设置,避免与后面画面风格不一致
|
||||
applyImageMotion(cEl, COVER_DUR, -1, fxMotion);
|
||||
}
|
||||
t = Number((t + COVER_DUR).toFixed(2));
|
||||
}
|
||||
|
||||
for (let i = 0; i < segs.length; i++) {
|
||||
const seg = segs[i];
|
||||
const track = audio[seg.uid];
|
||||
@@ -709,8 +772,35 @@ export default function QuickVideo({
|
||||
if (captions.length) editor.setContorlAndSelectedElemenent?.([]);
|
||||
|
||||
const transCount = fxTrans === 'none' ? 0 : Math.max(0, segs.length - 1);
|
||||
|
||||
// 项目文件名 = 用户输入的标题:顶栏标题、工程数据、项目列表卡片名三处同步
|
||||
// AI 出片的项目文件名带【AI】标识(已带前缀则不重复叠加)
|
||||
const rawTitle = title.trim();
|
||||
const projTitle = rawTitle ? (rawTitle.startsWith('【AI】') ? rawTitle : `【AI】${rawTitle}`) : '';
|
||||
if (projTitle) {
|
||||
editor.data.title = projTitle;
|
||||
// movie.data 若是独立引用,一并改掉(保存走 sortZIndexNewData)
|
||||
const md: any = (editor as any).movie?.data;
|
||||
if (md && md !== editor.data) md.title = projTitle;
|
||||
try {
|
||||
if (typeof (editor as any).saveApp === 'function') {
|
||||
await (editor as any).saveApp();
|
||||
}
|
||||
} catch (e) {
|
||||
console.warn('[qv] 保存标题失败', e);
|
||||
}
|
||||
try {
|
||||
// 本地模式:项目卡片名存的是 meta.name(saveProject 不会用 title 覆盖),需单独同步
|
||||
const { updateLocalProjectMeta } = await import('@services/localStorageService');
|
||||
await updateLocalProjectMeta(editor.appid, { name: projTitle }).catch(() => {});
|
||||
} catch (e) {
|
||||
console.warn('[qv] 同步项目名失败', e);
|
||||
}
|
||||
}
|
||||
|
||||
Toast.success(
|
||||
`已生成 ${segs.length} 段:图片${fxMotion === 'none' ? '' : '(带动效)'}、配音、字幕已就位` +
|
||||
(cover ? '封面 + ' : '') +
|
||||
`已生成 ${segs.length} 段:图片${fxMotion === 'none' ? '' : '(带动效)'}、配音、字幕已就位` +
|
||||
(transCount ? `,${transCount} 个转场` : ''),
|
||||
);
|
||||
onClose();
|
||||
@@ -732,6 +822,9 @@ export default function QuickVideo({
|
||||
setAudio({});
|
||||
setTitle('');
|
||||
setImages([]);
|
||||
setCover(null);
|
||||
setCoverErr(null);
|
||||
setCoverLoading(false);
|
||||
setRate(0);
|
||||
setEmotion('calm');
|
||||
};
|
||||
@@ -822,7 +915,7 @@ export default function QuickVideo({
|
||||
<>
|
||||
<div className={styles.desc}>
|
||||
素材三选一:上传图片,或上传 Word / PDF 文档,或输入网址自动抓取正文和配图 ——
|
||||
AI 看懂素材后写口播文案,再生成字幕和配音。
|
||||
AI 看懂素材后写口播文案,并根据标题和图片自动生成一张视频封面(片头 3 秒),再生成字幕和配音。
|
||||
</div>
|
||||
<div className={styles.modeRow}>
|
||||
<RadioGroup
|
||||
@@ -1185,9 +1278,31 @@ export default function QuickVideo({
|
||||
</div>
|
||||
|
||||
<div className={styles.summary}>
|
||||
<div className={styles.coverRow}>
|
||||
<img className={styles.coverThumb} src={cover?.url} alt="视频封面" />
|
||||
<div className={styles.coverInfo}>
|
||||
<div>
|
||||
{coverLoading ? (
|
||||
<>
|
||||
<Spin size="small" /> AI 正在生成封面文案与大字封面…
|
||||
</>
|
||||
) : cover ? (
|
||||
<>
|
||||
视频封面 · 片头 <b>{COVER_DUR}</b> 秒 ·{' '}
|
||||
<b>{cover.local ? '本地标题模板' : 'AI 封面文案 · 大字发光'}</b>
|
||||
</>
|
||||
) : (
|
||||
'未生成封面'
|
||||
)}
|
||||
</div>
|
||||
{coverErr && !coverLoading && (
|
||||
<div style={{ color: '#d4380d' }}>封面文案生成失败({coverErr}),已用标题模板渲染</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
<div>
|
||||
<MusicOne size={14} /> 图片 <b>{images.length}</b> 张 · 口播 <b>{segs.length}</b> 段 ·
|
||||
预计成片 <b>{totalDur.toFixed(1)}</b> 秒
|
||||
预计成片 <b>{(totalDur + (cover ? COVER_DUR : 0)).toFixed(1)}</b> 秒
|
||||
</div>
|
||||
<div>
|
||||
转场 <b>{TRANS_OPTIONS.find(o => o.value === fxTrans)?.label}</b> · 动效{' '}
|
||||
@@ -1248,7 +1363,7 @@ export default function QuickVideo({
|
||||
`素材池 ${images.length}/${MAX_IMAGES} 张图片${src?.text ? ` · 正文 ${src.text.length} 字` : ''}`}
|
||||
{step === 1 && `${segs.length} 段文案`}
|
||||
{step === 2 && `已配音 ${freshCount}/${segs.length} 段`}
|
||||
{step === 3 && `总长约 ${totalDur.toFixed(1)} 秒`}
|
||||
{step === 3 && `总长约 ${(totalDur + (cover ? COVER_DUR : 0)).toFixed(1)} 秒`}
|
||||
</span>
|
||||
<div style={{ display: 'flex', gap: 8 }}>
|
||||
<Button onClick={onClose}>取消</Button>
|
||||
|
||||
@@ -169,6 +169,33 @@
|
||||
line-height: 2;
|
||||
}
|
||||
|
||||
/* AI 封面预览(确认生成页) */
|
||||
.coverRow {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 12px;
|
||||
padding-bottom: 8px;
|
||||
margin-bottom: 4px;
|
||||
border-bottom: 1px dashed rgba(255, 255, 255, 0.35);
|
||||
}
|
||||
|
||||
.coverThumb {
|
||||
width: 132px;
|
||||
height: 74px;
|
||||
object-fit: cover;
|
||||
border-radius: 6px;
|
||||
border: 1px solid #fff;
|
||||
background: rgba(255, 255, 255, 0.06);
|
||||
flex: 0 0 auto;
|
||||
}
|
||||
|
||||
.coverInfo {
|
||||
font-size: 13px;
|
||||
color: #fff;
|
||||
line-height: 1.7;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.footer {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
|
||||
@@ -115,9 +115,16 @@ export default function Draft(props: IProps) {
|
||||
</a>
|
||||
<input
|
||||
title={language.val('draft_name_input')}
|
||||
placeholder={language.val('draft_name_input')}
|
||||
onKeyDown={e => {
|
||||
if (e.key === 'Enter') e.currentTarget.blur();
|
||||
e.stopPropagation();
|
||||
}}
|
||||
onFocus={e => {
|
||||
currentName.current = e.target.value;
|
||||
e.currentTarget.select();
|
||||
}}
|
||||
onClick={e => e.stopPropagation()}
|
||||
onBlur={async e => {
|
||||
if (e.target.value === currentName.current) return;
|
||||
item.name = e.target.value;
|
||||
|
||||
@@ -18,10 +18,32 @@
|
||||
|
||||
.name {
|
||||
margin-top: 10px;
|
||||
border: none;
|
||||
border: 1px solid transparent;
|
||||
width: 100%;
|
||||
background: transparent;
|
||||
color: var(--theme-text);
|
||||
cursor: text;
|
||||
border-radius: 6px;
|
||||
padding: 4px 6px;
|
||||
font-size: 14px;
|
||||
line-height: 1.4;
|
||||
transition: background 0.2s, border-color 0.2s;
|
||||
|
||||
&:hover {
|
||||
background: var(--theme-wateritem);
|
||||
border-color: var(--theme-main);
|
||||
}
|
||||
|
||||
&:focus {
|
||||
outline: none;
|
||||
background: var(--theme-wateritem);
|
||||
border-color: var(--theme-main);
|
||||
}
|
||||
|
||||
&::placeholder {
|
||||
color: var(--theme-text);
|
||||
opacity: 0.5;
|
||||
}
|
||||
}
|
||||
|
||||
.pic {
|
||||
|
||||
@@ -651,9 +651,12 @@ const projectFileQueue = new Map<string, Promise<void>>();
|
||||
/** 保存项目数据 */
|
||||
export async function saveProject(appId: string, data: any): Promise<void> {
|
||||
const existing = await localDB.projects.get(appId);
|
||||
/* 项目文件名跟随工程标题:顶栏改的是 data.title,此前保存时 name 恒取旧值,
|
||||
导致顶栏改名对列表文件名完全无效。title 为空则沿用原名。 */
|
||||
const titleName = typeof data?.title === 'string' && data.title.trim() ? data.title : '';
|
||||
await localDB.projects.put({
|
||||
id: appId,
|
||||
name: existing?.name || data?.name || 'Untitled',
|
||||
name: titleName || existing?.name || data?.name || 'Untitled',
|
||||
categoryId: existing?.categoryId || data?.categoryId || '0',
|
||||
thumb: existing?.thumb || data?.thumb || '',
|
||||
description: existing?.description || data?.description || '',
|
||||
@@ -826,7 +829,14 @@ export async function updateLocalProjectMeta(
|
||||
): Promise<[any, string | null]> {
|
||||
const record = await localDB.projects.get(id);
|
||||
if (!record) return [null, '项目不存在'];
|
||||
if (params.name !== undefined) record.name = params.name;
|
||||
if (params.name !== undefined) {
|
||||
record.name = params.name;
|
||||
/* 文件名与工程标题双向一致:列表改名时同步 data.title,
|
||||
否则打开编辑器顶栏仍显示旧标题(两处各存各的会分叉) */
|
||||
if (params.name && record.data && typeof record.data === 'object') {
|
||||
(record.data as any).title = params.name;
|
||||
}
|
||||
}
|
||||
if (params.category_id !== undefined) record.categoryId = String(params.category_id);
|
||||
if (params.thumb !== undefined) record.thumb = params.thumb;
|
||||
if (params.description !== undefined) record.description = params.description;
|
||||
|
||||
@@ -205,6 +205,306 @@ export async function generateQuickVideoCopy(params: {
|
||||
return [{ title: params.title, segments }, null];
|
||||
}
|
||||
|
||||
/** 封面文案:AI 根据标题 + 素材写吸引人的封面文字(主标题 / 副标题 / 角标) */
|
||||
export interface QvCoverCopy {
|
||||
/** 主标题:突出重点、抓眼球,≤12 字 */
|
||||
main: string;
|
||||
/** 副标题 / 钩子句,写出特色,≤18 字 */
|
||||
sub?: string;
|
||||
/** 角标短词,≤6 字(如「实测有效」「保姆级教程」) */
|
||||
tag?: string;
|
||||
/** true = AI 生成;false = 本地标题模板兜底 */
|
||||
ai?: boolean;
|
||||
}
|
||||
|
||||
export interface QvCover {
|
||||
url: string;
|
||||
w: number;
|
||||
h: number;
|
||||
/** true = AI 文案失败,用标题模板兜底渲染 */
|
||||
local?: boolean;
|
||||
/** 渲染进封面的文案 */
|
||||
copy?: QvCoverCopy;
|
||||
}
|
||||
|
||||
/** 封面文案请求的固定标记(E2E mock 按它区分请求) */
|
||||
export const COVER_COPY_MARK = '生成短视频封面文案';
|
||||
|
||||
/** 量图片尺寸(取不到按 16:9 兜底) */
|
||||
function measureImage(img: HTMLImageElement): { w: number; h: number } {
|
||||
const w = Number(img.naturalWidth) || 0;
|
||||
const h = Number(img.naturalHeight) || 0;
|
||||
return { w: w > 0 ? w : 1280, h: h > 0 ? h : 720 };
|
||||
}
|
||||
|
||||
/** 远程图片转 data URL(失败返回空串,调用方退回无背景渲染) */
|
||||
async function toDataUrl(url: string): Promise<string> {
|
||||
try {
|
||||
const res = await fetch(url);
|
||||
if (!res.ok) return '';
|
||||
const blob = await res.blob();
|
||||
return await new Promise<string>(resolve => {
|
||||
const fr = new FileReader();
|
||||
fr.onload = () => resolve(String(fr.result || ''));
|
||||
fr.onerror = () => resolve('');
|
||||
fr.readAsDataURL(blob);
|
||||
});
|
||||
} catch (e) {
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
/** 本地模板兜底文案:标题直接当主标题,素材首句当副标题 */
|
||||
function templateCoverCopy(params: { title: string; sourceText?: string }): QvCoverCopy {
|
||||
const main = params.title.trim().slice(0, 14) || '未命名视频';
|
||||
const first = (params.sourceText || '').split(/[。!?!?.\n]/).map(s => s.trim()).find(s => s.length > 4);
|
||||
return { main, sub: first ? first.slice(0, 18) : undefined, ai: false };
|
||||
}
|
||||
|
||||
/**让模型根据标题/素材写封面文案(可带首图帮助理解画面),失败返回 [null, 错误] */
|
||||
async function askCoverCopy(params: {
|
||||
title: string;
|
||||
images?: string[];
|
||||
sourceText?: string;
|
||||
}): Promise<[QvCoverCopy | null, string | null]> {
|
||||
const useVision = !!params.images?.length && (await aiVisionAvailable());
|
||||
const text =
|
||||
`${COVER_COPY_MARK}。视频标题:${params.title}。\n` +
|
||||
(params.sourceText ? `素材正文节选:${params.sourceText.slice(0, 800)}。\n` : '') +
|
||||
'要求:写出现在最吸引人点击的封面文字,突出重点、有特色、口语化有钩子。\n' +
|
||||
'输出 JSON:{"main":"主标题,≤12字,必须突出重点","sub":"副标题/钩子句,≤18字,写出特色","tag":"角标短词,≤6字,可留空"}\n' +
|
||||
'只输出 JSON,不要任何解释。';
|
||||
const content: any[] = [{ type: 'text', text }];
|
||||
if (useVision) {
|
||||
content.push({ type: 'image_url', image_url: { url: await shrinkImageForVision(params.images![0], 640) } });
|
||||
}
|
||||
const [res, err] = await localChatCompletion({
|
||||
messages: [
|
||||
{ role: 'system', content: '你是短视频封面文案专家,只输出 JSON。' },
|
||||
{ role: 'user', content: useVision ? content : text },
|
||||
],
|
||||
});
|
||||
if (err) return [null, err];
|
||||
const raw = res?.choices?.[0]?.message?.content;
|
||||
const json = parseJsonLoose<{ main?: any; sub?: any; tag?: any }>(typeof raw === 'string' ? raw : raw?.content || '');
|
||||
const main = String(json?.main || '').replace(/\s+/g, '').trim().slice(0, 16);
|
||||
if (!main) return [null, '模型没有返回封面文案'];
|
||||
const sub = String(json?.sub || '').replace(/\s+/g, '').trim().slice(0, 24) || undefined;
|
||||
const tag = String(json?.tag || '').replace(/\s+/g, '').trim().slice(0, 8) || undefined;
|
||||
return [{ main, sub, tag, ai: true }, null];
|
||||
}
|
||||
|
||||
/** 加载图片(失败 resolve null) */
|
||||
function loadImage(src: string): Promise<HTMLImageElement | null> {
|
||||
return new Promise(resolve => {
|
||||
try {
|
||||
const img = new Image();
|
||||
img.onload = () => resolve(img);
|
||||
img.onerror = () => resolve(null);
|
||||
img.src = src;
|
||||
} catch (e) {
|
||||
resolve(null);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/** 按最大宽度缩字号(保证文字不出画) */
|
||||
function fitFont(ctx: CanvasRenderingContext2D, text: string, maxW: number, start: number, min: number, weight = '900'): number {
|
||||
let size = start;
|
||||
ctx.font = `${weight} ${size}px "PingFang SC", "Microsoft YaHei", "Noto Sans CJK SC", sans-serif`;
|
||||
while (size > min && ctx.measureText(text).width > maxW) {
|
||||
size -= 4;
|
||||
ctx.font = `${weight} ${size}px "PingFang SC", "Microsoft YaHei", "Noto Sans CJK SC", sans-serif`;
|
||||
}
|
||||
return size;
|
||||
}
|
||||
|
||||
/**
|
||||
* 大字发光描边绘制:先画发光层(shadowBlur),再描边,最后实心填充,文字突出重点
|
||||
*/
|
||||
function drawGlowStrokeText(
|
||||
ctx: CanvasRenderingContext2D,
|
||||
text: string,
|
||||
x: number,
|
||||
y: number,
|
||||
size: number,
|
||||
fill: string,
|
||||
stroke: string,
|
||||
glow: string,
|
||||
weight = '900',
|
||||
) {
|
||||
ctx.font = `${weight} ${size}px "PingFang SC", "Microsoft YaHei", "Noto Sans CJK SC", sans-serif`;
|
||||
ctx.textAlign = 'center';
|
||||
ctx.textBaseline = 'middle';
|
||||
ctx.lineJoin = 'round';
|
||||
// 发光层:同色文字带大模糊阴影画两遍,亮度更足
|
||||
ctx.save();
|
||||
ctx.shadowColor = glow;
|
||||
ctx.shadowBlur = Math.max(18, size * 0.35);
|
||||
ctx.fillStyle = fill;
|
||||
ctx.fillText(text, x, y);
|
||||
ctx.fillText(text, x, y);
|
||||
ctx.restore();
|
||||
// 描边层
|
||||
ctx.strokeStyle = stroke;
|
||||
ctx.lineWidth = Math.max(4, size * 0.14);
|
||||
ctx.strokeText(text, x, y);
|
||||
// 实心填充
|
||||
ctx.fillStyle = fill;
|
||||
ctx.fillText(text, x, y);
|
||||
}
|
||||
|
||||
/** 本地渲染封面:素材图背景(暗化)或渐变底 + AI 文案大字发光描边 */
|
||||
async function renderCover(copy: QvCoverCopy, bgDataUrl?: string): Promise<{ url: string; w: number; h: number }> {
|
||||
const W = 1280;
|
||||
const H = 720;
|
||||
const cv = document.createElement('canvas');
|
||||
cv.width = W;
|
||||
cv.height = H;
|
||||
const ctx = cv.getContext('2d');
|
||||
if (!ctx) throw new Error('canvas 不可用');
|
||||
|
||||
const bg = bgDataUrl ? await loadImage(bgDataUrl) : null;
|
||||
if (bg && (bg.naturalWidth || bg.width)) {
|
||||
const { w: iw, h: ih } = measureImage(bg);
|
||||
const scale = Math.max(W / iw, H / ih);
|
||||
const dw = iw * scale;
|
||||
const dh = ih * scale;
|
||||
ctx.drawImage(bg, (W - dw) / 2, (H - dh) / 2, dw, dh);
|
||||
// 暗化渐变蒙版,保证文字可读
|
||||
const veil = ctx.createLinearGradient(0, 0, 0, H);
|
||||
veil.addColorStop(0, 'rgba(8,10,30,0.42)');
|
||||
veil.addColorStop(0.5, 'rgba(8,10,30,0.58)');
|
||||
veil.addColorStop(1, 'rgba(8,10,30,0.78)');
|
||||
ctx.fillStyle = veil;
|
||||
ctx.fillRect(0, 0, W, H);
|
||||
} else {
|
||||
// 无背景:深色渐变 + 光斑,质感不输生图
|
||||
const g = ctx.createLinearGradient(0, 0, W, H);
|
||||
g.addColorStop(0, '#101a4d');
|
||||
g.addColorStop(0.55, '#25124f');
|
||||
g.addColorStop(1, '#0b1030');
|
||||
ctx.fillStyle = g;
|
||||
ctx.fillRect(0, 0, W, H);
|
||||
const blob = (cx: number, cy: number, r: number, c: string) => {
|
||||
const rg = ctx.createRadialGradient(cx, cy, 0, cx, cy, r);
|
||||
rg.addColorStop(0, c);
|
||||
rg.addColorStop(1, 'rgba(0,0,0,0)');
|
||||
ctx.fillStyle = rg;
|
||||
ctx.beginPath();
|
||||
ctx.arc(cx, cy, r, 0, Math.PI * 2);
|
||||
ctx.fill();
|
||||
};
|
||||
blob(220, 160, 380, 'rgba(88,120,255,0.35)');
|
||||
blob(1080, 560, 420, 'rgba(255,95,140,0.28)');
|
||||
blob(640, 360, 460, 'rgba(255,196,64,0.14)');
|
||||
}
|
||||
|
||||
const main = copy.main || '视频封面';
|
||||
const sub = (copy.sub || '').slice(0, 24);
|
||||
const tag = (copy.tag || '').slice(0, 8);
|
||||
|
||||
// 主标题:可拆两行,字号尽量大
|
||||
let lines = [main];
|
||||
if (main.length > 9) {
|
||||
const cut = Math.ceil(main.length / 2);
|
||||
lines = [main.slice(0, cut), main.slice(cut)];
|
||||
}
|
||||
const mainSize = fitFont(ctx, lines.reduce((a, b) => (a.length > b.length ? a : b)), W - 180, lines.length > 1 ? 132 : 168, 72);
|
||||
const lineH = mainSize * 1.2;
|
||||
|
||||
const tagH = tag ? 66 : 0;
|
||||
const subSize = sub ? fitFont(ctx, sub, W - 240, 62, 36, '800') : 0;
|
||||
const subGap = sub ? 40 : 0;
|
||||
const totalH = tagH + 34 + lines.length * lineH + subGap + (sub ? subSize : 0);
|
||||
let cursorY = (H - totalH) / 2 + tagH / 2;
|
||||
|
||||
// 角标胶囊
|
||||
if (tag) {
|
||||
const tagSize = 40;
|
||||
ctx.font = `900 ${tagSize}px "PingFang SC", "Microsoft YaHei", "Noto Sans CJK SC", sans-serif`;
|
||||
const tw = ctx.measureText(tag).width;
|
||||
const pw = tw + 80;
|
||||
const ph = 66;
|
||||
const px = W / 2 - pw / 2;
|
||||
const py = cursorY - ph / 2;
|
||||
const r = ph / 2;
|
||||
ctx.beginPath();
|
||||
ctx.moveTo(px + r, py);
|
||||
ctx.arcTo(px + pw, py, px + pw, py + ph, r);
|
||||
ctx.arcTo(px + pw, py + ph, px, py + ph, r);
|
||||
ctx.arcTo(px, py + ph, px, py, r);
|
||||
ctx.arcTo(px, py, px + pw, py, r);
|
||||
ctx.closePath();
|
||||
ctx.save();
|
||||
ctx.shadowColor = 'rgba(255,196,64,0.85)';
|
||||
ctx.shadowBlur = 26;
|
||||
const bgg = ctx.createLinearGradient(px, py, px + pw, py + ph);
|
||||
bgg.addColorStop(0, '#ffd166');
|
||||
bgg.addColorStop(1, '#ff9f43');
|
||||
ctx.fillStyle = bgg;
|
||||
ctx.fill();
|
||||
ctx.restore();
|
||||
ctx.fillStyle = '#3a1d00';
|
||||
ctx.textAlign = 'center';
|
||||
ctx.textBaseline = 'middle';
|
||||
ctx.fillText(tag, W / 2, cursorY + 2);
|
||||
cursorY += ph / 2 + 34;
|
||||
}
|
||||
|
||||
// 主标题(发光 + 描边 + 实心,突出重点)
|
||||
const mainFill = '#ffffff';
|
||||
const mainStroke = 'rgba(6,8,24,0.92)';
|
||||
lines.forEach((ln, i) => {
|
||||
drawGlowStrokeText(ctx, ln, W / 2, cursorY + lineH / 2 + i * lineH, mainSize, mainFill, mainStroke, 'rgba(120,170,255,0.95)');
|
||||
});
|
||||
cursorY += lines.length * lineH + subGap;
|
||||
|
||||
// 副标题(暖色发光描边,次级重点)
|
||||
if (sub) {
|
||||
drawGlowStrokeText(ctx, sub, W / 2, cursorY + subSize / 2, subSize, '#ffe9a8', 'rgba(6,8,24,0.9)', 'rgba(255,196,64,0.9)', '800');
|
||||
}
|
||||
|
||||
const url = cv.toDataURL('image/png');
|
||||
if (!url || !url.startsWith('data:image/')) throw new Error('封面画布导出失败');
|
||||
return { url, w: W, h: H };
|
||||
}
|
||||
|
||||
/**
|
||||
* 自动封面:AI 根据标题/素材写吸引人的封面文案(主标题+副标题+角标),
|
||||
* 再本地渲染成大字发光描边封面(素材图作背景),不再依赖文生图。
|
||||
* @param params 标题 / 素材图 / 素材正文
|
||||
* @returns [封面, 错误];文案生成失败时仍返回模板兜底封面(local=true)
|
||||
*/
|
||||
export async function generateQuickVideoCover(params: {
|
||||
title: string;
|
||||
images?: string[];
|
||||
sourceText?: string;
|
||||
}): Promise<[QvCover | null, string | null]> {
|
||||
let copy: QvCoverCopy | null = null;
|
||||
let copyErr: string | null = null;
|
||||
if (params.title.trim()) {
|
||||
try {
|
||||
[copy, copyErr] = await askCoverCopy(params);
|
||||
} catch (e: any) {
|
||||
copyErr = e?.message || String(e);
|
||||
}
|
||||
}
|
||||
if (!copy) copy = templateCoverCopy(params);
|
||||
|
||||
// 背景优先用第一张素材图(转 data URL 避免画布跨域污染)
|
||||
let bg = '';
|
||||
const first = params.images?.length ? params.images[0] : '';
|
||||
if (first) bg = first.startsWith('data:') ? first : await toDataUrl(first);
|
||||
|
||||
try {
|
||||
const out = await renderCover(copy, bg || undefined);
|
||||
return [{ ...out, local: !copy.ai, copy }, copyErr];
|
||||
} catch (e: any) {
|
||||
return [null, copyErr || e?.message || String(e)];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 合成一段配音,返回可直接用于 <audio> 的同源地址
|
||||
*/
|
||||
|
||||
Reference in new issue
Block a user