Initial commit: CMS completo com gerenciamento de leads e personalização de tema
This commit is contained in:
37
frontend/src/lib/minio.ts
Normal file
37
frontend/src/lib/minio.ts
Normal file
@@ -0,0 +1,37 @@
|
||||
import * as Minio from 'minio';
|
||||
|
||||
export const minioClient = new Minio.Client({
|
||||
endPoint: process.env.MINIO_ENDPOINT || 'localhost',
|
||||
port: parseInt(process.env.MINIO_PORT || '9000'),
|
||||
useSSL: process.env.MINIO_USE_SSL === 'true',
|
||||
accessKey: process.env.MINIO_ACCESS_KEY || 'admin',
|
||||
secretKey: process.env.MINIO_SECRET_KEY || 'adminpassword',
|
||||
});
|
||||
|
||||
export const bucketName = process.env.MINIO_BUCKET_NAME || 'occto-images';
|
||||
|
||||
// Ensure bucket exists
|
||||
export async function ensureBucketExists() {
|
||||
try {
|
||||
const exists = await minioClient.bucketExists(bucketName);
|
||||
if (!exists) {
|
||||
await minioClient.makeBucket(bucketName, 'us-east-1');
|
||||
// Set policy to public read
|
||||
const policy = {
|
||||
Version: '2012-10-17',
|
||||
Statement: [
|
||||
{
|
||||
Effect: 'Allow',
|
||||
Principal: { AWS: ['*'] },
|
||||
Action: ['s3:GetObject'],
|
||||
Resource: [`arn:aws:s3:::${bucketName}/*`],
|
||||
},
|
||||
],
|
||||
};
|
||||
await minioClient.setBucketPolicy(bucketName, JSON.stringify(policy));
|
||||
console.log(`Bucket ${bucketName} created and policy set to public read.`);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error ensuring bucket exists:', error);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user