fix(core): update

This commit is contained in:
2019-10-15 19:23:06 +02:00
parent c333533c63
commit caf0566020
3 changed files with 38 additions and 7 deletions

View File

@@ -2,7 +2,7 @@ import * as plugins from './smartbucket.plugins';
import { SmartBucket } from './smartbucket.classes.smartbucket';
export class Bucket {
public static async createFromName(smartbucketRef: SmartBucket, bucketNameArg: string) {
public static async getBucketByName(smartbucketRef: SmartBucket, bucketNameArg: string) {
const buckets = await smartbucketRef.minioClient.listBuckets();
const foundBucket = buckets.find(bucket => {
return bucket.name === bucketNameArg;
@@ -12,13 +12,32 @@ export class Bucket {
console.log(`bucket with name ${bucketNameArg} exists.`)
console.log(`Taking this as base for new Bucket instance`);
return new this(smartbucketRef, bucketNameArg);
} else {
return null;
}
}
public static async createBucketByName(smartbucketRef: SmartBucket, bucketName: string) {
await smartbucketRef.minioClient.makeBucket(bucketName, 'ams3').catch(e => console.log(e));
return new Bucket(smartbucketRef, bucketName);
}
public static async removeBucketByName(smartbucketRef: SmartBucket, bucketName: string) {
await smartbucketRef.minioClient.removeBucket(bucketName).catch(e => console.log(e));
}
public smartbucketRef: SmartBucket;
public name: string;
constructor(smartbucketRef: SmartBucket, bucketName: string) {
this.smartbucketRef = smartbucketRef;
this.name = bucketName;
}
/**
* store file
*/
public store(fileName:) {
}
}

View File

@@ -26,15 +26,16 @@ export class SmartBucket {
});
}
public async createBucket(bucketName: string) {
await this.minioClient.makeBucket(bucketName, 'ams3').catch(e => console.log(e));
public async createBucket(bucketNameArg: string) {
const bucket = await Bucket.createBucketByName(this, bucketNameArg);
return bucket;
}
public async removeBucket(bucketName: string) {
await this.minioClient.removeBucket(bucketName).catch(e => console.log(e));
await Bucket.removeBucketByName(this, bucketName);
}
public async getBucket(bucketName: string) {
return Bucket.getFromName(this, bucketName);
public async getBucketByName(bucketName: string) {
return Bucket.getBucketByName(this, bucketName);
}
}