@pittica/google-cloud-storage-helpers 1.2.0 → 1.2.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/LICENSE CHANGED
@@ -186,7 +186,7 @@ Apache License
186
186
  same "printed page" as the copyright notice for easier
187
187
  identification within third-party archives.
188
188
 
189
- Copyright 2024 Pittica S.r.l.
189
+ Copyright 2024-2025 Pittica S.r.l.
190
190
 
191
191
  Licensed under the Apache License, Version 2.0 (the "License");
192
192
  you may not use this file except in compliance with the License.
@@ -16,6 +16,9 @@ const {
16
16
  Storage
17
17
  } = require("@google-cloud/storage");
18
18
  const log = require("@pittica/logger-helpers");
19
+ const {
20
+ getStorage
21
+ } = require("./storage");
19
22
 
20
23
  /**
21
24
  * Moves all files from a bucket to another.
@@ -24,21 +27,26 @@ const log = require("@pittica/logger-helpers");
24
27
  * @param {string} destination Destination bucket.
25
28
  */
26
29
  exports.moveFiles = async (source, destination) => {
27
- const storage = new Storage({
28
- retryOptions: {
29
- autoRetry: true,
30
- retryDelayMultiplier: 4
31
- }
32
- });
30
+ const storage = getStorage();
33
31
  const bucket = storage.bucket(destination);
34
32
  const [files] = await storage.bucket(source).getFiles();
35
- files.forEach(results => results.forEach(file => {
36
- const {
37
- id
38
- } = file;
39
- log.info(`Moving "${id}" from "${source}" to "${destination}"`);
40
- file.copy(bucket.file(id)).then(() => this.deleteFile(file) ? log.success(`Moved "${id}" from "${source}" to "${destination}"`) : log.error(`Failed deleted "${id}" in "${source}"`)).catch(() => log.error(`Failed moving "${id}" from "${source}" to "${destination}"`));
41
- }));
33
+ files.forEach(results => Array.isArray(results) ? results.forEach(file => this.moveFile(file, bucket)) : this.moveFile(results, bucket));
34
+ };
35
+
36
+ /**
37
+ * Moves a file from a bucket to another.
38
+ *
39
+ * @param {File} file File object.
40
+ * @param {Bucket} bucket Bucket object.
41
+ */
42
+ exports.moveFile = async (file, bucket) => {
43
+ const {
44
+ id
45
+ } = file;
46
+ const source = file.metadata.bucket;
47
+ const destination = bucket.id;
48
+ log.info(`Moving "${id}" from "${source}" to "${destination}"`);
49
+ file.copy(bucket.file(id)).then(() => this.deleteFile(file) ? log.success(`Moved "${id}" from "${source}" to "${destination}"`) : log.error(`Failed deleted "${id}" in "${source}"`)).catch(() => log.error(`Failed moving "${id}" from "${source}" to "${destination}"`));
42
50
  };
43
51
 
44
52
  /**
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@pittica/google-cloud-storage-helpers",
3
3
  "private": false,
4
- "version": "1.2.0",
4
+ "version": "1.2.2",
5
5
  "description": "Helpers for Google Cloud Storage.",
6
6
  "main": "dist/index.js",
7
7
  "scripts": {
@@ -26,11 +26,11 @@
26
26
  },
27
27
  "homepage": "https://github.com/pittica/google-cloud-storage-helpers#README.md",
28
28
  "dependencies": {
29
- "@google-cloud/storage": "^7.15.2",
29
+ "@google-cloud/storage": "^7.16.0",
30
30
  "@pittica/logger-helpers": "^0.9.0"
31
31
  },
32
32
  "devDependencies": {
33
- "@babel/cli": "^7.26.4",
33
+ "@babel/cli": "^7.27.0",
34
34
  "mkdirp": "^3.0.1",
35
35
  "prettier": "^3.5.3",
36
36
  "rimraf": "^6.0.1",