mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -05:00
Implement getRedirectUrl() for the S3 backend
This commit is contained in:
parent
7abea41166
commit
3e7e4369af
4 changed files with 39 additions and 7 deletions
|
@ -96,8 +96,6 @@ A `string` containing the signed link, or `null` if a link cannot be generated.
|
||||||
|
|
||||||
In the case of `null`, you should fall back to `getObjectStream` as sometimes signed links cannot be generated.
|
In the case of `null`, you should fall back to `getObjectStream` as sometimes signed links cannot be generated.
|
||||||
|
|
||||||
Signed links are currently only supported on the `gcs` backend.
|
|
||||||
|
|
||||||
Do not use this method if you are using a secondary persistor, as this mechanism does not check to see if the object actually exists - so cannot provide a fallback.
|
Do not use this method if you are using a secondary persistor, as this mechanism does not check to see if the object actually exists - so cannot provide a fallback.
|
||||||
|
|
||||||
#### getObjectSize
|
#### getObjectSize
|
||||||
|
|
|
@ -114,9 +114,25 @@ module.exports = class S3Persistor extends AbstractPersistor {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async getRedirectUrl() {
|
async getRedirectUrl(bucketName, key) {
|
||||||
// not implemented
|
const expiresSeconds = Math.round(this.settings.signedUrlExpiryInMs / 1000)
|
||||||
return null
|
try {
|
||||||
|
const url = await this._getClientForBucket(
|
||||||
|
bucketName
|
||||||
|
).getSignedUrlPromise('getObject', {
|
||||||
|
Bucket: bucketName,
|
||||||
|
Key: key,
|
||||||
|
Expires: expiresSeconds
|
||||||
|
})
|
||||||
|
return url
|
||||||
|
} catch (err) {
|
||||||
|
throw PersistorHelper.wrapError(
|
||||||
|
err,
|
||||||
|
'error generating signed url for S3 file',
|
||||||
|
{ bucketName, key },
|
||||||
|
ReadError
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async deleteDirectory(bucketName, key, continuationToken) {
|
async deleteDirectory(bucketName, key, continuationToken) {
|
||||||
|
|
|
@ -250,7 +250,7 @@ describe('GcsPersistorTests', function () {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('getFile', function () {
|
describe('getRedirectUrl', function () {
|
||||||
let signedUrl
|
let signedUrl
|
||||||
|
|
||||||
beforeEach(async function () {
|
beforeEach(async function () {
|
||||||
|
|
|
@ -27,6 +27,7 @@ describe('S3PersistorTests', function () {
|
||||||
]
|
]
|
||||||
const filesSize = 33
|
const filesSize = 33
|
||||||
const md5 = 'ffffffff00000000ffffffff00000000'
|
const md5 = 'ffffffff00000000ffffffff00000000'
|
||||||
|
const redirectUrl = 'https://wombat.potato/giraffe'
|
||||||
|
|
||||||
let Logger,
|
let Logger,
|
||||||
Transform,
|
Transform,
|
||||||
|
@ -126,7 +127,8 @@ describe('S3PersistorTests', function () {
|
||||||
.returns({ promise: sinon.stub().resolves({ ETag: `"${md5}"` }) }),
|
.returns({ promise: sinon.stub().resolves({ ETag: `"${md5}"` }) }),
|
||||||
copyObject: sinon.stub().returns(EmptyPromise),
|
copyObject: sinon.stub().returns(EmptyPromise),
|
||||||
deleteObject: sinon.stub().returns(EmptyPromise),
|
deleteObject: sinon.stub().returns(EmptyPromise),
|
||||||
deleteObjects: sinon.stub().returns(EmptyPromise)
|
deleteObjects: sinon.stub().returns(EmptyPromise),
|
||||||
|
getSignedUrlPromise: sinon.stub().resolves(redirectUrl)
|
||||||
}
|
}
|
||||||
S3 = sinon.stub().returns(S3Client)
|
S3 = sinon.stub().returns(S3Client)
|
||||||
|
|
||||||
|
@ -354,6 +356,22 @@ describe('S3PersistorTests', function () {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
describe('getRedirectUrl', function () {
|
||||||
|
let signedUrl
|
||||||
|
|
||||||
|
beforeEach(async function () {
|
||||||
|
signedUrl = await S3Persistor.getRedirectUrl(bucket, key)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('should request a signed URL', function () {
|
||||||
|
expect(S3Client.getSignedUrlPromise).to.have.been.called
|
||||||
|
})
|
||||||
|
|
||||||
|
it('should return the url', function () {
|
||||||
|
expect(signedUrl).to.equal(redirectUrl)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
describe('getObjectSize', function () {
|
describe('getObjectSize', function () {
|
||||||
describe('when called with valid parameters', function () {
|
describe('when called with valid parameters', function () {
|
||||||
let size
|
let size
|
||||||
|
|
Loading…
Reference in a new issue