smartbucket/ts/classes.smartbucket.ts

48 lines
1.3 KiB
TypeScript
Raw Permalink Normal View History

2024-06-17 14:01:35 +00:00
// classes.smartbucket.ts
2024-05-20 23:22:21 +00:00
import * as plugins from './plugins.js';
import { Bucket } from './classes.bucket.js';
2018-09-14 16:07:20 +00:00
export class SmartBucket {
2024-02-10 03:36:34 +00:00
public config: plugins.tsclass.storage.IS3Descriptor;
2019-10-14 18:55:07 +00:00
2024-06-17 14:01:35 +00:00
public s3Client: plugins.s3.S3Client;
2019-10-14 21:53:41 +00:00
2024-06-17 14:01:35 +00:00
/**
* the constructor of SmartBucket
*/
2018-09-14 16:07:20 +00:00
/**
* the constructor of SmartBucket
*/
2024-06-17 18:00:57 +00:00
constructor(configArg: plugins.tsclass.storage.IS3Descriptor) {
2018-09-14 16:07:20 +00:00
this.config = configArg;
2024-06-17 17:57:56 +00:00
const protocol = configArg.useSsl === false ? 'http' : 'https';
2024-06-17 18:00:57 +00:00
const port = configArg.port ? `:${configArg.port}` : '';
const endpoint = `${protocol}://${configArg.endpoint}${port}`;
2024-06-17 14:01:35 +00:00
this.s3Client = new plugins.s3.S3Client({
endpoint,
2024-06-17 17:57:56 +00:00
region: configArg.region || 'us-east-1',
2024-06-17 14:01:35 +00:00
credentials: {
2024-06-17 17:57:56 +00:00
accessKeyId: configArg.accessKey,
secretAccessKey: configArg.accessSecret,
2024-06-17 14:01:35 +00:00
},
forcePathStyle: true, // Necessary for S3-compatible storage like MinIO or Wasabi
2019-10-15 12:16:28 +00:00
});
2018-09-14 16:07:20 +00:00
}
2019-10-15 17:23:06 +00:00
public async createBucket(bucketNameArg: string) {
const bucket = await Bucket.createBucketByName(this, bucketNameArg);
return bucket;
2019-10-15 12:16:28 +00:00
}
public async removeBucket(bucketName: string) {
2019-10-15 17:23:06 +00:00
await Bucket.removeBucketByName(this, bucketName);
2019-10-15 12:16:28 +00:00
}
2019-10-14 21:53:41 +00:00
2019-10-15 17:23:06 +00:00
public async getBucketByName(bucketName: string) {
return Bucket.getBucketByName(this, bucketName);
2019-10-14 21:53:41 +00:00
}
2024-06-17 18:00:57 +00:00
}