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 () => {
|
||||
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 () => {
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user