Skip to content

Commit 5481898

Browse files
authored
修复了应用复制后头像不显示和window系统不显示头像的问题 (#400)
* 修改了readme * 修复了应用复制后头像没有被复制的issue * 修复了应用复制后头像没有被复制的issue
1 parent 40c4e5f commit 5481898

File tree

3 files changed

+38
-14
lines changed

3 files changed

+38
-14
lines changed

frontend/src/components/file-upload/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ const UploadImg = ({ appId = '', icon = '', uploadSuccess }) => {
5858
let res: any = await uploadChatFile(TENANT_ID, appId, formData, headers);
5959
if (res.code === 0) {
6060
const path = `${AIPP_URL}/${TENANT_ID}/file?filePath=${res.data.file_path}&fileName=${res.data.file_name}`;
61-
uploadSuccess(path);
61+
uploadSuccess(res.data.file_path);
6262
getImgPath(path);
6363
}
6464
} catch (err) {

frontend/src/pages/appDev/components/copy-app.tsx

Lines changed: 33 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,16 @@ import { Message } from '@/shared/utils/message';
1313
import { convertImgPath } from '@/common/util';
1414
import { TENANT_ID } from '@/pages/chatPreview/components/send-editor/common/config';
1515
import UploadImg from '@/components/file-upload';
16-
16+
import serviceConfig from "@/shared/http/httpConfig";
17+
import { uploadChatFile } from '@/shared/http/aipp';
1718
/**
1819
* 复制应用
1920
*
2021
* @param copyRef 当前组件的ref.
2122
* @return {JSX.Element}
2223
* @constructor
2324
*/
24-
25+
const { AIPP_URL } = serviceConfig;
2526
const CopyApp = ({ copyRef }) => {
2627
const { t } = useTranslation();
2728
const [form] = Form.useForm();
@@ -30,25 +31,43 @@ const CopyApp = ({ copyRef }) => {
3031
const [loading, setLoading] = useState(false);
3132
const [appInfo, setAppInfo] = useState({});
3233
const navigate = useHistory().push;
34+
const tenantId = TENANT_ID;
3335

3436
useImperativeHandle(copyRef, () => {
3537
return {
3638
openModal: (appInfo) => dataInit(appInfo),
3739
};
3840
});
39-
4041
// 初始化数据
4142
const dataInit = (appInfo) => {
4243
setAppInfo(appInfo);
4344
form.setFieldsValue({
4445
name: appInfo.name,
45-
icon: appInfo.attributes?.icon,
46+
icon: '',
4647
});
47-
if (appInfo.attributes?.icon) {
48-
setFilePath(appInfo.attributes.icon);
48+
49+
if (appInfo.attributes.icon) {
50+
reuploadIcon(appInfo.attributes.icon)
4951
}
5052
setOpen(true);
53+
5154
}
55+
//重新上传图片
56+
const reuploadIcon = async (iconUrl) => {
57+
const res = await fetch(iconUrl);
58+
const blob = await res.blob();
59+
const file = new File([blob], "clone.png", { type: blob.type });
60+
const formData = new FormData();
61+
formData.append("file", file);
62+
let uploadRes = await uploadChatFile(TENANT_ID, appInfo.id, formData, {
63+
'attachment-filename': encodeURI(file.name),
64+
'Content-Type': 'multipart/form-data',
65+
});
66+
if (uploadRes.code === 0) {
67+
const realPath = uploadRes.data.file_path.replace(/^.*[\\/]/, "");
68+
setFilePath(realPath); //存文件名
69+
}
70+
};
5271
// 复制应用
5372
const handleCopyApp = async () => {
5473
try {
@@ -58,7 +77,7 @@ const CopyApp = ({ copyRef }) => {
5877
const copyParam = {
5978
name: formParams.name,
6079
description: attributes.description,
61-
icon: '',
80+
icon: filePath,
6281
app_type: attributes.app_type,
6382
app_built_type: appBuiltType,
6483
type,
@@ -98,10 +117,13 @@ const CopyApp = ({ copyRef }) => {
98117
<Form form={form} layout='vertical' autoComplete='off' className='edit-form-content'>
99118
<Form.Item label={t('icon')} name='icon'>
100119
<div className='avatar'>
101-
<UploadImg
120+
<UploadImg
102121
appId={appInfo.id}
103-
icon={appInfo.attributes?.icon}
104-
uploadSuccess={(path: string) => setFilePath(path)}
122+
icon={`${AIPP_URL}/${tenantId}/file?filePath=/var/share/${filePath}&fileName=${filePath}`}
123+
uploadSuccess={(path: string) =>{
124+
const realPath = path.replace(/^.*[\\/]/, "");
125+
setFilePath(realPath);
126+
}}
105127
/>
106128
</div>
107129
</Form.Item>
@@ -119,7 +141,7 @@ const CopyApp = ({ copyRef }) => {
119141
>
120142
<Input />
121143
</Form.Item>
122-
</Form>
144+
</Form>
123145
</div>
124146
</Modal>
125147
</>

frontend/src/pages/components/edit-modal.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -298,8 +298,10 @@ const EditModal = (props) => {
298298
formData.append('file', file);
299299
let res: any = await uploadChatFile(tenantId, appId, formData, headers);
300300
if (res.code === 0) {
301-
let path = `${AIPP_URL}/${tenantId}/file?filePath=${res.data.file_path}&fileName=${res.data.file_name}`;
302-
setFilePath(path);
301+
const realPath = res.data.file_path.replace(/^.*[\\/]/, "");
302+
setFilePath(realPath);
303+
const realPath2 = `/var/share/${realPath}`;
304+
let path = `${AIPP_URL}/${tenantId}/file?filePath=${realPath2}&fileName=${realPath}`;
303305
convertImgPath(path).then(res => {
304306
setImgPath(res);
305307
});

0 commit comments

Comments
 (0)