import { apiInterceptors, postAgentMy, postAgentUninstall, postAgentUpload } from '@/client/api'; import { IMyPlugin } from '@/types/agent'; import { ClearOutlined, LoadingOutlined, UploadOutlined } from '@ant-design/icons'; import { useRequest } from 'ahooks'; import { Button, Card, Spin, Tag, Tooltip, Upload, UploadProps, message } from 'antd'; import { useCallback, useState } from 'react'; import { useTranslation } from 'react-i18next'; import MyEmpty from '../common/MyEmpty'; function MyPlugins() { const { t } = useTranslation(); const [messageApi, contextHolder] = message.useMessage(); const [uploading, setUploading] = useState(false); const [isError, setIsError] = useState(false); const [actionIndex, setActionIndex] = useState(); const { data = [], loading, refresh, } = useRequest(async () => { const [err, res] = await apiInterceptors(postAgentMy()); setIsError(!!err); return res ?? []; }); const uninstall = async (name: string, index: number) => { if (actionIndex) return; setActionIndex(index); const [err] = await apiInterceptors(postAgentUninstall(name)); message[err ? 'error' : 'success'](err ? 'failed' : 'success'); !err && refresh(); setActionIndex(undefined); }; const renderAction = useCallback( (item: IMyPlugin, index: number) => { if (index === actionIndex) { return ; } return (
{ uninstall(item.name, index); }} >
); }, [actionIndex], ); const onChange: UploadProps['onChange'] = async info => { if (!info) { message.error('Please select the *.zip,*.rar file'); return; } try { const file = info.file; setUploading(true); const formData = new FormData(); formData.append('doc_file', file as any); messageApi.open({ content: `Uploading ${file.name}`, type: 'loading', duration: 0 }); const [err] = await apiInterceptors(postAgentUpload(undefined, formData, { timeout: 60000 })); if (err) return; message.success('success'); refresh(); } catch (e: any) { message.error(e?.message || 'Upload Error'); } finally { setUploading(false); messageApi.destroy(); } }; return ( {contextHolder}
false} name='file' accept='.zip,.rar' multiple={false} onChange={onChange} showUploadList={{ showDownloadIcon: false, showPreviewIcon: false, showRemoveIcon: false, }} itemRender={() => <>} >
{!data.length && !loading && }
{data.map((item, index) => (

{item.name}

{item.version && v{item.version}} {item.type && Type {item.type}}

{item.description}

))}
); } export default MyPlugins;