store-s3-aws 1.0.1 → 1.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "store-s3-aws",
3
- "version": "1.0.1",
3
+ "version": "1.1.2",
4
4
  "description": "Lib to store files in AWS S3",
5
5
  "main": "index.js",
6
6
  "scripts": {
package/src/AwsS3Store.js CHANGED
@@ -1,7 +1,7 @@
1
1
  const path = require('path');
2
2
  const fs = require('fs');
3
3
  const { createReadStream } = require('fs');
4
- const { S3Client, HeadObjectCommand, GetObjectCommand, DeleteObjectCommand } = require('@aws-sdk/client-s3');
4
+ const { S3Client, HeadObjectCommand, GetObjectCommand, DeleteObjectCommand, CopyObjectCommand } = require('@aws-sdk/client-s3');
5
5
  const { Upload } = require('@aws-sdk/lib-storage');
6
6
 
7
7
  class AwsS3Store {
@@ -124,6 +124,12 @@ class AwsS3Store {
124
124
  };
125
125
  try {
126
126
  await this.#getClientS3().send(new HeadObjectCommand(params));
127
+ const backupKey = `${options.remoteFilePath}.backup`;
128
+ await this.#getClientS3().send(new CopyObjectCommand({
129
+ Bucket: this.bucketName,
130
+ CopySource: `${this.bucketName}/${options.remoteFilePath}`,
131
+ Key: backupKey
132
+ }));
127
133
  await this.#getClientS3().send(new DeleteObjectCommand(params));
128
134
  this.debugLog(`[METHOD: #deletePrevious] File deleted. PATH='${options.remoteFilePath}'.`);
129
135
  } catch (err) {