Compare commits
4 Commits
Author | SHA1 | Date | |
---|---|---|---|
1089c8f3ec | |||
789ff96cf0 | |||
1b49699663 | |||
aa209e87c1 |
2
package-lock.json
generated
2
package-lock.json
generated
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@pushrocks/smartbucket",
|
"name": "@pushrocks/smartbucket",
|
||||||
"version": "1.0.21",
|
"version": "1.0.23",
|
||||||
"lockfileVersion": 1,
|
"lockfileVersion": 1,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@pushrocks/smartbucket",
|
"name": "@pushrocks/smartbucket",
|
||||||
"version": "1.0.21",
|
"version": "1.0.23",
|
||||||
"description": "simple cloud independent object storage",
|
"description": "simple cloud independent object storage",
|
||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
"typings": "dist/index.d.ts",
|
"typings": "dist/index.d.ts",
|
||||||
|
10
test/test.ts
10
test/test.ts
@ -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('dir1/file2.txt', 'dir1/file2.txt content');
|
||||||
await myBucket.fastStore('dir2/file1.txt', 'dir2/file1.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/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');
|
await myBucket.fastStore('file1.txt', 'file1 content');
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -68,10 +69,10 @@ tap.test('should get base directory', async () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
tap.test('should correctly build paths for sub directories', async () => {
|
tap.test('should correctly build paths for sub directories', async () => {
|
||||||
const dir1 = await baseDirectory.getSubDirectoryByName('dir1');
|
const dir4 = await baseDirectory.getSubDirectoryByName('dir3/dir4');
|
||||||
expect(dir1).to.be.instanceOf(smartbucket.Directory);
|
expect(dir4).to.be.instanceOf(smartbucket.Directory);
|
||||||
const dir1BasePath = dir1.getBasePath();
|
const dir4BasePath = dir4.getBasePath();
|
||||||
console.log(dir1BasePath);
|
console.log(dir4BasePath);
|
||||||
});
|
});
|
||||||
|
|
||||||
tap.test('clean up directory style tests', async () => {
|
tap.test('clean up directory style tests', async () => {
|
||||||
@ -79,6 +80,7 @@ tap.test('clean up directory style tests', async () => {
|
|||||||
await myBucket.fastRemove('dir1/file2.txt');
|
await myBucket.fastRemove('dir1/file2.txt');
|
||||||
await myBucket.fastRemove('dir2/file1.txt');
|
await myBucket.fastRemove('dir2/file1.txt');
|
||||||
await myBucket.fastRemove('dir3/file1.txt');
|
await myBucket.fastRemove('dir3/file1.txt');
|
||||||
|
await myBucket.fastRemove('dir3/dir4/file1.txt');
|
||||||
await myBucket.fastRemove('file1.txt');
|
await myBucket.fastRemove('file1.txt');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -43,6 +43,10 @@ export class Directory {
|
|||||||
const parentDirectories = this.getParentDirectories();
|
const parentDirectories = this.getParentDirectories();
|
||||||
let basePath = '';
|
let basePath = '';
|
||||||
for (const parentDir of parentDirectories) {
|
for (const parentDir of parentDirectories) {
|
||||||
|
if (parentDir.name === '') {
|
||||||
|
basePath = this.name;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
basePath = parentDir.name + '/' + this.name;
|
basePath = parentDir.name + '/' + this.name;
|
||||||
}
|
}
|
||||||
return basePath;
|
return basePath;
|
||||||
@ -63,9 +67,12 @@ export class Directory {
|
|||||||
if(!bucketItem.name) {
|
if(!bucketItem.name) {
|
||||||
return;
|
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('/')) {
|
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 directoryArray: Directory[] = [];
|
||||||
const duplexStream = plugins.streamfunction.createDuplexStream<plugins.minio.BucketItem, void>(
|
const duplexStream = plugins.streamfunction.createDuplexStream<plugins.minio.BucketItem, void>(
|
||||||
async bucketItem => {
|
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('/')) {
|
if (subtractedPath.includes('/')) {
|
||||||
const dirName = bucketItem.name.split('/')[0];
|
const dirName = subtractedPath.split('/')[0];
|
||||||
if (directoryArray.find(directory => directory.name === dirName)) {
|
if (directoryArray.find(directory => directory.name === dirName)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -124,11 +134,20 @@ export class Directory {
|
|||||||
* gets a sub directory
|
* gets a sub directory
|
||||||
*/
|
*/
|
||||||
public async getSubDirectoryByName(dirNameArg: string): Promise<Directory> {
|
public async getSubDirectoryByName(dirNameArg: string): Promise<Directory> {
|
||||||
// TODO: make this recursive
|
const dirNameArray = dirNameArg.split('/');
|
||||||
const directories = await this.listDirectories();
|
|
||||||
|
const getDirectory = async (directoryArg: Directory, dirNameToSearch: string) => {
|
||||||
|
const directories = await directoryArg.listDirectories();
|
||||||
return directories.find(directory => {
|
return directories.find(directory => {
|
||||||
return directory.name === dirNameArg;
|
return directory.name === dirNameToSearch;
|
||||||
});
|
});
|
||||||
|
};
|
||||||
|
let wantedDirectory: Directory;
|
||||||
|
for (const dirNameToSearch of dirNameArray) {
|
||||||
|
const directoryToSearchIn = wantedDirectory ? wantedDirectory : this;
|
||||||
|
wantedDirectory = await getDirectory(directoryToSearchIn, dirNameToSearch);
|
||||||
|
}
|
||||||
|
return wantedDirectory;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Reference in New Issue
Block a user