mirror of
https://github.com/labring/FastGPT.git
synced 2025-10-17 00:14:51 +00:00

* 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
40 lines
1.1 KiB
TypeScript
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);
|
|
};
|