fix(core): update
This commit is contained in:
parent
fcadbe0a44
commit
514a8407f6
@ -58,9 +58,13 @@ tap.test('prepare for directory style tests', async () => {
|
|||||||
tap.test('should get base directory', async () => {
|
tap.test('should get base directory', async () => {
|
||||||
baseDirectory = await myBucket.getBaseDirectory();
|
baseDirectory = await myBucket.getBaseDirectory();
|
||||||
const directories = await baseDirectory.listDirectories();
|
const directories = await baseDirectory.listDirectories();
|
||||||
|
console.log('Found the following directories:');
|
||||||
|
console.log(directories);
|
||||||
expect(directories.length).to.equal(3);
|
expect(directories.length).to.equal(3);
|
||||||
const files = await baseDirectory.listFiles();
|
const files = await baseDirectory.listFiles();
|
||||||
|
console.log('Found the following files:');
|
||||||
console.log(files);
|
console.log(files);
|
||||||
|
expect(files.length).to.equal(1);
|
||||||
});
|
});
|
||||||
|
|
||||||
tap.test('clean up directory style tests', async () => {
|
tap.test('clean up directory style tests', async () => {
|
||||||
|
@ -4,7 +4,7 @@ import { File } from './smartbucket.classes.file';
|
|||||||
|
|
||||||
export class Directory {
|
export class Directory {
|
||||||
public bucketRef: Bucket;
|
public bucketRef: Bucket;
|
||||||
public parentDirectory: Directory;
|
public parentDirectoryRef: Directory;
|
||||||
public name: string;
|
public name: string;
|
||||||
|
|
||||||
public tree: string[];
|
public tree: string[];
|
||||||
@ -13,7 +13,7 @@ export class Directory {
|
|||||||
|
|
||||||
constructor(bucketRefArg: Bucket, parentDiretory: Directory, name: string) {
|
constructor(bucketRefArg: Bucket, parentDiretory: Directory, name: string) {
|
||||||
this.bucketRef = bucketRefArg;
|
this.bucketRef = bucketRefArg;
|
||||||
this.parentDirectory = parentDiretory;
|
this.parentDirectoryRef = parentDiretory;
|
||||||
this.name = name;
|
this.name = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -22,9 +22,9 @@ export class Directory {
|
|||||||
*/
|
*/
|
||||||
public getParentDirectories(): Directory[] {
|
public getParentDirectories(): Directory[] {
|
||||||
let parentDirectories: Directory[] = [];
|
let parentDirectories: Directory[] = [];
|
||||||
if (this.parentDirectory) {
|
if (this.parentDirectoryRef) {
|
||||||
parentDirectories.push(this.parentDirectory);
|
parentDirectories.push(this.parentDirectoryRef);
|
||||||
parentDirectories = parentDirectories.concat(this.parentDirectory.getParentDirectories());
|
parentDirectories = parentDirectories.concat(this.parentDirectoryRef.getParentDirectories());
|
||||||
}
|
}
|
||||||
return parentDirectories;
|
return parentDirectories;
|
||||||
}
|
}
|
||||||
@ -58,9 +58,16 @@ export class Directory {
|
|||||||
this.getBasePath()
|
this.getBasePath()
|
||||||
);
|
);
|
||||||
const fileArray: File[] = [];
|
const fileArray: File[] = [];
|
||||||
const duplexStream = plugins.streamfunction.createDuplexStream<string, void>(
|
const duplexStream = plugins.streamfunction.createDuplexStream<plugins.minio.BucketItem, void>(
|
||||||
async fileName => {
|
async bucketItem => {
|
||||||
fileArray.push(new File(this, fileName));
|
if(!bucketItem.name) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const subtractedPath = bucketItem.name.replace(this.getBasePath(), '');
|
||||||
|
if (!subtractedPath.includes('/')) {
|
||||||
|
fileArray.push(new File(this, bucketItem.name));
|
||||||
|
}
|
||||||
|
|
||||||
},
|
},
|
||||||
async tools => {
|
async tools => {
|
||||||
done.resolve();
|
done.resolve();
|
||||||
@ -83,11 +90,10 @@ 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 fileName => {
|
async bucketItem => {
|
||||||
console.log(fileName);
|
const subtractedPath = bucketItem.name.replace(this.getBasePath(), '');
|
||||||
const subtractedPath = fileName.name.replace(this.getBasePath(), '');
|
|
||||||
if (subtractedPath.includes('/')) {
|
if (subtractedPath.includes('/')) {
|
||||||
const dirName = fileName.name.split('/')[0];
|
const dirName = bucketItem.name.split('/')[0];
|
||||||
if (directoryArray.find(directory => directory.name === dirName)) {
|
if (directoryArray.find(directory => directory.name === dirName)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -33,13 +33,15 @@ export class File {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// INSTANCE
|
// INSTANCE
|
||||||
public directoryRef: Directory;
|
public parentDirectoryRef: Directory;
|
||||||
|
public name: string;
|
||||||
|
|
||||||
public path: string;
|
public path: string;
|
||||||
public metaData: IFileMetaData;
|
public metaData: IFileMetaData;
|
||||||
|
|
||||||
constructor(directoryRefArg: Directory, fileName: string) {
|
constructor(directoryRefArg: Directory, fileName: string) {
|
||||||
this.directoryRef = directoryRefArg;
|
this.parentDirectoryRef = directoryRefArg;
|
||||||
|
this.name = fileName;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async getContentAsString() {
|
public async getContentAsString() {
|
||||||
@ -49,8 +51,8 @@ export class File {
|
|||||||
|
|
||||||
public async getContentAsBuffer() {
|
public async getContentAsBuffer() {
|
||||||
const done = plugins.smartpromise.defer();
|
const done = plugins.smartpromise.defer();
|
||||||
const fileStream = await this.directoryRef.bucketRef.smartbucketRef.minioClient
|
const fileStream = await this.parentDirectoryRef.bucketRef.smartbucketRef.minioClient
|
||||||
.getObject(this.directoryRef.bucketRef.name, this.path)
|
.getObject(this.parentDirectoryRef.bucketRef.name, this.path)
|
||||||
.catch(e => console.log(e));
|
.catch(e => console.log(e));
|
||||||
let completeFile = new Buffer('');
|
let completeFile = new Buffer('');
|
||||||
const duplexStream = plugins.streamfunction.createDuplexStream<Buffer, Buffer>(
|
const duplexStream = plugins.streamfunction.createDuplexStream<Buffer, Buffer>(
|
||||||
@ -82,10 +84,10 @@ export class File {
|
|||||||
* removes this file
|
* removes this file
|
||||||
*/
|
*/
|
||||||
public async remove() {
|
public async remove() {
|
||||||
await this.directoryRef.bucketRef.smartbucketRef.minioClient.removeObject(
|
await this.parentDirectoryRef.bucketRef.smartbucketRef.minioClient.removeObject(
|
||||||
this.directoryRef.bucketRef.name,
|
this.parentDirectoryRef.bucketRef.name,
|
||||||
this.path
|
this.path
|
||||||
);
|
);
|
||||||
await this.directoryRef.listFiles();
|
await this.parentDirectoryRef.listFiles();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user