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');
|
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();
|
export default tap.start();
|
||||||
|
@ -41,9 +41,12 @@ tap.test('should get data in bucket', async () => {
|
|||||||
const fileString = await myBucket.fastGet({
|
const fileString = await myBucket.fastGet({
|
||||||
path: 'hithere/socool.txt',
|
path: 'hithere/socool.txt',
|
||||||
});
|
});
|
||||||
const fileStringStream = await myBucket.fastGetStream({
|
const fileStringStream = await myBucket.fastGetStream(
|
||||||
path: 'hithere/socool.txt',
|
{
|
||||||
}, 'nodestream');
|
path: 'hithere/socool.txt',
|
||||||
|
},
|
||||||
|
'nodestream'
|
||||||
|
);
|
||||||
console.log(fileString);
|
console.log(fileString);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -331,7 +331,9 @@ export class Bucket {
|
|||||||
}): Promise<void> {
|
}): Promise<void> {
|
||||||
try {
|
try {
|
||||||
const destinationBucket = optionsArg.targetBucket || this;
|
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) {
|
if (exists && !optionsArg.overwrite) {
|
||||||
console.error(
|
console.error(
|
||||||
@ -424,8 +426,8 @@ export class Bucket {
|
|||||||
Prefix: checkPath,
|
Prefix: checkPath,
|
||||||
Delimiter: '/',
|
Delimiter: '/',
|
||||||
});
|
});
|
||||||
const response = await this.smartbucketRef.s3Client.send(command);
|
const { CommonPrefixes } = await this.smartbucketRef.s3Client.send(command);
|
||||||
return response.CommonPrefixes.length > 0;
|
return !!CommonPrefixes && CommonPrefixes.length > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async isFile(pathDescriptor: interfaces.IPathDecriptor): Promise<boolean> {
|
public async isFile(pathDescriptor: interfaces.IPathDecriptor): Promise<boolean> {
|
||||||
@ -435,8 +437,8 @@ export class Bucket {
|
|||||||
Prefix: checkPath,
|
Prefix: checkPath,
|
||||||
Delimiter: '/',
|
Delimiter: '/',
|
||||||
});
|
});
|
||||||
const response = await this.smartbucketRef.s3Client.send(command);
|
const { Contents } = await this.smartbucketRef.s3Client.send(command);
|
||||||
return response.Contents.length > 0;
|
return !!Contents && Contents.length > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async getMagicBytes(optionsArg: { path: string; length: number }): Promise<Buffer> {
|
public async getMagicBytes(optionsArg: { path: string; length: number }): Promise<Buffer> {
|
||||||
@ -449,7 +451,7 @@ export class Bucket {
|
|||||||
const response = await this.smartbucketRef.s3Client.send(command);
|
const response = await this.smartbucketRef.s3Client.send(command);
|
||||||
const chunks = [];
|
const chunks = [];
|
||||||
const stream = response.Body as any; // SdkStreamMixin includes readable stream
|
const stream = response.Body as any; // SdkStreamMixin includes readable stream
|
||||||
|
|
||||||
for await (const chunk of stream) {
|
for await (const chunk of stream) {
|
||||||
chunks.push(chunk);
|
chunks.push(chunk);
|
||||||
}
|
}
|
||||||
|
@ -92,16 +92,13 @@ export class File {
|
|||||||
/**
|
/**
|
||||||
* deletes this file
|
* deletes this file
|
||||||
*/
|
*/
|
||||||
public async delete(optionsArg?: {
|
public async delete(optionsArg?: { mode: 'trash' | 'permanent' }) {
|
||||||
mode: 'trash' | 'permanent';
|
|
||||||
}) {
|
|
||||||
|
|
||||||
optionsArg = {
|
optionsArg = {
|
||||||
... {
|
...{
|
||||||
mode: 'permanent',
|
mode: 'permanent',
|
||||||
},
|
},
|
||||||
...optionsArg,
|
...optionsArg,
|
||||||
}
|
};
|
||||||
|
|
||||||
if (optionsArg.mode === 'permanent') {
|
if (optionsArg.mode === 'permanent') {
|
||||||
await this.parentDirectoryRef.bucketRef.fastRemove({
|
await this.parentDirectoryRef.bucketRef.fastRemove({
|
||||||
@ -126,7 +123,7 @@ export class File {
|
|||||||
path: await trash.getTrashKeyByOriginalBasePath(this.getBasePath()),
|
path: await trash.getTrashKeyByOriginalBasePath(this.getBasePath()),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
await this.parentDirectoryRef.listFiles();
|
await this.parentDirectoryRef.listFiles();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -169,16 +166,19 @@ export class File {
|
|||||||
await this.parentDirectoryRef.bucketRef.fastPutStream({
|
await this.parentDirectoryRef.bucketRef.fastPutStream({
|
||||||
path: this.getBasePath(),
|
path: this.getBasePath(),
|
||||||
readableStream: optionsArg.contents,
|
readableStream: optionsArg.contents,
|
||||||
|
overwrite: true,
|
||||||
});
|
});
|
||||||
} else if (Buffer.isBuffer(optionsArg.contents)) {
|
} else if (Buffer.isBuffer(optionsArg.contents)) {
|
||||||
await this.parentDirectoryRef.bucketRef.fastPut({
|
await this.parentDirectoryRef.bucketRef.fastPut({
|
||||||
path: this.getBasePath(),
|
path: this.getBasePath(),
|
||||||
contents: optionsArg.contents,
|
contents: optionsArg.contents,
|
||||||
|
overwrite: true,
|
||||||
});
|
});
|
||||||
} else if (typeof optionsArg.contents === 'string') {
|
} else if (typeof optionsArg.contents === 'string') {
|
||||||
await this.parentDirectoryRef.bucketRef.fastPut({
|
await this.parentDirectoryRef.bucketRef.fastPut({
|
||||||
path: this.getBasePath(),
|
path: this.getBasePath(),
|
||||||
contents: Buffer.from(optionsArg.contents, optionsArg.encoding),
|
contents: Buffer.from(optionsArg.contents, optionsArg.encoding),
|
||||||
|
overwrite: true,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -238,7 +238,7 @@ export class File {
|
|||||||
public async getMagicBytes(optionsArg: { length: number }): Promise<Buffer> {
|
public async getMagicBytes(optionsArg: { length: number }): Promise<Buffer> {
|
||||||
return this.parentDirectoryRef.bucketRef.getMagicBytes({
|
return this.parentDirectoryRef.bucketRef.getMagicBytes({
|
||||||
path: this.getBasePath(),
|
path: this.getBasePath(),
|
||||||
length: optionsArg.length
|
length: optionsArg.length,
|
||||||
})
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user