- Removed MinIO client and related imports from various modules. - Introduced S3 client and OSS integration for object storage. - Updated all references to MinIO methods with corresponding S3 methods. - Added new flowme table schema to the database. - Adjusted upload and download routes to utilize S3 for file operations. - Removed obsolete MinIO-related files and routes. - Ensured compatibility with existing application logic while transitioning to S3.
44 lines
1.3 KiB
TypeScript
44 lines
1.3 KiB
TypeScript
import { CreateBucketCommand, HeadObjectCommand, S3Client, } from '@aws-sdk/client-s3';
|
|
import { OssBase } from '@kevisual/oss/s3.ts';
|
|
import { useConfig } from '@kevisual/use-config';
|
|
const config = useConfig();
|
|
|
|
export const bucketName = config.S3_BUCKET_NAME || 'resources';
|
|
|
|
export const s3Client = new S3Client({
|
|
credentials: {
|
|
accessKeyId: config.S3_ACCESS_KEY_ID || '',
|
|
secretAccessKey: config.S3_SECRET_ACCESS_KEY || '',
|
|
},
|
|
region: config.S3_REGION,
|
|
endpoint: config.S3_ENDPOINT,
|
|
// minio配置
|
|
forcePathStyle: true,
|
|
});
|
|
|
|
// 判断 bucketName 是否存在,不存在则创建
|
|
(async () => {
|
|
try {
|
|
await s3Client.send(new HeadObjectCommand({ Bucket: bucketName, Key: '' }));
|
|
console.log(`Bucket ${bucketName} exists.`);
|
|
} catch (error) {
|
|
console.log(`Bucket ${bucketName} does not exist. Creating...`);
|
|
if (config.S3_ENDPOINT?.includes?.('9000')) {
|
|
// 创建 bucket
|
|
await s3Client.send(new CreateBucketCommand({ Bucket: bucketName }));
|
|
console.log(`Bucket ${bucketName} created.`);
|
|
}
|
|
}
|
|
})();
|
|
|
|
if (!s3Client) {
|
|
throw new Error('S3 client not initialized');
|
|
}
|
|
|
|
export const oss = new OssBase({
|
|
client: s3Client,
|
|
bucketName: bucketName,
|
|
prefix: '',
|
|
})
|
|
|
|
export const minioResources = `${config.S3_ENDPOINT}/${bucketName}`; |