mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-28 23:03:35 -05:00
Merge pull request #11179 from overleaf/em-upgrade-gcs-lib
Upgrade @google-cloud/storage library to 6.9.0 GitOrigin-RevId: 0e80dcccca4679ffe28d5b16512a691e58694e2b
This commit is contained in:
parent
f97a543d41
commit
4325f1d947
6 changed files with 285 additions and 1210 deletions
|
@ -22,7 +22,7 @@
|
||||||
"@overleaf/logger": "*"
|
"@overleaf/logger": "*"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@google-cloud/storage": "~5.1.2",
|
"@google-cloud/storage": "^6.9.0",
|
||||||
"@overleaf/o-error": "*",
|
"@overleaf/o-error": "*",
|
||||||
"aws-sdk": "^2.718.0",
|
"aws-sdk": "^2.718.0",
|
||||||
"fast-crc32c": "https://github.com/overleaf/node-fast-crc32c/archive/aae6b2a4c7a7a159395df9cc6c38dfde702d6f51.tar.gz",
|
"fast-crc32c": "https://github.com/overleaf/node-fast-crc32c/archive/aae6b2a4c7a7a159395df9cc6c38dfde702d6f51.tar.gz",
|
||||||
|
|
|
@ -213,7 +213,8 @@ module.exports = class GcsPersistor extends AbstractPersistor {
|
||||||
}
|
}
|
||||||
|
|
||||||
async deleteDirectory(bucketName, key) {
|
async deleteDirectory(bucketName, key) {
|
||||||
let query = { directory: key, autoPaginate: false }
|
const prefix = ensurePrefixIsDirectory(key)
|
||||||
|
let query = { prefix, autoPaginate: false }
|
||||||
do {
|
do {
|
||||||
try {
|
try {
|
||||||
const [files, nextQuery] = await this.storage
|
const [files, nextQuery] = await this.storage
|
||||||
|
@ -247,11 +248,12 @@ module.exports = class GcsPersistor extends AbstractPersistor {
|
||||||
|
|
||||||
async directorySize(bucketName, key) {
|
async directorySize(bucketName, key) {
|
||||||
let files
|
let files
|
||||||
|
const prefix = ensurePrefixIsDirectory(key)
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const [response] = await this.storage
|
const [response] = await this.storage
|
||||||
.bucket(bucketName)
|
.bucket(bucketName)
|
||||||
.getFiles({ directory: key })
|
.getFiles({ prefix })
|
||||||
files = response
|
files = response
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
throw PersistorHelper.wrapError(
|
throw PersistorHelper.wrapError(
|
||||||
|
@ -301,3 +303,7 @@ module.exports = class GcsPersistor extends AbstractPersistor {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function ensurePrefixIsDirectory(key) {
|
||||||
|
return key === '' || key.endsWith('/') ? key : `${key}/`
|
||||||
|
}
|
||||||
|
|
|
@ -554,12 +554,13 @@ describe('GcsPersistorTests', function () {
|
||||||
|
|
||||||
describe('deleteDirectory', function () {
|
describe('deleteDirectory', function () {
|
||||||
const directoryName = `${ObjectId()}/${ObjectId()}`
|
const directoryName = `${ObjectId()}/${ObjectId()}`
|
||||||
|
const directoryPrefix = `${directoryName}/`
|
||||||
describe('with valid parameters', function () {
|
describe('with valid parameters', function () {
|
||||||
beforeEach(async function () {
|
beforeEach(async function () {
|
||||||
GcsBucket.getFiles = sinon.stub()
|
GcsBucket.getFiles = sinon.stub()
|
||||||
// set up multiple paginated calls to getFiles
|
// set up multiple paginated calls to getFiles
|
||||||
GcsBucket.getFiles
|
GcsBucket.getFiles
|
||||||
.withArgs({ directory: directoryName, autoPaginate: false })
|
.withArgs({ prefix: directoryPrefix, autoPaginate: false })
|
||||||
.resolves([['aaa', 'bbb'], 'call-1'])
|
.resolves([['aaa', 'bbb'], 'call-1'])
|
||||||
GcsBucket.getFiles
|
GcsBucket.getFiles
|
||||||
.withArgs('call-1')
|
.withArgs('call-1')
|
||||||
|
@ -571,7 +572,7 @@ describe('GcsPersistorTests', function () {
|
||||||
it('should list the objects in the directory', function () {
|
it('should list the objects in the directory', function () {
|
||||||
expect(Storage.prototype.bucket).to.have.been.calledWith(bucket)
|
expect(Storage.prototype.bucket).to.have.been.calledWith(bucket)
|
||||||
expect(GcsBucket.getFiles).to.have.been.calledWith({
|
expect(GcsBucket.getFiles).to.have.been.calledWith({
|
||||||
directory: directoryName,
|
prefix: directoryPrefix,
|
||||||
autoPaginate: false,
|
autoPaginate: false,
|
||||||
})
|
})
|
||||||
expect(GcsBucket.getFiles).to.have.been.calledWith('call-1')
|
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 () {
|
it('should list the objects in the directory', function () {
|
||||||
expect(Storage.prototype.bucket).to.have.been.calledWith(bucket)
|
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 () {
|
it('should return the directory size', function () {
|
||||||
|
@ -633,7 +636,9 @@ describe('GcsPersistorTests', function () {
|
||||||
|
|
||||||
it('should list the objects in the directory', function () {
|
it('should list the objects in the directory', function () {
|
||||||
expect(Storage.prototype.bucket).to.have.been.calledWith(bucket)
|
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 () {
|
it('should return zero', function () {
|
||||||
|
|
1468
package-lock.json
generated
1468
package-lock.json
generated
File diff suppressed because it is too large
Load diff
|
@ -34,7 +34,7 @@
|
||||||
"streamifier": "^0.1.1"
|
"streamifier": "^0.1.1"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@google-cloud/storage": "^5.1.2",
|
"@google-cloud/storage": "^6.9.0",
|
||||||
"chai": "^4.3.6",
|
"chai": "^4.3.6",
|
||||||
"chai-as-promised": "^7.1.1",
|
"chai-as-promised": "^7.1.1",
|
||||||
"mocha": "^10.2.0",
|
"mocha": "^10.2.0",
|
||||||
|
|
|
@ -35,7 +35,7 @@
|
||||||
"tiny-async-pool": "^1.1.0"
|
"tiny-async-pool": "^1.1.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@google-cloud/storage": "^5.1.2",
|
"@google-cloud/storage": "^6.9.0",
|
||||||
"aws-sdk": "^2.718.0",
|
"aws-sdk": "^2.718.0",
|
||||||
"chai": "^4.3.6",
|
"chai": "^4.3.6",
|
||||||
"chai-as-promised": "^7.1.1",
|
"chai-as-promised": "^7.1.1",
|
||||||
|
|
Loading…
Reference in a new issue