Skip to content

Commit c40c0d1

Browse files
committed
Refactor MinIO configuration variables and clean up API plugin handlers for improved readability and consistency
1 parent 4ccbcb7 commit c40c0d1

File tree

8 files changed

+36
-59
lines changed

8 files changed

+36
-59
lines changed

packages/service/common/minio/index.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ import { Client } from 'minio';
33
export * from 'minio';
44
export { Client };
55

6-
export const S3_ENDPOINT = process.env.MINIO_ENDPOINT || 'localhost';
7-
export const S3_PORT = process.env.MINIO_PORT ? parseInt(process.env.MINIO_PORT) : 9000;
8-
export const S3_USE_SSL = process.env.MINIO_USE_SSL === 'true';
9-
export const S3_ACCESS_KEY = process.env.MINIO_ACCESS_KEY || 'minioadmin';
10-
export const S3_SECRET_KEY = process.env.MINIO_SECRET_KEY || 'minioadmin';
6+
export const S3_ENDPOINT = process.env.S3_ENDPOINT || 'localhost';
7+
export const S3_PORT = process.env.S3_PORT ? parseInt(process.env.S3_PORT) : 9000;
8+
export const S3_USE_SSL = process.env.S3_USE_SSL === 'true';
9+
export const S3_ACCESS_KEY = process.env.S3_ACCESS_KEY || 'minioadmin';
10+
export const S3_SECRET_KEY = process.env.S3_SECRET_KEY || 'minioadmin';
1111

1212
export const connectionMinio = (() => {
1313
if (!global.minioClient) {

packages/service/core/app/plugin/controller.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,6 @@ const dbPluginFormat = (item: SystemPluginConfigSchemaType): SystemPluginTemplat
373373
pluginOrder: item.pluginOrder,
374374
associatedPluginId,
375375
userGuide,
376-
toolSource: 'uploaded', // Custom plugins are uploaded
377376
workflow: {
378377
nodes: [],
379378
edges: []

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@
1313
"Only_support_uploading_one_image": "仅支持上传一张图片",
1414
"Please select the image to upload": "请选择要上传的图片",
1515
"Please wait for all files to upload": "请等待所有文件上传完成",
16-
"common.common.upload_system_tools": "上传系统工具",
1716
"bucket_chat": "对话文件",
1817
"bucket_file": "知识库文件",
1918
"click_to_view_raw_source": "点击查看来源",
2019
"common.Some images failed to process": "部分图片处理失败",
2120
"common.dataset_data_input_image_support_format": "支持 .jpg, .jpeg, .png, .gif, .webp 格式",
2221
"common.import_update": "导入/更新",
22+
"common.upload_system_tools": "上传系统工具",
2323
"count.core.dataset.collection.Create Success": "成功导入 {{count}} 张图片",
2424
"delete_image": "删除图片",
2525
"file_name": "文件名",

projects/app/.env.template

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,3 +91,10 @@ CONFIG_JSON_PATH=
9191
# Signoz
9292
SIGNOZ_BASE_URL=
9393
SIGNOZ_SERVICE_NAME=
94+
95+
# MINIO
96+
S3_ENDPOINT=localhost
97+
S3_PORT=9000
98+
S3_USE_SSL=false
99+
S3_ACCESS_KEY=minioadmin
100+
S3_SECRET_KEY=minioadmin

projects/app/src/pages/api/plugin/delete.ts

Lines changed: 8 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,22 @@
11
import type { NextApiRequest, NextApiResponse } from 'next';
2-
import { jsonRes } from '@fastgpt/service/common/response';
32
import { NextAPI } from '@/service/middleware/entry';
43
import { deleteSystemTool } from '@fastgpt/service/core/app/tool/api';
54
import { cleanSystemPluginCache } from '@fastgpt/service/core/app/plugin/controller';
65

7-
type RequestBody = {
8-
toolId: string;
9-
};
10-
116
async function handler(req: NextApiRequest, res: NextApiResponse<any>) {
12-
try {
13-
const { toolId }: RequestBody = req.body;
7+
const toolId = (req.query.toolId as string) || req.body?.toolId;
148

15-
if (!toolId) {
16-
return Promise.reject('ToolId is required');
17-
}
9+
if (!toolId) {
10+
return Promise.reject('ToolId is required');
11+
}
1812

19-
const actualToolId = toolId.includes('-') ? toolId.split('-').slice(1).join('-') : toolId;
13+
const actualToolId = toolId.includes('-') ? toolId.split('-').slice(1).join('-') : toolId;
2014

21-
const result = await deleteSystemTool(actualToolId);
15+
const result = await deleteSystemTool(actualToolId);
2216

23-
try {
24-
await cleanSystemPluginCache();
25-
} catch (error) {
26-
console.error('Clear plugin cache error:', error);
27-
}
17+
cleanSystemPluginCache();
2818

29-
return jsonRes(res, result);
30-
} catch (error) {
31-
return jsonRes(res, {
32-
code: 500,
33-
error: error instanceof Error ? error.message : 'Unknown error'
34-
});
35-
}
19+
return result;
3620
}
3721

3822
export default NextAPI(handler);

projects/app/src/pages/api/plugin/upload.ts

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,20 @@
11
import type { NextApiRequest, NextApiResponse } from 'next';
2-
import { jsonRes } from '@fastgpt/service/common/response';
32
import { NextAPI } from '@/service/middleware/entry';
43
import { uploadSystemTool } from '@fastgpt/service/core/app/tool/api';
54
import { cleanSystemPluginCache } from '@fastgpt/service/core/app/plugin/controller';
65

76
async function handler(req: NextApiRequest, res: NextApiResponse<any>) {
8-
try {
9-
const { url } = req.body;
7+
const { url } = req.body;
108

11-
if (!url) {
12-
return Promise.reject('URL is required');
13-
}
9+
if (!url) {
10+
return Promise.reject('URL is required');
11+
}
1412

15-
const result = await uploadSystemTool(url);
13+
const result = await uploadSystemTool(url);
1614

17-
try {
18-
await cleanSystemPluginCache();
19-
} catch (error) {
20-
console.error('Clear plugin cache error:', error);
21-
}
15+
cleanSystemPluginCache();
2216

23-
return jsonRes(res, result);
24-
} catch (error) {
25-
return jsonRes(res, {
26-
code: 500,
27-
error: error instanceof Error ? error.message : 'Unknown error'
28-
});
29-
}
17+
return result;
3018
}
3119

3220
export default NextAPI(handler);

projects/app/src/pages/dashboard/[pluginGroupId]/index.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ const SystemTools = () => {
5656
data: plugins = [],
5757
loading: isLoading,
5858
runAsync: refreshPlugins
59+
// refreshAsync: refreshPlugins
5960
} = useRequest2(getSystemPlugTemplates, {
6061
manual: false
6162
});
@@ -94,6 +95,7 @@ const SystemTools = () => {
9495
});
9596

9697
await postUploadFileAndUrl(fileUrl);
98+
await refreshPlugins({ parentId: null });
9799
},
98100
{
99101
manual: true,
@@ -106,7 +108,6 @@ const SystemTools = () => {
106108
setSelectFiles([]);
107109
onClose();
108110
// null means all tools
109-
await refreshPlugins({ parentId: null });
110111
},
111112
onError: (error) => {
112113
toast({
@@ -184,7 +185,7 @@ const SystemTools = () => {
184185
<Flex alignItems={'center'} justifyContent={'space-between'}>
185186
{isPc ? (
186187
<Box fontSize={'lg'} color={'myGray.900'} fontWeight={500}>
187-
{t('common:core.module.template.System Tools')}
188+
{t('app:core.module.template.System Tools')}
188189
</Box>
189190
) : (
190191
MenuIcon

projects/app/src/web/common/file/api.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { GET, POST } from '@/web/common/api/request';
1+
import { DELETE, GET, POST } from '@/web/common/api/request';
22
import type { UploadImgProps } from '@fastgpt/global/common/file/api.d';
33
import { type AxiosProgressEvent } from 'axios';
44
import type { PresignedUrlResponse } from '@fastgpt/service/common/file/plugin/config';
@@ -43,14 +43,12 @@ export const postPresignedUrl = (data: {
4343
export const postConfirmUpload = (data: { objectName: string; size: string }) =>
4444
POST<string>('/common/file/plugin/confirmUpload', data);
4545

46-
export const postUploadFileAndUrl = async (url: string) => {
47-
POST('/plugin/upload', {
46+
export const postUploadFileAndUrl = (url: string) =>
47+
POST<void>('/plugin/upload', {
4848
url: url
4949
});
50-
};
5150

52-
export const postDeletePlugin = async (toolId: string) => {
53-
POST('/plugin/delete', {
51+
export const postDeletePlugin = (toolId: string) =>
52+
DELETE<void>('/plugin/delete', {
5453
toolId
5554
});
56-
};

0 commit comments

Comments
 (0)