Compare commits

...

8 Commits

Author SHA1 Message Date
1089c8f3ec 1.0.23 2019-10-20 01:19:34 +02:00
789ff96cf0 fix(core): update 2019-10-20 01:19:34 +02:00
1b49699663 1.0.22 2019-10-20 01:18:13 +02:00
aa209e87c1 fix(core): update 2019-10-20 01:18:13 +02:00
9ad70a9942 1.0.21 2019-10-20 00:45:12 +02:00
bc41089925 fix(core): update 2019-10-20 00:45:11 +02:00
ab39809c2a 1.0.20 2019-10-19 22:57:37 +02:00
cede6c7539 fix(core): update 2019-10-19 22:57:36 +02:00
4 changed files with 42 additions and 13 deletions

2
package-lock.json generated
View File

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

View File

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

View File

@ -52,6 +52,7 @@ tap.test('prepare for directory style tests', async () => {
await myBucket.fastStore('dir1/file2.txt', 'dir1/file2.txt content');
await myBucket.fastStore('dir2/file1.txt', 'dir2/file1.txt content');
await myBucket.fastStore('dir3/file1.txt', 'dir3/file1.txt content');
await myBucket.fastStore('dir3/dir4/file1.txt', 'dir3/dir4/file1.txt content');
await myBucket.fastStore('file1.txt', 'file1 content');
});
@ -67,11 +68,19 @@ tap.test('should get base directory', async () => {
expect(files.length).to.equal(1);
});
tap.test('should correctly build paths for sub directories', async () => {
const dir4 = await baseDirectory.getSubDirectoryByName('dir3/dir4');
expect(dir4).to.be.instanceOf(smartbucket.Directory);
const dir4BasePath = dir4.getBasePath();
console.log(dir4BasePath);
});
tap.test('clean up directory style tests', async () => {
await myBucket.fastRemove('dir1/file1.txt');
await myBucket.fastRemove('dir1/file2.txt');
await myBucket.fastRemove('dir2/file1.txt');
await myBucket.fastRemove('dir3/file1.txt');
await myBucket.fastRemove('dir3/dir4/file1.txt');
await myBucket.fastRemove('file1.txt');
});

View File

@ -43,7 +43,11 @@ export class Directory {
const parentDirectories = this.getParentDirectories();
let basePath = '';
for (const parentDir of parentDirectories) {
basePath = parentDir.name + '/' + basePath;
if (parentDir.name === '') {
basePath = this.name;
continue;
}
basePath = parentDir.name + '/' + this.name;
}
return basePath;
}
@ -63,9 +67,12 @@ export class Directory {
if(!bucketItem.name) {
return;
}
const subtractedPath = bucketItem.name.replace(this.getBasePath(), '');
let subtractedPath = bucketItem.name.replace(this.getBasePath(), '');
if (subtractedPath.startsWith('/')) {
subtractedPath = subtractedPath.substr(1);
}
if (!subtractedPath.includes('/')) {
fileArray.push(new File(this, bucketItem.name));
fileArray.push(new File(this, subtractedPath));
}
},
@ -91,9 +98,12 @@ export class Directory {
const directoryArray: Directory[] = [];
const duplexStream = plugins.streamfunction.createDuplexStream<plugins.minio.BucketItem, void>(
async bucketItem => {
const subtractedPath = bucketItem.name.replace(this.getBasePath(), '');
let subtractedPath = bucketItem.name.replace(this.getBasePath(), '');
if (subtractedPath.startsWith('/')) {
subtractedPath = subtractedPath.substr(1);
}
if (subtractedPath.includes('/')) {
const dirName = bucketItem.name.split('/')[0];
const dirName = subtractedPath.split('/')[0];
if (directoryArray.find(directory => directory.name === dirName)) {
return;
}
@ -124,11 +134,20 @@ export class Directory {
* gets a sub directory
*/
public async getSubDirectoryByName(dirNameArg: string): Promise<Directory> {
// TODO: make this recursive
const directories = await this.listDirectories();
return directories.find(directory => {
return directory.name === dirNameArg;
});
const dirNameArray = dirNameArg.split('/');
const getDirectory = async (directoryArg: Directory, dirNameToSearch: string) => {
const directories = await directoryArg.listDirectories();
return directories.find(directory => {
return directory.name === dirNameToSearch;
});
};
let wantedDirectory: Directory;
for (const dirNameToSearch of dirNameArray) {
const directoryToSearchIn = wantedDirectory ? wantedDirectory : this;
wantedDirectory = await getDirectory(directoryToSearchIn, dirNameToSearch);
}
return wantedDirectory;
}
/**
@ -154,7 +173,8 @@ export class Directory {
public async fastGet(pathArg: string) {
const path = plugins.path.join(this.getBasePath(), pathArg);
await this.bucketRef.fastGet(path);
const result = await this.bucketRef.fastGet(path);
return result;
}
public async fastRemove(pathArg: string) {