Files
unicut/src/components/header/Header.tsx
T
jinghui 59241af720 本地化改造:免登录 + 本机 AI + 离线可用
在上游 gitee.com/676015863/unicut 基础上做的自托管改造,使其可脱离官方账号体系
与 CDN 独立运行。详见 CHANGELOG.md。

主要能力
- 免登录:GUEST_USER 直接使用核心功能,checkAuth 不再拦截
- 本机 AI:对话 mimo-v2.6-flash(同源 /newapi/v1)、视觉 deepseek-v4-flash-vision-exp、
  生图 /omniai、生视频 /civideo;密钥仅存服务端(nginx 占位符 + entrypoint 注入)
- AI 一键出片:图片+标题 → AI 文案 → 人声/语速/情绪 → 确认生成直接排时间轴,
  并支持转场、图片运镜、字幕位置/大小/配色/入场动画
- 离线可用:工程数据 IndexedDB + 项目文件 JSON 双写;官方素材走同源 /cdn/ 反代;
  无 OPFS 时素材回落 IndexedDB files 表

修复
- 账号类接口本地短路,不再反复弹「Header parameter [authorization] cannot be empty」
- isFSApiSupported 改取值判断,修 OPFS 判定错误导致卡在文件夹引导页
- 模板素材统一 /cdn/ 改写 + nginx 兜底转发,修缩略图全裂
- 剔除素材已失效的模板(上游 CDN 已删,点开必卡 loading 50%)
- 补齐 SDK 内置 4 张滤镜贴图,修画布卡 loading 0%
- 封面上传失败不再中断整次保存

品牌与页面
- 「云剪」改为 UniCut
- 首页删除收费标准栏目;顶部菜单移除 GitHub/Gitee;底部栏整体下线

安全
- .env 与 public/local-ai.json(含密钥)已在 .gitignore,不入库
- public/local-ai.json.example 仅含占位符
2026-10-26 18:18:41 +08:00

167 lines
5.8 KiB
TypeScript

import React, { useReducer, useEffect, useState } from 'react';
import styles from './header.module.less';
import { NavLink, Link, withRouter } from 'react-router-dom';
import { observer } from 'mobx-react';
import { user } from '@stores/user';
import logoImg from '@images/logo2.png';
import { Button, Popover, Avatar, Space, Toast } from '@douyinfe/semi-ui';
import Login from '@components/login';
import User from './user/User';
import { config } from '@config/index';
import { theme, ThemeName } from '@theme';
import { layout } from '@stores/layout';
import { IconDuration, IconSun } from '@douyinfe/semi-icons';
import { getInitData } from '@config/initData';
import { server } from './server';
import { pubsub } from '@utils/pubsub';
import Intl from '@language/Intl';
import { language } from '@language/language';
import { AllApplication, Box, International } from '@icon-park/react';
import classNames from 'classnames';
import { reURL } from '@utils/util';
import VipRecharge from '@pages/editor/components/header/VipRecharge';
import CreditRecharge from '@pages/editor/components/header/CreditRecharge';
export interface IProps {
componentName?: string;
match?: any;
navs?: any[];
}
const Header = (props: IProps) => {
// const [, forceUpdate] = useReducer(x => x + 1, 0);
const [cid = '', cname = ''] = props.match.params.cid?.split('_') || [];
const [vipRechargeVisible, setVipRechargeVisible] = useState(false);
const [creditRechargeVisible, setCreditRechargeVisible] = useState(false);
// 创建视频
const createVideo = async () => {
const initData = getInitData();
if (cid) {
initData.category_id = cid;
}
const [res, err] = await server.createVideo(initData);
if (err) {
Toast.error(err);
return;
}
location.href = `${config.editorHost}/${res.id}`;
};
useEffect(() => {
const vipSub = pubsub.subscribe('showVipRecharge', () => {
setVipRechargeVisible(true);
});
const creditSub = pubsub.subscribe('showCreditRecharge', () => {
setCreditRechargeVisible(true);
});
return () => {
pubsub.unsubscribe('showVipRecharge');
pubsub.unsubscribe('showCreditRecharge');
};
}, []);
const languageType = language.getLanguage();
return (
<div className={styles.header}>
<div className={styles.logoNav}>
<Link to="/">
<div
className={classNames({
[styles.logoen]: true,
})}
></div>
</Link>
<div className={styles.nav}>
<NavLink
to="/"
className={styles.text}
activeClassName={styles.active}
isActive={(match, location) => {
if (location.pathname === '/') {
return true;
}
}}
>
<Intl name="common_home" />
</NavLink>
{props.navs?.map((item, index) => (
<a key={index} href={item.to} className={styles.text}>
{item.name}
</a>
))}
{/* <NavLink to="/article/vip" className={styles.text} activeClassName={styles.active}>
会员中心
</NavLink> */}
{/* <NavLink to="/tools" className={styles.text} activeClassName={styles.active}>
<Intl name="common_tools" />
</NavLink> */}
<NavLink to="/article/about" className={styles.text} activeClassName={styles.active}>
<Intl name="common_about_us" />
</NavLink>
{/* 详情页优先:教程入口直接指向一篇具体文章,相关文章在页尾互相串联 */}
<NavLink
to="/article/local-deploy-guide"
className={styles.text}
activeClassName={styles.active}
>
使用教程
</NavLink>
{/* <a
href={languageType === 'en-US' ? '/docs/en' : '/docs'}
target="_blank"
className={styles.text}
>
<Intl name="common_tech_docs" />
</a> */}
</div>
</div>
<Space spacing={20}>
{/* <a
className={styles.space}
onClick={() => {
if (language.getLanguage() === 'en-US') {
language.setLanguage('zh-CN');
} else {
language.setLanguage('en-US');
}
}}
>
<Intl name="user_language" />
</a> */}
{!!user.info && (
<>
<Link to="/workspace/material" className={styles.space}>
{/* <Intl name="user_workspace" /> */}
<Box theme="outline" size="20" fill="var(--theme-icon)" />
素材
</Link>
<Link to="/workspace/draft" className={styles.space + ' ' + styles.active2}>
{/* <Intl name="user_workspace" /> */}
<AllApplication theme="outline" size="20" fill="var(--theme-icon)" />
项目
</Link>
</>
)}
{/* <a className={styles.createVideoBtn} onClick={createVideo}>
<Button theme="solid" type="primary" className={styles.create}>
<Intl name="common_create_video" />
</Button>
</a> */}
{user.info && !user.info.guest ? (
<Popover content={<User />} position="bottomRight" trigger="hover">
<Avatar src={reURL(user.info.avatar, config.resourcesHost)} size="small" color="blue" alt="Lisa LeBlanc">
{user.info.name.toUpperCase().split('')[0]}
</Avatar>
</Popover>
) : null}
</Space>
<VipRecharge visible={vipRechargeVisible} onCancel={() => setVipRechargeVisible(false)} />
<CreditRecharge visible={creditRechargeVisible} onCancel={() => setCreditRechargeVisible(false)} />
</div>
);
};
export default withRouter(observer(Header));