Skip to content

Commit c36570c

Browse files
authored
[frontend] bugfix: fix guest mode get file icon failed bug (#455)
1 parent addefcf commit c36570c

File tree

5 files changed

+40
-10
lines changed

5 files changed

+40
-10
lines changed

app-builder/plugins/aipp-plugin/src/main/java/modelengine/fit/jober/aipp/controller/AppBuilderGuestController.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,10 @@
1717
import modelengine.fit.http.annotation.RequestBody;
1818
import modelengine.fit.http.annotation.RequestMapping;
1919
import modelengine.fit.http.annotation.RequestParam;
20+
import modelengine.fit.http.entity.FileEntity;
2021
import modelengine.fit.http.entity.PartitionedEntity;
2122
import modelengine.fit.http.server.HttpClassicServerRequest;
23+
import modelengine.fit.http.server.HttpClassicServerResponse;
2224
import modelengine.fit.jane.common.controller.AbstractController;
2325
import modelengine.fit.jane.common.entity.OperationContext;
2426
import modelengine.fit.jane.common.response.Rsp;
@@ -483,6 +485,26 @@ public Rsp<List<FileRspDto>> batchUploadFile(HttpClassicServerRequest httpReques
483485
return Rsp.ok(fileRspDtos);
484486
}
485487

488+
/**
489+
* 从远端下载文件或者从 nas 下载文件。
490+
*
491+
* @param httpRequest 表示 Http 请求体的 {@link HttpClassicServerRequest}。
492+
* @param tenantId 表示租户唯一标识的 {@link String}。
493+
* @param fileCanonicalPath 表示文件的规范路径的 {@link String}。
494+
* @param fileName 表示文件名的 {@link String}。
495+
* @param httpClassicServerResponse 表示 Http 响应的 {@link HttpClassicServerResponse}。
496+
* @return 表示文件实体的 {@link FileEntity}。
497+
* @throws IOException 表示文件读写异常的 {@link IOException}。
498+
*/
499+
@GetMapping(path = "/{tenant_id}/file", description = "下载文件")
500+
public FileEntity getFile(HttpClassicServerRequest httpRequest, @PathVariable("tenant_id") String tenantId,
501+
@RequestParam(value = "filePath", required = false) String fileCanonicalPath,
502+
@RequestParam(value = "fileName") String fileName, HttpClassicServerResponse httpClassicServerResponse)
503+
throws IOException {
504+
OperationContext context = new OperationContext();
505+
return this.fileService.getFile(context, fileCanonicalPath, fileName, httpClassicServerResponse);
506+
}
507+
486508
/**
487509
* 清空应用的历史对话。
488510
*

frontend/src/common/util.ts

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,19 @@ export function bytesToSize(bytes) {
99
return (bytes / Math.pow(k, i)).toFixed(2) + ' ' + sizes[i];
1010
}
1111

12-
export function convertImgPath(path: string) {
12+
export function convertImgPath(path: string, isGuest = false) {
1313
return new Promise((resolve, reject) => {
14-
fetch(path, {
15-
headers: {
16-
'X-Auth-Token': getCookie('__Host-X-Auth-Token'),
17-
'X-Csrf-Token': getCookie('__Host-X-Csrf-Token')
18-
},
14+
const headers: HeadersInit = {};
15+
let requestPath = path;
16+
if (isGuest) {
17+
requestPath = path.replace('/appbuilder/v1/api/', '/appbuilder/v1/api/guest/');
18+
} else {
19+
headers['X-Auth-Token'] = getCookie('__Host-X-Auth-Token');
20+
headers['X-Csrf-Token'] = getCookie('__Host-X-Csrf-Token');
21+
}
22+
23+
fetch(requestPath, {
24+
headers,
1925
})
2026
.then(response => response.blob())
2127
.then(blob => {
@@ -57,4 +63,4 @@ export const listFormate = (arr) => {
5763
});
5864
});
5965
return res;
60-
}
66+
}

frontend/src/pages/chatPreview/components/chat-details.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,9 +129,10 @@ const NormalAppInfo = (props) => {
129129
const Img = (props) => {
130130
const { icon } = props;
131131
const [imgPath, setImgPath] = useState('');
132+
const isGuest = useAppSelector((state) => state.appStore.isGuest);
132133
useEffect(() => {
133134
if (icon) {
134-
convertImgPath(icon).then(res => {
135+
convertImgPath(icon, isGuest).then(res => {
135136
setImgPath(res);
136137
});
137138
}

frontend/src/pages/chatPreview/components/receive-box/receive-box.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,9 +124,10 @@ const Loading = () => {
124124
const Img = (props) => {
125125
const { iconPath } = props;
126126
const [imgPath, setImgPath] = useState('');
127+
const isGuest = useAppSelector((state) => state.appStore.isGuest);
127128
useEffect(() => {
128129
if (iconPath) {
129-
convertImgPath(iconPath).then(res => {
130+
convertImgPath(iconPath, isGuest).then(res => {
130131
setImgPath(res);
131132
});
132133
}

frontend/src/pages/chatPreview/components/send-editor/components/editor-btn-home.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ const EditorBtnHome = (props) => {
100100
// 获取图片
101101
const getImgPath = async (cardInfo) => {
102102
if (cardInfo && cardInfo.icon) {
103-
const res: any = await convertImgPath(cardInfo.icon);
103+
const res: any = await convertImgPath(cardInfo.icon, isGuest);
104104
setAppIcon(res);
105105
}
106106
};

0 commit comments

Comments
 (0)