sync: 同步总仓库 luoguang/monkey-ai weiyuan@bfdfb339 的 web/ 改动

同步基准:总仓库 a2ca13cb(= 本仓库初始导入 d8f3aee2)
范围:a2ca13cb..bfdfb339 中触及 web/ 的提交(不含 web/.claude/settings.local.json)

- 8490ac02 feat(aliyun): integrate Wan 3 and Qwen Image models
- 2aff08ec perf(analytics): 运营看板概览改读汇总表,首屏从 19s 降到 0.4s
- dc69335e feat(experience): 体验中心图像/视频创作升级(能力 schema、估价、新创作台)
- b059c657 fix(org): 下线 /org/create 自助加入企业页与 POST /api/org/join
- 4fcf47e6 fix(i18n): 修复中/英/韩/繁体多语言错乱,补齐日/越/泰译文
- e4c301d5 fix: merge enterprise task record date filters
- c9369b95 feat: expose enterprise image and video task records
- a410fee5 feat(claude): 无断点请求自动注入 cache_control 断点(方案 2)
- 521b3376 feat(claude): 缓存命中率优化——上游粘性路由 + 缓存时长强制改写
- 73b615dd feat(pricing): 企业成员不论登录身份均按所属企业等级计价与扣费
- f73f55c3 feat(client): 新增 WeyAi 版本说明管理与公开读取接口
- 8cdf1994 fix(topup): reset amount when switching from PayPal
- 93a4ac34 feat(baidu): configure Seedance liveness header by channel
- cb1818c5 fix(weyai): 按评审修正内容清理竞态、默认适用端与中文退回(M21)
- 04214d83 feat(weyai): WeyAi 内容管理与客户端内容接口(M21 第二部分)
- e3c4a57c feat(weyai): 设置页新增 WeyAi 页签与内容专用 COS 桶(M21 第一部分)
- b5ee8e70 fix(auth): 会话角色/状态以 DB 为准,修复提升管理员后管理接口报权限不足
- e4618fc2 fix: 修复企业看板日志聚合死循环导致 CPU 打满,并降低看板查询开销
- 584aad52 style(web): 个人中心侧边栏按 prettier 换行
- b8d87064 fix: 小程序教程隐藏充值后保留原步骤编号,企业充值判断直接用 isMiniProgramWebView
- eee7f5b2 fix: 小程序里企业首页不落到充值页,隐藏钱包入口与教程充值步骤
- 8b254d49 fix: 小程序里隐藏企业充值入口与页面
- a67661b4 fix(web): 小程序里个人中心默认页跳过充值和发票,避免来回跳转
- cff6c543 feat(web): WeyAi 小程序里打开个人中心时不出现充值和开票
- c6c99eb6 feat(billing): Claude 全部缓存写入统一按 1h 倍率计费
- 0699d1bf fix(web): 小程序 web-view 里注册页同样只显示站内方式
- 04853331 feat(web): WeyAi 小程序 web-view 里登录页只显示站内登录方式
This commit is contained in:
qiubaishen
2026-11-10 11:05:34 +08:00
parent d8f3aee261
commit 6160a23117
275 changed files with 38656 additions and 7694 deletions
@@ -0,0 +1,361 @@
/*
Copyright (C) 2025 QuantumNous
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
For commercial licensing, please contact support@quantumnous.com
*/
// 系统设置 →「WeyAi」→「内容存储」(M21):WeyAi 展示内容(作品视频、封面、模板包)
// 专用的 COS 桶。和系统 COS 桶分开,权限、费用、生命周期都单独管;没配置时
// 内容功能整体关闭,不会退回系统桶。只对超级管理员显示,后端按 root-only 校验。
import React, { useCallback, useEffect, useState } from 'react';
import {
Banner,
Button,
Card,
Col,
Form,
Input,
Row,
Spin,
Switch,
Typography,
} from '@douyinfe/semi-ui';
import { useTranslation } from 'react-i18next';
import { API, showError, showSuccess } from '../../../helpers';
const { Text } = Typography;
const MASKED_PLACEHOLDER = '***ALREADY_SET***';
const BUCKET_KEY = 'WeyAiContentCosBucket';
const REGION_KEY = 'WeyAiContentCosRegion';
const SECRET_ID_KEY = 'WeyAiContentCosSecretId';
const SECRET_KEY_KEY = 'WeyAiContentCosSecretKey';
const USE_SYSTEM_KEY = 'WeyAiContentCosUseSystemKey';
const KEY_LABELS = {
[BUCKET_KEY]: '存储桶名称',
[REGION_KEY]: '地域',
[SECRET_ID_KEY]: 'SecretId',
[SECRET_KEY_KEY]: 'SecretKey',
[USE_SYSTEM_KEY]: '沿用系统 COS 的密钥',
};
const CHECK_LABELS = {
config: '配置完整',
bucket: '能访问存储桶',
write: '能写入并删除对象',
cors: '已有浏览器直传所需的跨域规则',
};
const EMPTY_VALUES = {
[BUCKET_KEY]: '',
[REGION_KEY]: '',
[SECRET_ID_KEY]: '',
[USE_SYSTEM_KEY]: false,
};
const SettingsWeyAiContentStorage = () => {
const { t } = useTranslation();
const [loading, setLoading] = useState(true);
const [saving, setSaving] = useState(false);
const [testing, setTesting] = useState(false);
const [writingCors, setWritingCors] = useState(false);
const [values, setValues] = useState(EMPTY_VALUES);
const [original, setOriginal] = useState(EMPTY_VALUES);
const [secretKeySet, setSecretKeySet] = useState(false);
const [secretKeyInput, setSecretKeyInput] = useState('');
const [checks, setChecks] = useState(null);
const load = useCallback(async () => {
setLoading(true);
try {
const res = await API.get('/api/option/');
if (!res?.data?.success) {
showError(res?.data?.message || t('加载失败,请重试'));
return;
}
const map = {};
(res.data.data || []).forEach((item) => {
map[item.key] = item.value;
});
const next = {
[BUCKET_KEY]: map[BUCKET_KEY] || '',
[REGION_KEY]: map[REGION_KEY] || '',
[SECRET_ID_KEY]: map[SECRET_ID_KEY] || '',
[USE_SYSTEM_KEY]: map[USE_SYSTEM_KEY] === 'true',
};
setValues(next);
setOriginal(next);
setSecretKeySet(Boolean(map[SECRET_KEY_KEY]));
setSecretKeyInput('');
} catch (_e) {
showError(t('加载失败,请重试'));
} finally {
setLoading(false);
}
}, [t]);
useEffect(() => {
load();
}, [load]);
const setField = (key) => (value) =>
setValues((prev) => ({ ...prev, [key]: value }));
const save = async () => {
const updates = [];
Object.keys(values).forEach((key) => {
if (values[key] !== original[key]) {
const value =
typeof values[key] === 'boolean'
? String(values[key])
: values[key].trim();
updates.push({ key, value });
}
});
// 密钥只在填写了新值时提交,留空不覆盖已保存的值
const secret = secretKeyInput.trim();
if (secret && secret !== MASKED_PLACEHOLDER) {
updates.push({ key: SECRET_KEY_KEY, value: secret });
}
if (updates.length === 0) {
showSuccess(t('没有需要保存的修改'));
return;
}
setSaving(true);
try {
const results = await Promise.all(
updates.map((item) =>
API.put('/api/option/', item, { skipErrorHandler: true }).then(
(res) => ({ key: item.key, res }),
(err) => ({ key: item.key, err }),
),
),
);
const failed = results.filter(({ res }) => !res?.data?.success);
if (failed.length > 0) {
failed.forEach(({ key, res, err }) => {
const message =
res?.data?.message ||
err?.response?.data?.message ||
t('保存失败,请重试');
showError(
t('{{label}}:{{message}}', {
label: t(KEY_LABELS[key] || key),
message,
}),
);
});
// 已成功的项记为新的原值,改回旧值时才能再次提交
const saved = results
.filter(({ res }) => res?.data?.success)
.map(({ key }) => key);
setOriginal((prev) => {
const next = { ...prev };
saved.forEach((key) => {
if (key in values) next[key] = values[key];
});
return next;
});
if (saved.includes(SECRET_KEY_KEY)) {
setSecretKeySet(true);
setSecretKeyInput('');
}
return;
}
showSuccess(t('保存成功'));
setChecks(null);
await load();
} finally {
setSaving(false);
}
};
const dirty =
secretKeyInput.trim() !== '' ||
Object.keys(values).some((key) => values[key] !== original[key]);
const runTest = async () => {
setTesting(true);
try {
const res = await API.post(
'/api/option/weyai/content_storage/test',
{},
{ skipErrorHandler: true },
);
if (!res?.data?.success) {
showError(res?.data?.message || t('测试失败,请重试'));
return;
}
setChecks(res.data.data?.checks || []);
} catch (err) {
showError(err?.response?.data?.message || t('测试失败,请重试'));
} finally {
setTesting(false);
}
};
const writeCors = async () => {
setWritingCors(true);
try {
const res = await API.post(
'/api/option/weyai/content_storage/cors',
{},
{ skipErrorHandler: true },
);
if (!res?.data?.success) {
showError(res?.data?.message || t('写入失败,请重试'));
return;
}
showSuccess(t('跨域规则已写入'));
await runTest();
} catch (err) {
showError(err?.response?.data?.message || t('写入失败,请重试'));
} finally {
setWritingCors(false);
}
};
const corsMissing = checks?.some(
(check) => check.name === 'cors' && !check.ok,
);
return (
<Card>
<Form.Section
text={t('内容存储')}
extraText={t(
'WeyAi 展示内容(作品视频、封面、模板包)专用的腾讯云 COS 存储桶,和系统 COS 桶分开;没有配置时内容功能不可用,不会改用系统桶',
)}
>
<Spin spinning={loading}>
<Banner
type='info'
closeIcon={null}
className='mb-4'
description={t(
'请在腾讯云单独建一个私有读写的存储桶,推荐再建一个只授权给这个桶的子账号密钥。客户端拿到的是有时效的签名地址,不需要公有读',
)}
/>
<Row gutter={16}>
<Col xs={24} md={12} className='mb-3'>
<Text className='block mb-1'>{t('存储桶名称')}</Text>
<Input
value={values[BUCKET_KEY]}
onChange={setField(BUCKET_KEY)}
placeholder='weyai-content-1250000000'
aria-label={t('存储桶名称')}
/>
<Text type='tertiary' size='small'>
{t('带 APPID 后缀的完整桶名')}
</Text>
</Col>
<Col xs={24} md={12} className='mb-3'>
<Text className='block mb-1'>{t('地域')}</Text>
<Input
value={values[REGION_KEY]}
onChange={setField(REGION_KEY)}
placeholder='ap-guangzhou'
aria-label={t('地域')}
/>
</Col>
</Row>
<div className='mb-3 flex items-center gap-2'>
<Switch
checked={values[USE_SYSTEM_KEY]}
onChange={setField(USE_SYSTEM_KEY)}
aria-label={t('沿用系统 COS 的密钥')}
/>
<Text>{t('沿用系统 COS 的密钥')}</Text>
</div>
<Text type='tertiary' size='small' className='block mb-3'>
{values[USE_SYSTEM_KEY]
? t(
'使用「运营设置」里腾讯云 COS 的 SecretId 和 SecretKey,只需填写桶名和地域;那组密钥要有这个桶的读写权限',
)
: t(
'填写一组有这个桶读写权限的密钥;推荐使用只授权给这个桶的子账号密钥,泄露时影响最小',
)}
</Text>
{!values[USE_SYSTEM_KEY] && (
<Row gutter={16}>
<Col xs={24} md={12} className='mb-3'>
<Text className='block mb-1'>SecretId</Text>
<Input
value={values[SECRET_ID_KEY]}
onChange={setField(SECRET_ID_KEY)}
aria-label='SecretId'
/>
</Col>
<Col xs={24} md={12} className='mb-3'>
<Text className='block mb-1'>SecretKey</Text>
<Input
mode='password'
value={secretKeyInput}
onChange={setSecretKeyInput}
aria-label='SecretKey'
placeholder={
secretKeySet
? t('已设置,留空则不修改')
: t('敏感信息不会发送到前端显示')
}
/>
</Col>
</Row>
)}
<div className='flex flex-wrap gap-2 mt-2'>
<Button type='primary' loading={saving} onClick={save}>
{t('保存')}
</Button>
<Button loading={testing} disabled={dirty} onClick={runTest}>
{t('测试连接')}
</Button>
{corsMissing && (
<Button loading={writingCors} onClick={writeCors}>
{t('写入跨域规则')}
</Button>
)}
</div>
{dirty && (
<Text type='tertiary' size='small' className='block mt-2'>
{t('测试的是已保存的配置,请先保存再测试')}
</Text>
)}
{checks && (
<div className='mt-4'>
{checks.map((check) => (
<div key={check.name} className='mb-1'>
<Text type={check.ok ? 'success' : 'danger'}>
{check.ok ? '✓ ' : '✗ '}
{t(CHECK_LABELS[check.name] || check.name)}
</Text>
{!check.ok && check.message && (
<Text type='tertiary' size='small' className='ml-2'>
{check.message}
</Text>
)}
</div>
))}
</div>
)}
</Spin>
</Form.Section>
</Card>
);
};
export default SettingsWeyAiContentStorage;