fix: use overwrite to make metadata files work
During a delete the metadata file is updated. As the overwrite property was not set, the metadata couldn't be updated and caused issues.
This commit is contained in:
parent
cec9c07b7c
commit
8d160cefb0
@ -21,8 +21,20 @@ tap.test('should create a valid smartbucket', async () => {
|
||||
expect(myBucket.name).toEqual('testzone');
|
||||
});
|
||||
|
||||
tap.test('', async () => {
|
||||
|
||||
})
|
||||
tap.test('should put a file into the trash', async () => {
|
||||
const path = 'hithere/socool.txt';
|
||||
const file = await myBucket.fastPut({
|
||||
path,
|
||||
contents: 'hi there!',
|
||||
});
|
||||
expect(await file.getMetaData().then((meta) => meta.metadataFile.getJsonData())).toEqual({});
|
||||
await file.delete({ mode: 'trash' });
|
||||
expect(await file.getMetaData().then((meta) => meta.metadataFile.getJsonData())).toEqual({
|
||||
custom_recycle: {
|
||||
deletedAt: 123,
|
||||
originalPath: 'hithere/socool.txt',
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
export default tap.start();
|
@ -41,9 +41,12 @@ tap.test('should get data in bucket', async () => {
|
||||
const fileString = await myBucket.fastGet({
|
||||
path: 'hithere/socool.txt',
|
||||
});
|
||||
const fileStringStream = await myBucket.fastGetStream({
|
||||
const fileStringStream = await myBucket.fastGetStream(
|
||||
{
|
||||
path: 'hithere/socool.txt',
|
||||
}, 'nodestream');
|
||||
},
|
||||
'nodestream'
|
||||
);
|
||||
console.log(fileString);
|
||||
});
|
||||
|
||||
|
@ -331,7 +331,9 @@ export class Bucket {
|
||||
}): Promise<void> {
|
||||
try {
|
||||
const destinationBucket = optionsArg.targetBucket || this;
|
||||
const exists = await destinationBucket.fastExists({ path: optionsArg.destinationPath });
|
||||
const exists = await destinationBucket.fastExists({
|
||||
path: optionsArg.destinationPath,
|
||||
});
|
||||
|
||||
if (exists && !optionsArg.overwrite) {
|
||||
console.error(
|
||||
@ -424,8 +426,8 @@ export class Bucket {
|
||||
Prefix: checkPath,
|
||||
Delimiter: '/',
|
||||
});
|
||||
const response = await this.smartbucketRef.s3Client.send(command);
|
||||
return response.CommonPrefixes.length > 0;
|
||||
const { CommonPrefixes } = await this.smartbucketRef.s3Client.send(command);
|
||||
return !!CommonPrefixes && CommonPrefixes.length > 0;
|
||||
}
|
||||
|
||||
public async isFile(pathDescriptor: interfaces.IPathDecriptor): Promise<boolean> {
|
||||
@ -435,8 +437,8 @@ export class Bucket {
|
||||
Prefix: checkPath,
|
||||
Delimiter: '/',
|
||||
});
|
||||
const response = await this.smartbucketRef.s3Client.send(command);
|
||||
return response.Contents.length > 0;
|
||||
const { Contents } = await this.smartbucketRef.s3Client.send(command);
|
||||
return !!Contents && Contents.length > 0;
|
||||
}
|
||||
|
||||
public async getMagicBytes(optionsArg: { path: string; length: number }): Promise<Buffer> {
|
||||
|
@ -92,16 +92,13 @@ export class File {
|
||||
/**
|
||||
* deletes this file
|
||||
*/
|
||||
public async delete(optionsArg?: {
|
||||
mode: 'trash' | 'permanent';
|
||||
}) {
|
||||
|
||||
public async delete(optionsArg?: { mode: 'trash' | 'permanent' }) {
|
||||
optionsArg = {
|
||||
... {
|
||||
...{
|
||||
mode: 'permanent',
|
||||
},
|
||||
...optionsArg,
|
||||
}
|
||||
};
|
||||
|
||||
if (optionsArg.mode === 'permanent') {
|
||||
await this.parentDirectoryRef.bucketRef.fastRemove({
|
||||
@ -169,16 +166,19 @@ export class File {
|
||||
await this.parentDirectoryRef.bucketRef.fastPutStream({
|
||||
path: this.getBasePath(),
|
||||
readableStream: optionsArg.contents,
|
||||
overwrite: true,
|
||||
});
|
||||
} else if (Buffer.isBuffer(optionsArg.contents)) {
|
||||
await this.parentDirectoryRef.bucketRef.fastPut({
|
||||
path: this.getBasePath(),
|
||||
contents: optionsArg.contents,
|
||||
overwrite: true,
|
||||
});
|
||||
} else if (typeof optionsArg.contents === 'string') {
|
||||
await this.parentDirectoryRef.bucketRef.fastPut({
|
||||
path: this.getBasePath(),
|
||||
contents: Buffer.from(optionsArg.contents, optionsArg.encoding),
|
||||
overwrite: true,
|
||||
});
|
||||
}
|
||||
}
|
||||
@ -238,7 +238,7 @@ export class File {
|
||||
public async getMagicBytes(optionsArg: { length: number }): Promise<Buffer> {
|
||||
return this.parentDirectoryRef.bucketRef.getMagicBytes({
|
||||
path: this.getBasePath(),
|
||||
length: optionsArg.length
|
||||
})
|
||||
length: optionsArg.length,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user