smartbucket/ts/smartbucket.classes.smartbucket.ts

41 lines
1.0 KiB
TypeScript
Raw Permalink Normal View History

2018-09-14 16:07:20 +00:00
import * as plugins from './smartbucket.plugins';
2019-10-15 12:16:28 +00:00
import { Bucket } from './smartbucket.classes.bucket';
2018-09-14 16:07:20 +00:00
export interface ISmartBucketConfig {
2019-10-15 12:16:28 +00:00
endpoint: string;
accessKey: string;
accessSecret: string;
2019-07-07 08:48:24 +00:00
}
2018-09-14 16:07:20 +00:00
export class SmartBucket {
2019-10-14 18:55:07 +00:00
public config: ISmartBucketConfig;
2019-10-15 12:16:28 +00:00
public minioClient: plugins.minio.Client;
2019-10-14 21:53:41 +00:00
2018-09-14 16:07:20 +00:00
/**
* the constructor of SmartBucket
*/
constructor(configArg: ISmartBucketConfig) {
this.config = configArg;
2019-10-15 12:16:28 +00:00
this.minioClient = new plugins.minio.Client({
endPoint: this.config.endpoint,
port: 443,
useSSL: true,
accessKey: this.config.accessKey,
secretKey: this.config.accessSecret
});
2018-09-14 16:07:20 +00:00
}
2019-10-15 12:16:28 +00:00
public async createBucket(bucketName: string) {
await this.minioClient.makeBucket(bucketName, 'ams3').catch(e => console.log(e));
}
public async removeBucket(bucketName: string) {
await this.minioClient.removeBucket(bucketName).catch(e => console.log(e));
}
2019-10-14 21:53:41 +00:00
2019-10-15 12:16:28 +00:00
public async getBucket(bucketName: string) {
return Bucket.getFromName(this, bucketName);
2019-10-14 21:53:41 +00:00
}
2018-09-14 16:07:20 +00:00
}