Skip to content

Commit 87d0338

Browse files
committed
Refactor image dataset handling by improving internationalization strings, enhancing error messages, and streamlining the preview URL generation process.
1 parent d751de7 commit 87d0338

File tree

13 files changed

+92
-202
lines changed

13 files changed

+92
-202
lines changed

.gitignore

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,4 @@ files/helm/fastgpt/fastgpt-0.1.0.tgz
4444
files/helm/fastgpt/charts/*.tgz
4545

4646
tmp/
47-
coverage
48-
deploy/docker/aiproxy_pg
49-
deploy/docker/mongo
50-
deploy/docker/pg
51-
deploy
47+
coverage
-11.2 MB
Binary file not shown.

packages/web/i18n/en/common.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,7 @@
185185
"comfirn_create": "Confirm Creation",
186186
"commercial_function_tip": "Please Upgrade to the Commercial Version to Use This Feature: https://doc.fastgpt.cn/docs/commercial/intro/",
187187
"common.Confirm Update": "Confirm update",
188+
"common.Create Failed": "Failed to create a collection",
188189
"comon.Continue_Adding": "Continue Adding",
189190
"compliance.chat": "The content is generated by third-party AI and cannot be guaranteed to be true and accurate. It is for reference only.",
190191
"compliance.dataset": "Please ensure that your content strictly complies with relevant laws and regulations and avoid containing any illegal or infringing content. \nPlease be careful when uploading materials that may contain sensitive information.",

packages/web/i18n/en/dataset.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{
2+
" error?.message || t('core.dataset.collection.Create Failed'),\n status.core.dataset.collection.Create Failed": "",
23
"Enable": "Enable",
34
"add_file": "Import",
45
"api_file": "API Dataset",

packages/web/i18n/en/file.json

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,18 @@
11
{
2+
" t('core.dataset.collection.Create Success', { count.core.dataset.collection.Create Success": "",
3+
" t('file.Please select the image to upload select the image to upload'),\n status.file.Please select the image to upload select the image to upload": "Please select the image to upload select the image to upload",
4+
"Action": "Please select the image to upload",
5+
"All images import failed": "All pictures failed to import",
6+
"Please select the image to upload": "Please select the image to upload",
7+
"Please select the image to upload select the image to upload": "",
8+
"Please wait for all files to upload": "Please wait for all files to be uploaded to complete",
29
"bucket_chat": "Conversation Files",
310
"bucket_file": "Dataset Documents",
411
"click_to_view_raw_source": "Click to View Original Source",
12+
"delete_image": "Delete pictures",
513
"file_name": "Filename",
614
"file_size": "Filesize",
15+
"reached_max_file_count": "Maximum file count reached",
716
"release_the_mouse_to_upload_the_file": "Release Mouse to Upload File",
817
"select_and_drag_file_tip": "Click or Drag Files Here to Upload",
918
"select_file_amount_limit": "You can select up to {{max}} files",
@@ -12,7 +21,7 @@
1221
"support_file_type": "Supports {{fileType}} file types",
1322
"support_max_count": "Supports up to {{maxCount}} files",
1423
"support_max_size": "Maximum file size is {{maxSize}}",
24+
"upload_error_description": "Only multiple files or a single folder can be uploaded at a time",
1525
"upload_failed": "Upload Failed",
16-
"reached_max_file_count": "Maximum file count reached",
17-
"upload_error_description": "Only multiple files or a single folder can be uploaded at a time"
18-
}
26+
"uploading": "Uploading..."
27+
}

packages/web/i18n/zh-CN/common.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@
185185
"comfirn_create": "确认创建",
186186
"commercial_function_tip": "请升级商业版后使用该功能:https://doc.fastgpt.cn/docs/commercial/intro/",
187187
"common.Confirm Update": "确认更新",
188-
"common.Create Failed": "创建失败",
188+
"common.Create Failed": "创建集合失败",
189189
"common.error.unKnow": "未知问题",
190190
"comon.Continue_Adding": "继续添加",
191191
"compliance.chat": "内容由第三方 AI 生成,无法确保真实准确,仅供参考",

packages/web/i18n/zh-CN/file.json

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,16 @@
11
{
2+
"Action": "请选择要上传的图片",
3+
"All images import failed": "所有图片导入失败",
4+
"Please select the image to upload": "请选择要上传的图片",
5+
"Please wait for all files to upload": "请等待所有文件上传完成",
26
"bucket_chat": "对话文件",
37
"bucket_file": "知识库文件",
48
"click_to_view_raw_source": "点击查看来源",
9+
"count.core.dataset.collection.Create Success": "成功导入 {{count}} 张图片",
10+
"delete_image": "删除图片",
511
"file_name": "文件名",
612
"file_size": "文件大小",
13+
"reached_max_file_count": "已达到最大文件数量",
714
"release_the_mouse_to_upload_the_file": "松开鼠标上传文件",
815
"select_and_drag_file_tip": "点击或拖动文件到此处上传",
916
"select_file_amount_limit": "最多选择 {{max}} 个文件",
@@ -12,7 +19,7 @@
1219
"support_file_type": "支持 {{fileType}} 类型文件",
1320
"support_max_count": "最多支持 {{maxCount}} 个文件",
1421
"support_max_size": "单个文件最大 {{maxSize}}",
22+
"upload_error_description": "单次只支持上传多个文件或者一个文件夹",
1523
"upload_failed": "上传异常",
16-
"reached_max_file_count": "已达到最大文件数量",
17-
"upload_error_description": "单次只支持上传多个文件或者一个文件夹"
18-
}
24+
"uploading": "正在上传..."
25+
}

packages/web/i18n/zh-Hant/common.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,7 @@
185185
"comfirn_create": "確認建立",
186186
"commercial_function_tip": "請升級為商業版後使用此功能:https://doc.fastgpt.cn/docs/commercial/intro/",
187187
"common.Confirm Update": "確認更新",
188+
"common.Create Failed": "創建集合失敗",
188189
"comon.Continue_Adding": "繼續新增",
189190
"compliance.chat": "內容由第三方 AI 產生,無法保證其真實性與準確性,僅供參考。",
190191
"compliance.dataset": "請確保您的內容嚴格遵守相關法律法規,避免包含任何違法或侵權的內容。\n在上傳可能涉及敏感資訊的資料時請務必謹慎。",

packages/web/i18n/zh-Hant/dataset.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{
2+
" error?.message || t('core.dataset.collection.Create Failed'),\n status.core.dataset.collection.Create Failed": "",
23
"Enable": "啟用",
34
"add_file": "新增文件",
45
"api_file": "API 檔案庫",

packages/web/i18n/zh-Hant/file.json

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,18 @@
11
{
2+
" t('core.dataset.collection.Create Success', { count.core.dataset.collection.Create Success": "",
3+
" t('file.Please select the image to upload select the image to upload'),\n status.file.Please select the image to upload select the image to upload": "",
4+
"Action": "請選擇要上傳的圖片",
5+
"All images import failed": "所有圖片導入失敗",
6+
"Please select the image to upload": "請選擇要上傳的圖片",
7+
"Please select the image to upload select the image to upload": "",
8+
"Please wait for all files to upload": "請等待所有文件上傳完成",
29
"bucket_chat": "對話檔案",
310
"bucket_file": "知識庫檔案",
411
"click_to_view_raw_source": "點選檢視原始來源",
12+
"delete_image": "刪除圖片",
513
"file_name": "檔案名稱",
614
"file_size": "檔案大小",
15+
"reached_max_file_count": "已達檔案數量上限",
716
"release_the_mouse_to_upload_the_file": "放開滑鼠以上傳檔案",
817
"select_and_drag_file_tip": "點選或拖曳檔案至此處上傳",
918
"select_file_amount_limit": "最多可選擇 {{max}} 個檔案",
@@ -12,7 +21,7 @@
1221
"support_file_type": "支援 {{fileType}} 格式的檔案",
1322
"support_max_count": "最多可支援 {{maxCount}} 個檔案",
1423
"support_max_size": "單一檔案大小上限為 {{maxSize}}",
24+
"upload_error_description": "單次僅支援上傳多個檔案或一個資料夾",
1525
"upload_failed": "上傳失敗",
16-
"reached_max_file_count": "已達檔案數量上限",
17-
"upload_error_description": "單次僅支援上傳多個檔案或一個資料夾"
18-
}
26+
"uploading": "正在上傳..."
27+
}

projects/app/src/pageComponents/dataset/detail/DataCard.tsx

Lines changed: 3 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -55,31 +55,19 @@ const getImagePreviewUrl = async (
5555
datasetId: string
5656
) => {
5757
try {
58-
console.log('开始为图片生成预览URL:', { fileId, fileName, teamId });
59-
6058
if (!fileId) {
61-
console.error('fileId为空,无法生成预览URL');
6259
return '';
6360
}
64-
65-
// 通过API获取token,传递必要参数
6661
const token = await postGetFileToken({
6762
bucketName: 'dataset',
6863
fileId,
6964
teamId,
7065
datasetId
7166
});
72-
73-
// 添加域名前缀
74-
const origin = window.location.origin; // 获取当前域名
75-
76-
// 使用与upload.ts相同的URL格式
67+
const origin = window.location.origin;
7768
const previewUrl = `${origin}${ReadFileBaseUrl}/${encodeURIComponent(fileName)}?token=${token}`;
78-
console.log('成功生成预览URL:', previewUrl);
79-
8069
return previewUrl;
8170
} catch (error) {
82-
console.error('创建图片预览URL失败:', error);
8371
return '';
8472
}
8573
};
@@ -268,85 +256,48 @@ const DataCard = () => {
268256
fetchDetailsAndCreateUrls();
269257
}, [datasetDataList, isImageCollection]);
270258

271-
// 判断是否为图片集合的函数
272259
const isImageCollection = useMemo(() => {
273260
if (!collection) return false;
274-
// 检查metadata中是否有标记
275261
if (
276262
collection.metadata &&
277263
typeof collection.metadata === 'object' &&
278264
'isImageCollection' in collection.metadata
279265
) {
280266
return collection.metadata.isImageCollection === true;
281267
}
282-
// 集合名称判断(备选方案)
268+
// Fallback: check collection name
283269
return collection.name?.includes('图片集合') || false;
284270
}, [collection]);
285271

286-
// 添加状态存储预览URLs
287272
const [imagePreviewUrls, setImagePreviewUrls] = useState<Record<string, string>>({});
288273

289-
// 在数据加载成功后生成预览URLs
290274
useEffect(() => {
291275
if (!datasetDataList.length) {
292-
console.log('数据列表为空,不生成预览URL');
293276
return;
294277
}
295-
296278
if (!isImageCollection) {
297-
console.log('非图片集合,不生成预览URL');
298279
return;
299280
}
300-
301-
console.log('数据列表长度:', datasetDataList.length);
302-
console.log(
303-
'列表数据:',
304-
datasetDataList.map((item) => ({
305-
id: item._id,
306-
q: item.q,
307-
a: item.a,
308-
imageFileId: item.imageFileId
309-
}))
310-
);
311-
312-
// 直接使用列表数据生成预览URL
313281
const fetchDetailsAndCreateUrls = async () => {
314282
const urlMap: Record<string, string> = {};
315-
316-
// 并行处理所有项目
317283
const previewPromises = datasetDataList.map(async (item) => {
318284
try {
319-
// 直接检查列表数据中是否包含imageFileId
320285
if (item.imageFileId) {
321-
console.log(`项目 ${item._id} 包含图片ID:`, {
322-
imageFileId: item.imageFileId,
323-
fileName: item.a || 'image.jpg'
324-
});
325-
326286
const previewUrl = await getImagePreviewUrl(
327287
item.imageFileId,
328288
item.a ?? 'image.jpg',
329289
item.teamId ?? '',
330290
item.datasetId
331291
);
332-
333292
if (previewUrl) {
334293
urlMap[item._id] = previewUrl;
335-
console.log(`生成项目 ${item._id} 的预览URL成功`);
336294
}
337295
}
338-
} catch (error) {
339-
console.error(`生成项目 ${item._id} 预览URL失败:`, error);
340-
}
296+
} catch (error) {}
341297
});
342-
343-
// 等待所有预览URL生成完成
344298
await Promise.all(previewPromises);
345-
346-
console.log(`成功生成 ${Object.keys(urlMap).length} 个预览URL`);
347299
setImagePreviewUrls(urlMap);
348300
};
349-
350301
fetchDetailsAndCreateUrls();
351302
}, [datasetDataList, isImageCollection]);
352303

@@ -520,7 +471,6 @@ const DataCard = () => {
520471

521472
{/* Data content */}
522473
<Box wordBreak={'break-all'} fontSize={'sm'}>
523-
{/* 如果是图片数据且在图片集合中 */}
524474
{isImageCollection ? (
525475
<Box
526476
display="flex"
@@ -533,7 +483,6 @@ const DataCard = () => {
533483
bg="var(--Gray-Modern-100, #F4F4F7)"
534484
gap="24px"
535485
>
536-
{/* 图片区域 - 左侧 */}
537486
<Box
538487
width="420px"
539488
flexShrink={0}
@@ -556,7 +505,6 @@ const DataCard = () => {
556505
cursor="pointer"
557506
_hover={{ transform: 'scale(1.02)' }}
558507
onError={(e) => {
559-
console.error('图片加载失败:', imagePreviewUrls[item._id]);
560508
e.currentTarget.style.display = 'none';
561509
}}
562510
/>
@@ -572,8 +520,6 @@ const DataCard = () => {
572520
</Box>
573521
)}
574522
</Box>
575-
576-
{/* 描述文本 - 右侧 */}
577523
<Box
578524
flex="1 0 0"
579525
color="var(--Gray-Modern-800, #1D2532)"
@@ -591,7 +537,6 @@ const DataCard = () => {
591537
</Box>
592538
) : (
593539
<>
594-
{/* 非图片集合的展示保持不变 */}
595540
<Markdown source={item.q} isDisabled />
596541
{!!item.a && (
597542
<>
@@ -668,7 +613,6 @@ const DataCard = () => {
668613
</ScrollData>
669614
</Flex>
670615

671-
{/* 图片数据集的插入的输入模态框 */}
672616
{editDataId !== undefined &&
673617
collection &&
674618
(isImageCollection ? (

0 commit comments

Comments
 (0)