fix(core): update
This commit is contained in:
@@ -1 +1,4 @@
|
||||
import * as plugins from './smartbucket.plugins';
|
||||
export * from './smartbucket.classes.smartbucket';
|
||||
export * from './smartbucket.classes.bucket';
|
||||
export * from './smartbucket.classes.directory';
|
||||
export * from './smartbucket.classes.file';
|
||||
|
@@ -1,3 +1,24 @@
|
||||
import * as plugins from './smartbucket.plugins';
|
||||
import { SmartBucket } from './smartbucket.classes.smartbucket';
|
||||
|
||||
export class Bucket {}
|
||||
export class Bucket {
|
||||
public static async createFromName(smartbucketRef: SmartBucket, bucketNameArg: string) {
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
public smartbucketRef: SmartBucket;
|
||||
public name: string;
|
||||
constructor(smartbucketRef: SmartBucket, bucketName: string) {
|
||||
this.smartbucketRef = smartbucketRef;
|
||||
this.name = bucketName;
|
||||
}
|
||||
}
|
||||
|
@@ -1,33 +1,40 @@
|
||||
import * as plugins from './smartbucket.plugins';
|
||||
import { Bucket } from './smartbucket.classes.bucket';
|
||||
|
||||
export interface ISmartBucketConfig {
|
||||
provider: 'digitalocean';
|
||||
projectId: string;
|
||||
bucketName: string;
|
||||
endpoint: string;
|
||||
accessKey: string;
|
||||
accessSecret: string;
|
||||
}
|
||||
|
||||
export class SmartBucket {
|
||||
public config: ISmartBucketConfig;
|
||||
|
||||
public minioClient = new plugins.minio.Client({
|
||||
endPoint: 'ams3.digitaloceanspaces.com',
|
||||
port: 9000,
|
||||
useSSL: true,
|
||||
accessKey: 'Q3AM3UQ867SPQQA43P2F',
|
||||
secretKey: 'zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG'
|
||||
});
|
||||
public minioClient: plugins.minio.Client;
|
||||
|
||||
/**
|
||||
* the constructor of SmartBucket
|
||||
*/
|
||||
constructor(configArg: ISmartBucketConfig) {
|
||||
this.config = configArg;
|
||||
this.minioClient = new plugins.minio.Client({
|
||||
endPoint: this.config.endpoint,
|
||||
port: 443,
|
||||
useSSL: true,
|
||||
accessKey: this.config.accessKey,
|
||||
secretKey: this.config.accessSecret
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* initializes the Smartbucket
|
||||
*/
|
||||
public async init() {
|
||||
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));
|
||||
}
|
||||
|
||||
public async getBucket(bucketName: string) {
|
||||
return Bucket.getFromName(this, bucketName);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user