Files
FastGPT/packages/service/common/minio/init.ts
Ctrlz 31c12fdeb9 Enhance file upload functionality and system tool integration (#5257)
* Enhance file upload functionality and system tool integration

* Add supplementary documents and optimize the upload interface

* Refactor file plugin types and update upload configurations

* Refactor MinIO configuration variables and clean up API plugin handlers for improved readability and consistency

* File name change

* Refactor SystemTools component layout

* fix i18n

* fix

* fix

* fix
2025-07-31 11:46:10 +08:00

40 lines
1.1 KiB
TypeScript

import { connectionMinio } from './index';
import { addLog } from '../system/log';
import { retryFn } from '@fastgpt/global/common/system/utils';
export const ensureBucket = async (bucketName: string, isPublic: boolean = false) => {
return retryFn(async () => {
try {
const bucketExists = await connectionMinio.bucketExists(bucketName);
if (!bucketExists) {
addLog.info(`Creating bucket: ${bucketName}`);
await connectionMinio.makeBucket(bucketName);
}
if (isPublic) {
// Set public read policy
const policy = {
Version: '2012-10-17',
Statement: [
{
Effect: 'Allow',
Principal: '*',
Action: ['s3:GetObject'],
Resource: [`arn:aws:s3:::${bucketName}/*`]
}
]
};
await connectionMinio.setBucketPolicy(bucketName, JSON.stringify(policy));
addLog.info(`Set public read policy for bucket: ${bucketName}`);
}
return true;
} catch (error) {
addLog.error(`Failed to ensure bucket ${bucketName}:`, error);
throw error;
}
}, 3);
};