Let's use AI to Earn!
TypeScript auto-publishdouyindouyin-apielectron-appelectron-reactkuaishoukwaipublishedshipinhaotoolxiaohongshu
fix(web): MCP Key Detail Modal API & i18n Enhancement (#332)
布莱恩·奥夫托·杰森张5ba28fd0702a
diff --git a/project/web/src/app/[lng]/accounts/components/AccountSidebar/MCPKeyDetailModal.tsx b/project/web/src/app/[lng]/accounts/components/AccountSidebar/MCPKeyDetailModal.tsxindex 902dfe24..8743b47d 100644--- a/project/web/src/app/[lng]/accounts/components/AccountSidebar/MCPKeyDetailModal.tsx+++ b/project/web/src/app/[lng]/accounts/components/AccountSidebar/MCPKeyDetailModal.tsx@@ -1,9 +1,7 @@-import type { SocialAccount } from '@/api/types/account.type'import type { PlatType } from '@/app/config/platConfig'import { CopyOutlined, DeleteOutlined, KeyOutlined, UserOutlined } from '@ant-design/icons'import { Avatar, Button, Empty, List, message, Modal, Pagination, Popconfirm, Space, Tag } from 'antd'import React, { forwardRef, memo, useEffect, useImperativeHandle, useState } from 'react'-import { getAccountListApi } from '@/api/account'import { apiDeleteMCPRef, apiGetMCPRefList } from '@/api/mcp'import { AccountPlatInfoMap } from '@/app/config/platConfig'import { useTransClient } from '@/app/i18n/client'@@ -30,9 +28,8 @@ const MCPKeyDetailModal = memo(const [currentPage, setCurrentPage] = useState(1)const [pageSize, setPageSize] = useState(10)const [total, setTotal] = useState(0)- const [accountList, setAccountList] = useState<SocialAccount[]>([])- // 获取平台信息+ // Get platform informationconst getPlatformInfo = (platformType: string) => {const platInfo = AccountPlatInfoMap.get(platformType as PlatType)return {@@ -42,20 +39,7 @@ const MCPKeyDetailModal = memo(}}- // 获取所有账户列表- const fetchAccountList = async () => {- try {- const res: any = await getAccountListApi()- if (res?.code === 0) {- setAccountList(res.data || [])- }- }- catch (error) {- console.error('获取账户列表失败:', error)- }- }-- // 获取关联账户列表+ // Fetch associated accounts listconst fetchRefList = async () => {if (!keyInfo?.key)return@@ -64,23 +48,14 @@ const MCPKeyDetailModal = memo(setLoading(true)const res: any = await apiGetMCPRefList(currentPage, pageSize, keyInfo.key)if (res?.code === 0) {+ // API returns account data directly (no need to map)const refListData = res.data.list || []-- // 将账户ID映射到完整的账户信息- const enrichedRefList = refListData.map((refItem: any) => {- const accountInfo = accountList.find(account => account.id === refItem)- return {- ...refItem,- account: accountInfo || null,- }- })-- setRefList(enrichedRefList)+ setRefList(refListData)setTotal(res.data.total || 0)}}catch (error) {- message.error('获取关联账户列表失败')+ message.error(t('mcpManager.keyDetail.fetchAccountsFailed' as any))}finally {setLoading(false)@@ -88,39 +63,32 @@ const MCPKeyDetailModal = memo(}useEffect(() => {- if (open) {- fetchAccountList()- }- }, [open])-- useEffect(() => {- if (open && keyInfo && accountList.length > 0) {+ if (open && keyInfo) {fetchRefList()}- }, [open, keyInfo, currentPage, pageSize, accountList])+ }, [open, keyInfo, currentPage, pageSize])const handleCopyKey = (key: string) => {navigator.clipboard.writeText(key)- message.success('Key已复制到剪贴板')+ message.success(t('mcpManager.keyCopied' as any))}const handleUnlinkAccount = async (accountId: string) => {- console.log(accountId)try {const res = await apiDeleteMCPRef({key: keyInfo.key,accountId,})if (res?.code === 0) {- message.success('解除关联成功')- fetchRefList() // 刷新列表+ message.success(t('mcpManager.keyDetail.unlinkSuccess' as any))+ fetchRefList() // Refresh list}else {- message.error('解除关联失败')+ message.error(t('mcpManager.keyDetail.unlinkFailed' as any))}}catch (error) {- message.error('解除关联失败')+ message.error(t('mcpManager.keyDetail.unlinkFailed' as any))}}@@ -153,7 +121,7 @@ const MCPKeyDetailModal = memo(title={(<div style={{ display: 'flex', alignItems: 'center', gap: '8px' }}><KeyOutlined style={{ color: '#625BF2' }} />- MCP Key 详情+ {t('mcpManager.keyDetail.title' as any)}</div>)}open={open}@@ -164,59 +132,55 @@ const MCPKeyDetailModal = memo(>{keyInfo && (<>- {/* Key基本信息 */}+ {/* Key basic information */}<div className={styles.keyInfo}><div className={styles.keyHeader}><div className={styles.keyName}>- <span className={styles.label}>Key名称:</span>+ <span className={styles.label}>{t('mcpManager.keyDetail.keyName' as any)}</span><span className={styles.value}>{keyInfo.desc}</span></div><Space>- <Tag color={keyInfo.status === 1 ? 'green' : 'red'}>- {keyInfo.status === 1 ? '可用' : '不可用'}+ <Tag color={keyInfo.status === 'ACTIVE' ? 'green' : 'red'}>+ {keyInfo.status}</Tag><Buttontype="link"icon={<CopyOutlined />}onClick={() => handleCopyKey(keyInfo.key)}>- 复制Key+ {t('mcpManager.keyDetail.copyKey' as any)}</Button></Space></div><div className={styles.keyValue}>- <span className={styles.label}>Key值:</span>+ <span className={styles.label}>{t('mcpManager.keyDetail.keyValue' as any)}</span><span className={styles.value}>{keyInfo.key}</span></div><div className={styles.keyMeta}><div className={styles.metaItem}>- <span className={styles.label}>创建时间:</span>+ <span className={styles.label}>{t('mcpManager.keyDetail.createdTime' as any)}</span><span>{keyInfo.createdAt}</span></div><div className={styles.metaItem}>- <span className={styles.label}>关联账户:</span>- <span>- {total}- {' '}- 个- </span>+ <span className={styles.label}>{t('mcpManager.keyDetail.associatedAccounts' as any)}</span>+ <span>{t('mcpManager.keyDetail.accountsCount' as any, { count: total })}</span></div></div></div>- {/* 关联账户列表 */}+ {/* Associated accounts list */}<div className={styles.refList}><div className={styles.sectionTitle}><UserOutlined />- 关联账户列表+ {t('mcpManager.keyDetail.associatedAccountsList' as any)}</div>{refList.length === 0 && !loading? (<div className={styles.emptyState}>- <Empty description="暂无关联账户" />+ <Empty description={t('mcpManager.keyDetail.noAccounts' as any)} /></div>): (@@ -226,15 +190,15 @@ const MCPKeyDetailModal = memo(dataSource={refList}loading={loading}renderItem={(item) => {- const platformInfo = getPlatformInfo(item.account?.type)+ const platformInfo = getPlatformInfo(item.accountType)return (<List.Itemactions={[<Popconfirm- title="确定要解除关联吗?"- onConfirm={() => handleUnlinkAccount(item.account.id)}- okText="确定"- cancelText="取消"+ title={t('mcpManager.keyDetail.unlinkConfirm' as any)}+ onConfirm={() => handleUnlinkAccount(item.accountId)}+ okText={t('mcpManager.keyDetail.ok' as any)}+ cancelText={t('mcpManager.keyDetail.cancel' as any)}><Buttonkey="unlink"@@ -242,14 +206,14 @@ const MCPKeyDetailModal = memo(dangericon={<DeleteOutlined />}>- 解除关联+ {t('mcpManager.keyDetail.unlinkButton' as any)}</Button></Popconfirm>,]}><List.Item.Meta- avatar={<Avatar src={item.account?.avatar} />}- title={item.account?.nickname || t('unknownAccount')}+ avatar={item.avatar ? <Avatar src={item.avatar} /> : <Avatar icon={<UserOutlined />} />}+ title={item.name || item.nickname || item.accountId}description={(<div><div style={{ display: 'flex', alignItems: 'center', gap: '8px' }}>@@ -284,7 +248,7 @@ const MCPKeyDetailModal = memo(total={total}showSizeChangershowQuickJumper- showTotal={(total, range) => `第 ${range[0]}-${range[1]} 条,共 ${total} 条`}+ showTotal={(total, range) => t('mcpManager.keyDetail.paginationText' as any, { start: range[0], end: range[1], total })}onChange={(page, size) => {setCurrentPage(page)setPageSize(size)diff --git a/project/web/src/app/[lng]/accounts/components/AccountSidebar/MCPManagerModal.tsx b/project/web/src/app/[lng]/accounts/components/AccountSidebar/MCPManagerModal.tsxindex a44225d3..492a3d31 100644--- a/project/web/src/app/[lng]/accounts/components/AccountSidebar/MCPManagerModal.tsx+++ b/project/web/src/app/[lng]/accounts/components/AccountSidebar/MCPManagerModal.tsx@@ -87,20 +87,20 @@ const MCPManagerModal = memo(}// 创建关联(如果选择了多个账户,需要多次请求)- const createdKey = (createRes.data as any)?.key- if (createdKey) {- for (const account of accounts) {- try {- await apiCreateMCPRef({- key: createdKey,- accountId: account.id,- })- }- catch (error) {- console.error(t('mcpManager.createAssociationFailed', { account: account.account }), error)- }- }- }+ // const createdKey = (createRes.data as any)?.key+ // if (createdKey) {+ // for (const account of accounts) {+ // try {+ // await apiCreateMCPRef({+ // key: createdKey,+ // accountId: account.id,+ // })+ // }+ // catch (error) {+ // console.error(t('mcpManager.createAssociationFailed', { account: account.account }), error)+ // }+ // }+ // }setSelectedAccounts([])setIsCreateModalOpen(false)@@ -224,8 +224,8 @@ const MCPManagerModal = memo(title={(<Space><span>{item.desc}</span>- <Tag color={item.status === 1 ? 'green' : 'red'}>- {item.status === 1 ? t('mcpManager.available') : t('mcpManager.unavailable')}+ <Tag color={item.status === 'ACTIVE' ? 'green' : 'red'}>+ {item.status}</Tag></Space>)}diff --git a/project/web/src/app/[lng]/accounts/components/CalendarTiming/useCalendarTiming.ts b/project/web/src/app/[lng]/accounts/components/CalendarTiming/useCalendarTiming.tsindex df72758b..3c9830df 100644--- a/project/web/src/app/[lng]/accounts/components/CalendarTiming/useCalendarTiming.ts+++ b/project/web/src/app/[lng]/accounts/components/CalendarTiming/useCalendarTiming.ts@@ -190,7 +190,7 @@ export const useCalendarTiming = create(// 轮询查询发布任务详情async _pollQueryPubTask(pubRecord: PublishRecordItem) {// 延迟 5 秒- await new Promise(resolve => setTimeout(resolve, 5000))+ await new Promise(resolve => setTimeout(resolve, 20000))try {const res = await getPublishRecordDetail(pubRecord.flowId!)diff --git a/project/web/src/app/i18n/locales/en/account.json b/project/web/src/app/i18n/locales/en/account.jsonindex 2d170cb9..90b60f0b 100644--- a/project/web/src/app/i18n/locales/en/account.json+++ b/project/web/src/app/i18n/locales/en/account.json@@ -219,6 +219,25 @@"selectAccountsButton": "Select Accounts","create": "Create","cancel": "Cancel"+ },+ "keyDetail": {+ "title": "MCP Key Details",+ "keyName": "Key Name:",+ "keyValue": "Key Value:",+ "createdTime": "Created Time:",+ "associatedAccounts": "Associated Accounts:",+ "accountsCount": "{{count}} account(s)",+ "associatedAccountsList": "Associated Accounts List",+ "noAccounts": "No associated accounts",+ "fetchAccountsFailed": "Failed to fetch associated accounts",+ "unlinkSuccess": "Unlinked successfully",+ "unlinkFailed": "Failed to unlink",+ "unlinkConfirm": "Are you sure to unlink this account?",+ "unlinkButton": "Unlink",+ "copyKey": "Copy Key",+ "ok": "OK",+ "cancel": "Cancel",+ "paginationText": "{{start}}-{{end}} of {{total}} items"}},"mediaTypes": {diff --git a/project/web/src/app/i18n/locales/zh-CN/account.json b/project/web/src/app/i18n/locales/zh-CN/account.jsonindex 18445eb3..06b5f41e 100644--- a/project/web/src/app/i18n/locales/zh-CN/account.json+++ b/project/web/src/app/i18n/locales/zh-CN/account.json@@ -219,6 +219,25 @@"selectAccountsButton": "选择账户","create": "创建","cancel": "取消"+ },+ "keyDetail": {+ "title": "MCP Key 详情",+ "keyName": "Key名称:",+ "keyValue": "Key值:",+ "createdTime": "创建时间:",+ "associatedAccounts": "关联账户:",+ "accountsCount": "{{count}} 个",+ "associatedAccountsList": "关联账户列表",+ "noAccounts": "暂无关联账户",+ "fetchAccountsFailed": "获取关联账户列表失败",+ "unlinkSuccess": "解除关联成功",+ "unlinkFailed": "解除关联失败",+ "unlinkConfirm": "确定要解除关联吗?",+ "unlinkButton": "解除关联",+ "copyKey": "复制Key",+ "ok": "确定",+ "cancel": "取消",+ "paginationText": "第 {{start}}-{{end}} 条,共 {{total}} 条"}},"mediaTypes": {