Compare commits

..

6 Commits

Author SHA1 Message Date
6596893ee5 1.0.17 2019-10-18 15:43:06 +02:00
514a8407f6 fix(core): update 2019-10-18 15:43:06 +02:00
fcadbe0a44 1.0.16 2019-10-18 12:34:33 +02:00
e6398ebbe3 fix(core): update 2019-10-18 12:34:32 +02:00
8a7824f2d9 1.0.15 2019-10-18 12:22:43 +02:00
b61118c950 fix(core): update 2019-10-18 12:22:42 +02:00
5 changed files with 39 additions and 26 deletions

2
package-lock.json generated
View File

@ -1,6 +1,6 @@
{
"name": "@pushrocks/smartbucket",
"version": "1.0.14",
"version": "1.0.17",
"lockfileVersion": 1,
"requires": true,
"dependencies": {

View File

@ -1,6 +1,6 @@
{
"name": "@pushrocks/smartbucket",
"version": "1.0.14",
"version": "1.0.17",
"description": "simple cloud independent object storage",
"main": "dist/index.js",
"typings": "dist/index.d.ts",

View File

@ -13,22 +13,22 @@ tap.test('should create a valid smartbucket', async () => {
testSmartbucket = new smartbucket.SmartBucket({
accessKey: testQenv.getEnvVarOnDemand('S3_KEY'),
accessSecret: testQenv.getEnvVarOnDemand('S3_SECRET'),
endpoint: 'ams3.digitaloceanspaces.com'
endpoint: 'fra1.digitaloceanspaces.com'
});
});
tap.skip.test('should create testbucket', async () => {
await testSmartbucket.createBucket('smartbucket');
await testSmartbucket.createBucket('testzone');
});
tap.skip.test('should remove testbucket', async () => {
await testSmartbucket.removeBucket('pushrocks-smartbucket');
await testSmartbucket.removeBucket('testzone');
});
tap.test('should get a bucket', async () => {
myBucket = await testSmartbucket.getBucketByName('smartbucket');
myBucket = await testSmartbucket.getBucketByName('testzone');
expect(myBucket).to.be.instanceOf(smartbucket.Bucket);
expect(myBucket.name).to.equal('smartbucket');
expect(myBucket.name).to.equal('testzone');
});
// Fast operations
@ -58,8 +58,13 @@ tap.test('prepare for directory style tests', async () => {
tap.test('should get base directory', async () => {
baseDirectory = await myBucket.getBaseDirectory();
const directories = await baseDirectory.listDirectories();
console.log('Found the following directories:');
console.log(directories);
expect(directories.length).to.equal(3);
const files = await baseDirectory.listFiles();
console.log('Found the following files:');
console.log(files);
expect(files.length).to.equal(1);
});
tap.test('clean up directory style tests', async () => {

View File

@ -4,7 +4,7 @@ import { File } from './smartbucket.classes.file';
export class Directory {
public bucketRef: Bucket;
public parentDirectory: Directory;
public parentDirectoryRef: Directory;
public name: string;
public tree: string[];
@ -13,7 +13,7 @@ export class Directory {
constructor(bucketRefArg: Bucket, parentDiretory: Directory, name: string) {
this.bucketRef = bucketRefArg;
this.parentDirectory = parentDiretory;
this.parentDirectoryRef = parentDiretory;
this.name = name;
}
@ -22,9 +22,9 @@ export class Directory {
*/
public getParentDirectories(): Directory[] {
let parentDirectories: Directory[] = [];
if (this.parentDirectory) {
parentDirectories.push(this.parentDirectory);
parentDirectories = parentDirectories.concat(this.parentDirectory.getParentDirectories());
if (this.parentDirectoryRef) {
parentDirectories.push(this.parentDirectoryRef);
parentDirectories = parentDirectories.concat(this.parentDirectoryRef.getParentDirectories());
}
return parentDirectories;
}
@ -58,9 +58,16 @@ export class Directory {
this.getBasePath()
);
const fileArray: File[] = [];
const duplexStream = plugins.streamfunction.createDuplexStream<string, void>(
async fileName => {
fileArray.push(new File(this, fileName));
const duplexStream = plugins.streamfunction.createDuplexStream<plugins.minio.BucketItem, void>(
async bucketItem => {
if(!bucketItem.name) {
return;
}
const subtractedPath = bucketItem.name.replace(this.getBasePath(), '');
if (!subtractedPath.includes('/')) {
fileArray.push(new File(this, bucketItem.name));
}
},
async tools => {
done.resolve();
@ -83,11 +90,10 @@ export class Directory {
);
const directoryArray: Directory[] = [];
const duplexStream = plugins.streamfunction.createDuplexStream<plugins.minio.BucketItem, void>(
async fileName => {
console.log(fileName);
const subtractedPath = fileName.name.replace(this.getBasePath(), '');
async bucketItem => {
const subtractedPath = bucketItem.name.replace(this.getBasePath(), '');
if (subtractedPath.includes('/')) {
const dirName = fileName.name.split('/')[0];
const dirName = bucketItem.name.split('/')[0];
if (directoryArray.find(directory => directory.name === dirName)) {
return;
}

View File

@ -33,13 +33,15 @@ export class File {
}
// INSTANCE
public directoryRef: Directory;
public parentDirectoryRef: Directory;
public name: string;
public path: string;
public metaData: IFileMetaData;
constructor(directoryRefArg: Directory, fileName: string) {
this.directoryRef = directoryRefArg;
this.parentDirectoryRef = directoryRefArg;
this.name = fileName;
}
public async getContentAsString() {
@ -49,8 +51,8 @@ export class File {
public async getContentAsBuffer() {
const done = plugins.smartpromise.defer();
const fileStream = await this.directoryRef.bucketRef.smartbucketRef.minioClient
.getObject(this.directoryRef.bucketRef.name, this.path)
const fileStream = await this.parentDirectoryRef.bucketRef.smartbucketRef.minioClient
.getObject(this.parentDirectoryRef.bucketRef.name, this.path)
.catch(e => console.log(e));
let completeFile = new Buffer('');
const duplexStream = plugins.streamfunction.createDuplexStream<Buffer, Buffer>(
@ -82,10 +84,10 @@ export class File {
* removes this file
*/
public async remove() {
await this.directoryRef.bucketRef.smartbucketRef.minioClient.removeObject(
this.directoryRef.bucketRef.name,
await this.parentDirectoryRef.bucketRef.smartbucketRef.minioClient.removeObject(
this.parentDirectoryRef.bucketRef.name,
this.path
);
await this.directoryRef.listFiles();
await this.parentDirectoryRef.listFiles();
}
}