1
This commit is contained in:
69
src/config/videoPipeline.js
Normal file
69
src/config/videoPipeline.js
Normal file
@@ -0,0 +1,69 @@
|
||||
/**
|
||||
* 流水线配置校验:优先使用 Rust 缓存的 desktop_configs(get_app_config)。
|
||||
* 实际密钥由 Node 子进程通过环境变量 AICLIENT_CFG_* 读取,无需在前端 params 传递。
|
||||
*/
|
||||
|
||||
import { invoke } from "@tauri-apps/api/core";
|
||||
|
||||
/** @returns {Promise<{ ok: true } | { ok: false, message: string }>} */
|
||||
export async function ensureAppConfigReady() {
|
||||
try {
|
||||
const map = await invoke("get_app_config");
|
||||
if (map && typeof map === "object" && Object.keys(map).length > 0) {
|
||||
const apiKey =
|
||||
map.LLM_API_KEY ||
|
||||
map.llm_api_key ||
|
||||
map["llm.api_key"];
|
||||
if (!apiKey) {
|
||||
return {
|
||||
ok: false,
|
||||
message: "服务端配置缺少 LLM_API_KEY,请在 desktop_configs 表中维护",
|
||||
};
|
||||
}
|
||||
return { ok: true };
|
||||
}
|
||||
const serverMsg = await invoke("get_app_config_last_message");
|
||||
if (serverMsg) {
|
||||
return { ok: false, message: String(serverMsg) };
|
||||
}
|
||||
return {
|
||||
ok: false,
|
||||
message: "未获取到应用配置,请先登录并确保 desktop_configs 表有数据",
|
||||
};
|
||||
} catch {
|
||||
return {
|
||||
ok: false,
|
||||
message: "请在 Tauri 桌面端登录后使用(配置由服务端下发)",
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
const DOUYIN_RE = /douyin\.com|iesdouyin\.com|v\.douyin\.com/i;
|
||||
const DIRECT_VIDEO_RE = /\.(mp4|mov|m4v|webm|mkv|flv|avi)(\?|$)/i;
|
||||
|
||||
/** @returns {{ ok: true, value: string } | { ok: false, message: string }} */
|
||||
export function validateShareText(text) {
|
||||
const raw = String(text || "").trim();
|
||||
if (!raw) {
|
||||
return { ok: false, message: "请粘贴视频分享文本或视频链接" };
|
||||
}
|
||||
const urls = raw.match(/https?:\/\/[^\s\u4e00-\u9fa5]+/gi) || [];
|
||||
if (urls.some((u) => DIRECT_VIDEO_RE.test(u))) {
|
||||
return { ok: true, value: raw };
|
||||
}
|
||||
if (DOUYIN_RE.test(raw) || urls.some((u) => DOUYIN_RE.test(u))) {
|
||||
return { ok: true, value: raw };
|
||||
}
|
||||
return {
|
||||
ok: false,
|
||||
message:
|
||||
"请输入抖音分享文本、抖音视频链接,或直接视频文件链接(mp4/mov/webm/mkv/avi)",
|
||||
};
|
||||
}
|
||||
|
||||
export const DEFAULT_REWRITE_CONFIG = {
|
||||
style: "casual",
|
||||
length: "medium",
|
||||
keepHashtags: true,
|
||||
keepEmoji: true,
|
||||
};
|
||||
Reference in New Issue
Block a user