fix(core): update
This commit is contained in:
parent
9ad70a9942
commit
aa209e87c1
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;
|
||||||
@ -91,9 +95,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 +131,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();
|
|
||||||
return directories.find(directory => {
|
const getDirectory = async (directoryArg: Directory, dirNameToSearch: string) => {
|
||||||
return directory.name === dirNameArg;
|
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user