Skip to content

Commit de2acbf

Browse files
committed
Refactor file plugin types and update upload configurations
1 parent 3012d72 commit de2acbf

File tree

22 files changed

+101
-198
lines changed

22 files changed

+101
-198
lines changed

packages/service/common/file/plugin/config.ts

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,29 @@
11
import { mimeTypes } from './utils';
22

3-
// 插件类型枚举
4-
export enum PluginTypeEnum {
3+
export enum FilePluginTypeEnum {
54
tool = 'tool'
65
}
76

8-
// 插件路径枚举
97
export enum PluginPathEnum {
108
tools = 'plugin/tools'
119
}
1210

13-
// 插件类型到路径的映射
14-
export const PLUGIN_TYPE_TO_PATH_MAP: Record<PluginTypeEnum, PluginPathEnum> = {
15-
[PluginTypeEnum.tool]: PluginPathEnum.tools
11+
export const PLUGIN_TYPE_TO_PATH_MAP: Record<FilePluginTypeEnum, PluginPathEnum> = {
12+
[FilePluginTypeEnum.tool]: PluginPathEnum.tools
1613
};
1714

1815
export type UploadFileConfig = {
19-
maxFileSize: number; // 文件大小限制(字节)
20-
allowedExtensions?: string[]; // 允许的文件扩展名
21-
bucket: string; // 存储桶名称
16+
maxFileSize: number;
17+
allowedExtensions?: string[];
18+
bucket: string;
2219
};
2320

24-
// 默认配置
2521
export const defaultUploadConfig: UploadFileConfig = {
2622
maxFileSize: process.env.UPLOAD_MAX_FILE_SIZE
2723
? parseInt(process.env.UPLOAD_MAX_FILE_SIZE)
28-
: 100 * 1024 * 1024, // 默认 100MB
24+
: 10 * 1024 * 1024,
2925
bucket: process.env.MINIO_UPLOAD_BUCKET || 'fastgpt-uploads',
30-
allowedExtensions: Object.keys(mimeTypes) // 从 mimeTypes 映射表中获取支持的扩展名
26+
allowedExtensions: Object.keys(mimeTypes)
3127
};
3228

3329
export type FileMetadata = {
@@ -39,24 +35,21 @@ export type FileMetadata = {
3935
accessUrl: string;
4036
};
4137

42-
// 预签名URL请求输入类型
4338
export type PresignedUrlInput = {
4439
filename: string;
45-
pluginType?: PluginTypeEnum; // 插件类型,默认为 tool
40+
pluginType?: FilePluginTypeEnum;
4641
contentType?: string;
4742
metadata?: Record<string, string>;
4843
maxSize?: number;
4944
};
5045

51-
// 预签名URL响应类型
5246
export type PresignedUrlResponse = {
5347
fileId: string;
5448
objectName: string;
5549
uploadUrl: string;
5650
formData: Record<string, string>;
5751
};
5852

59-
// 保留原有类型以兼容现有代码
6053
export type FileUploadInput = {
6154
buffer: Buffer;
6255
filename: string;

packages/service/common/file/plugin/controller.ts

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,12 @@ import {
44
type UploadFileConfig,
55
type PresignedUrlInput,
66
type PresignedUrlResponse,
7-
PluginTypeEnum,
7+
FilePluginTypeEnum,
88
PLUGIN_TYPE_TO_PATH_MAP
99
} from './config';
1010
import { addLog } from '../../system/log';
1111
import { ensureBucket } from '../../minio/init';
12-
import * as path from 'path';
1312
import { connectionMinio } from '../../minio/index';
14-
import { MongoFastGPTPlugin } from './schema';
1513
import { inferContentType } from './utils';
1614

1715
let globalConfig: UploadFileConfig = defaultUploadConfig;
@@ -48,7 +46,7 @@ export const generatePresignedUrl = async (
4846
const currentConfig = { ...globalConfig };
4947

5048
const fileId = generateFileId();
51-
const pluginType = input.pluginType || PluginTypeEnum.tool;
49+
const pluginType = input.pluginType || FilePluginTypeEnum.tool;
5250
const pluginPath = PLUGIN_TYPE_TO_PATH_MAP[pluginType];
5351
const objectName = `${pluginPath}/${fileId}/${input.filename}`;
5452
const contentType = input.contentType || inferContentType(input.filename);
@@ -101,14 +99,7 @@ export const confirmPresignedUpload = async (objectName: string, size: string):
10199

102100
const accessUrl = generateDownloadUrl(objectName, currentConfig);
103101

104-
const pluginData = {
105-
url: accessUrl,
106-
type: 'tool' as const
107-
};
108-
109-
const result = await MongoFastGPTPlugin.create(pluginData);
110-
111-
return result.url;
102+
return accessUrl;
112103
} catch (error) {
113104
addLog.error('Failed to confirm presigned upload', error);
114105
return Promise.reject(`Failed to confirm presigned upload: ${error}`);

packages/service/common/file/plugin/schema.ts

Lines changed: 0 additions & 31 deletions
This file was deleted.

packages/service/common/minio/index.ts

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

6-
export const MINIO_ENDPOINT = process.env.MINIO_ENDPOINT || 'localhost';
7-
export const MINIO_PORT = process.env.MINIO_PORT ? parseInt(process.env.MINIO_PORT) : 9000;
8-
export const MINIO_USE_SSL = process.env.MINIO_USE_SSL === 'true';
9-
export const MINIO_ACCESS_KEY = process.env.MINIO_ACCESS_KEY || 'minioadmin';
10-
export const MINIO_SECRET_KEY = process.env.MINIO_SECRET_KEY || 'minioadmin';
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';
1111

1212
export const connectionMinio = (() => {
1313
if (!global.minioClient) {
1414
global.minioClient = new Client({
15-
endPoint: MINIO_ENDPOINT,
16-
port: MINIO_PORT,
17-
useSSL: MINIO_USE_SSL,
18-
accessKey: MINIO_ACCESS_KEY,
19-
secretKey: MINIO_SECRET_KEY
15+
endPoint: S3_ENDPOINT,
16+
port: S3_PORT,
17+
useSSL: S3_USE_SSL,
18+
accessKey: S3_ACCESS_KEY,
19+
secretKey: S3_SECRET_KEY
2020
});
2121
}
2222
return global.minioClient;

packages/service/common/minio/init.ts

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,6 @@ import { connectionMinio } from './index';
22
import { addLog } from '../system/log';
33
import { retryFn } from '@fastgpt/global/common/system/utils';
44

5-
export const initMinio = async () => {
6-
try {
7-
addLog.info('Connecting to MinIO...');
8-
9-
addLog.info('MinIO connected successfully');
10-
return true;
11-
} catch (error) {
12-
addLog.error('Failed to connect to MinIO:', error);
13-
return false;
14-
}
15-
};
16-
175
export const ensureBucket = async (bucketName: string, isPublic: boolean = false) => {
186
return retryFn(async () => {
197
try {

packages/service/core/app/tool/api.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,26 @@ export async function getSystemToolList() {
2929
return Promise.reject(res.body);
3030
}
3131

32+
export async function deleteSystemTool(toolId: string) {
33+
const res = await client.tool.delete({ body: { toolId } });
34+
35+
if (res.status === 200) {
36+
return res.body;
37+
}
38+
39+
return Promise.reject(res.body);
40+
}
41+
42+
export async function uploadSystemTool(url: string) {
43+
const res = await client.tool.upload({ body: { url } });
44+
45+
if (res.status === 200) {
46+
return res.body;
47+
}
48+
49+
return Promise.reject(res.body);
50+
}
51+
3252
const runToolInstance = new RunToolWithStream({
3353
baseUrl: BASE_URL,
3454
token: TOKEN

packages/web/core/workflow/constants.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ export const workflowNodeTemplateList: {
8686
export const defaultGroup: PluginGroupSchemaType = {
8787
groupId: 'systemPlugin',
8888
groupAvatar: 'core/app/type/pluginLight',
89-
groupName: i18nT('common:core.module.template.System Plugin'),
89+
groupName: i18nT('common:core.module.template.System Tools'),
9090
groupOrder: 0,
9191
groupTypes: systemPluginTemplateList
9292
};

packages/web/i18n/en/app.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
"confirm_delete_folder_tip": "Confirm to delete this folder? All apps and corresponding conversation records under it will be deleted. Please confirm!",
4444
"copy_one_app": "Create Duplicate",
4545
"core.app.QG.Switch": "Enable guess what you want to ask",
46+
"core.module.template.System Tools": "System Tools",
4647
"core.dataset.import.Custom prompt": "Custom Prompt",
4748
"create_by_curl": "By CURL",
4849
"create_by_template": "By template",

packages/web/i18n/en/common.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -659,7 +659,6 @@
659659
"core.module.template.AI support tool tip": "Models that support function calls can better use tool calls.",
660660
"core.module.template.Basic Node": "Basic",
661661
"core.module.template.Query extension": "Question Optimization",
662-
"core.module.template.System Plugin": "System Tools",
663662
"core.module.template.System input module": "System Input",
664663
"core.module.template.Team app": "Team",
665664
"core.module.template.UnKnow Module": "Unknown Module",

packages/web/i18n/en/file.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"Only_support_uploading_one_image": "Only support uploading one image",
1414
"Please select the image to upload": "Please select the image to upload",
1515
"Please wait for all files to upload": "Please wait for all files to be uploaded to complete",
16-
"Upload_system_tools": "Upload system tools",
16+
"common.upload_system_tools": "Upload system tools",
1717
"bucket_chat": "Conversation Files",
1818
"bucket_file": "Dataset Documents",
1919
"click_to_view_raw_source": "Click to View Original Source",

0 commit comments

Comments
 (0)