eip-cloud-services 1.0.8 → 1.0.9

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.
Files changed (2) hide show
  1. package/package.json +2 -2
  2. package/src/s3.js +33 -13
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eip-cloud-services",
3
- "version": "1.0.8",
3
+ "version": "1.0.9",
4
4
  "description": "Houses a collection of helpers for connecting with Cloud services.",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -22,4 +22,4 @@
22
22
  "mysql": "^2.18.1",
23
23
  "redis": "^4.6.7"
24
24
  }
25
- }
25
+ }
package/src/s3.js CHANGED
@@ -251,7 +251,7 @@ exports.del = async ( key, bucket = config.s3.Bucket ) => {
251
251
  };
252
252
 
253
253
  /**
254
- * Move an object within S3 to a different location.
254
+ * Copy an object within S3 to a different location. (This keep the original like a COPY / PASTE operation)
255
255
  *
256
256
  * @param {string} sourceKey - The source object key.
257
257
  * @param {string} destinationKey - The destination object key.
@@ -260,7 +260,7 @@ exports.del = async ( key, bucket = config.s3.Bucket ) => {
260
260
  * @returns {Promise} A promise that resolves when the object is successfully moved in S3.
261
261
  * @description Moves an object from the source location to the destination location within S3.
262
262
  */
263
- exports.move = async ( sourceKey, destinationKey, sourceBucket = config.s3.Bucket, destinationBucket = config.s3.Bucket ) => {
263
+ exports.copy = async ( sourceKey, destinationKey, sourceBucket = config.s3.Bucket, destinationBucket = config.s3.Bucket ) => {
264
264
  try {
265
265
  // Copy the object to the destination location
266
266
  const copyCommand = new CopyObjectCommand ( {
@@ -272,19 +272,39 @@ exports.move = async ( sourceKey, destinationKey, sourceBucket = config.s3.Bucke
272
272
  } );
273
273
 
274
274
  await S3.send ( copyCommand );
275
-
276
- // Delete the object from the source location
277
- const deleteCommand = new DeleteObjectsCommand ( {
278
- Bucket: sourceBucket,
279
- Delete: {
280
- Objects: [
281
- { Key: sourceKey }
282
- ],
283
- Quiet: true
275
+
276
+ if ( config.s3.logs === 'outputs' || config.s3.logs === 'verbose' ){
277
+ if ( sourceBucket === destinationBucket ){
278
+ log ( `S3 [COPY]: ${sourceKey} moved to ${destinationKey} on ${sourceBucket}.` );
284
279
  }
285
- } );
280
+ else {
281
+ log ( `S3 [COPY]: ${sourceKey} on ${sourceBucket} moved to ${destinationKey} on ${destinationBucket}.` );
282
+ }
283
+ }
284
+ }
285
+ catch ( error ) {
286
+ throw error;
287
+ }
288
+ };
289
+
290
+ /**
291
+ * Move an object within S3 to a different location. (This deletes the original like a CUT / PASTE operation)
292
+ *
293
+ * @param {string} sourceKey - The source object key.
294
+ * @param {string} destinationKey - The destination object key.
295
+ * @param {string} [sourceBucket=config.s3.Bucket] - The source bucket name. Defaults to the configured bucket.
296
+ * @param {string} [destinationBucket=config.s3.Bucket] - The destination bucket name. Defaults to the configured bucket.
297
+ * @returns {Promise} A promise that resolves when the object is successfully moved in S3.
298
+ * @description Moves an object from the source location to the destination location within S3.
299
+ */
300
+ exports.move = async ( sourceKey, destinationKey, sourceBucket = config.s3.Bucket, destinationBucket = config.s3.Bucket ) => {
301
+ try {
302
+
303
+ // Copy the object to the destination location
304
+ await this.copy ( sourceKey, destinationKey, sourceBucket, destinationBucket );
286
305
 
287
- await S3.send ( deleteCommand );
306
+ // Delete the object from the source location
307
+ await this.del ( sourceKey, sourceBucket );
288
308
 
289
309
  if ( config.s3.logs === 'outputs' || config.s3.logs === 'verbose' ){
290
310
  if ( sourceBucket === destinationBucket ){