smartbucket/ts/smartbucket.classes.bucket.ts

44 lines
1.3 KiB
TypeScript
Raw Normal View History

2019-10-14 18:55:07 +00:00
import * as plugins from './smartbucket.plugins';
2019-10-15 12:16:28 +00:00
import { SmartBucket } from './smartbucket.classes.smartbucket';
2019-10-14 18:55:07 +00:00
2019-10-15 12:16:28 +00:00
export class Bucket {
2019-10-15 17:23:06 +00:00
public static async getBucketByName(smartbucketRef: SmartBucket, bucketNameArg: string) {
2019-10-15 12:16:28 +00:00
const buckets = await smartbucketRef.minioClient.listBuckets();
const foundBucket = buckets.find(bucket => {
return bucket.name === bucketNameArg;
});
if (foundBucket) {
console.log(`bucket with name ${bucketNameArg} exists.`)
console.log(`Taking this as base for new Bucket instance`);
return new this(smartbucketRef, bucketNameArg);
2019-10-15 17:23:06 +00:00
} else {
return null;
2019-10-15 12:16:28 +00:00
}
}
2019-10-15 17:23:06 +00:00
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));
}
2019-10-15 12:16:28 +00:00
public smartbucketRef: SmartBucket;
public name: string;
2019-10-15 17:23:06 +00:00
2019-10-15 12:16:28 +00:00
constructor(smartbucketRef: SmartBucket, bucketName: string) {
this.smartbucketRef = smartbucketRef;
this.name = bucketName;
}
2019-10-15 17:23:06 +00:00
/**
* store file
*/
2019-10-15 18:00:00 +00:00
public store(pathArg: string, fileContent: string) {
2019-10-15 17:23:06 +00:00
}
2019-10-15 12:16:28 +00:00
}