46 lines
1.2 KiB
TypeScript
46 lines
1.2 KiB
TypeScript
// classes.smartbucket.ts
|
|
|
|
import * as plugins from './plugins.js';
|
|
import { Bucket } from './classes.bucket.js';
|
|
|
|
export class SmartBucket {
|
|
public config: plugins.tsclass.storage.IS3Descriptor;
|
|
|
|
public s3Client: plugins.s3.S3Client;
|
|
|
|
/**
|
|
* the constructor of SmartBucket
|
|
*/
|
|
/**
|
|
* the constructor of SmartBucket
|
|
*/
|
|
constructor(configArg: IS3Descriptor) {
|
|
this.config = configArg;
|
|
|
|
const protocol = configArg.useSsl === false ? 'http' : 'https';
|
|
const endpoint = `${protocol}://${configArg.endpoint}`;
|
|
|
|
this.s3Client = new plugins.s3.S3Client({
|
|
endpoint,
|
|
region: configArg.region || 'us-east-1',
|
|
credentials: {
|
|
accessKeyId: configArg.accessKey,
|
|
secretAccessKey: configArg.accessSecret,
|
|
},
|
|
forcePathStyle: true, // Necessary for S3-compatible storage like MinIO or Wasabi
|
|
});
|
|
}
|
|
|
|
public async createBucket(bucketNameArg: string) {
|
|
const bucket = await Bucket.createBucketByName(this, bucketNameArg);
|
|
return bucket;
|
|
}
|
|
|
|
public async removeBucket(bucketName: string) {
|
|
await Bucket.removeBucketByName(this, bucketName);
|
|
}
|
|
|
|
public async getBucketByName(bucketName: string) {
|
|
return Bucket.getBucketByName(this, bucketName);
|
|
}
|
|
} |