Эх сурвалжийг харах

Merge pull request #11179 from overleaf/em-upgrade-gcs-lib

Upgrade @google-cloud/storage library to 6.9.0

GitOrigin-RevId: 0e80dcccca4679ffe28d5b16512a691e58694e2b
Eric Mc Sween 3 жил өмнө
parent
commit
4325f1d947

+ 1 - 1
libraries/object-persistor/package.json

@@ -22,7 +22,7 @@
     "@overleaf/logger": "*"
   },
   "dependencies": {
-    "@google-cloud/storage": "~5.1.2",
+    "@google-cloud/storage": "^6.9.0",
     "@overleaf/o-error": "*",
     "aws-sdk": "^2.718.0",
     "fast-crc32c": "https://github.com/overleaf/node-fast-crc32c/archive/aae6b2a4c7a7a159395df9cc6c38dfde702d6f51.tar.gz",

+ 8 - 2
libraries/object-persistor/src/GcsPersistor.js

@@ -213,7 +213,8 @@ module.exports = class GcsPersistor extends AbstractPersistor {
   }
 
   async deleteDirectory(bucketName, key) {
-    let query = { directory: key, autoPaginate: false }
+    const prefix = ensurePrefixIsDirectory(key)
+    let query = { prefix, autoPaginate: false }
     do {
       try {
         const [files, nextQuery] = await this.storage
@@ -247,11 +248,12 @@ module.exports = class GcsPersistor extends AbstractPersistor {
 
   async directorySize(bucketName, key) {
     let files
+    const prefix = ensurePrefixIsDirectory(key)
 
     try {
       const [response] = await this.storage
         .bucket(bucketName)
-        .getFiles({ directory: key })
+        .getFiles({ prefix })
       files = response
     } catch (err) {
       throw PersistorHelper.wrapError(
@@ -301,3 +303,7 @@ module.exports = class GcsPersistor extends AbstractPersistor {
     }
   }
 }
+
+function ensurePrefixIsDirectory(key) {
+  return key === '' || key.endsWith('/') ? key : `${key}/`
+}

+ 9 - 4
libraries/object-persistor/test/unit/GcsPersistorTests.js

@@ -554,12 +554,13 @@ describe('GcsPersistorTests', function () {
 
   describe('deleteDirectory', function () {
     const directoryName = `${ObjectId()}/${ObjectId()}`
+    const directoryPrefix = `${directoryName}/`
     describe('with valid parameters', function () {
       beforeEach(async function () {
         GcsBucket.getFiles = sinon.stub()
         // set up multiple paginated calls to getFiles
         GcsBucket.getFiles
-          .withArgs({ directory: directoryName, autoPaginate: false })
+          .withArgs({ prefix: directoryPrefix, autoPaginate: false })
           .resolves([['aaa', 'bbb'], 'call-1'])
         GcsBucket.getFiles
           .withArgs('call-1')
@@ -571,7 +572,7 @@ describe('GcsPersistorTests', function () {
       it('should list the objects in the directory', function () {
         expect(Storage.prototype.bucket).to.have.been.calledWith(bucket)
         expect(GcsBucket.getFiles).to.have.been.calledWith({
-          directory: directoryName,
+          prefix: directoryPrefix,
           autoPaginate: false,
         })
         expect(GcsBucket.getFiles).to.have.been.calledWith('call-1')
@@ -615,7 +616,9 @@ describe('GcsPersistorTests', function () {
 
       it('should list the objects in the directory', function () {
         expect(Storage.prototype.bucket).to.have.been.calledWith(bucket)
-        expect(GcsBucket.getFiles).to.have.been.calledWith({ directory: key })
+        expect(GcsBucket.getFiles).to.have.been.calledWith({
+          prefix: `${key}/`,
+        })
       })
 
       it('should return the directory size', function () {
@@ -633,7 +636,9 @@ describe('GcsPersistorTests', function () {
 
       it('should list the objects in the directory', function () {
         expect(Storage.prototype.bucket).to.have.been.calledWith(bucket)
-        expect(GcsBucket.getFiles).to.have.been.calledWith({ directory: key })
+        expect(GcsBucket.getFiles).to.have.been.calledWith({
+          prefix: `${key}/`,
+        })
       })
 
       it('should return zero', function () {

Файлын зөрүү хэтэрхий том тул дарагдсан байна
+ 136 - 565
package-lock.json


+ 1 - 1
services/docstore/package.json

@@ -34,7 +34,7 @@
     "streamifier": "^0.1.1"
   },
   "devDependencies": {
-    "@google-cloud/storage": "^5.1.2",
+    "@google-cloud/storage": "^6.9.0",
     "chai": "^4.3.6",
     "chai-as-promised": "^7.1.1",
     "mocha": "^10.2.0",

+ 1 - 1
services/filestore/package.json

@@ -35,7 +35,7 @@
     "tiny-async-pool": "^1.1.0"
   },
   "devDependencies": {
-    "@google-cloud/storage": "^5.1.2",
+    "@google-cloud/storage": "^6.9.0",
     "aws-sdk": "^2.718.0",
     "chai": "^4.3.6",
     "chai-as-promised": "^7.1.1",

Энэ ялгаанд хэт олон файл өөрчлөгдсөн тул зарим файлыг харуулаагүй болно