Merge pull request #13274 from overleaf/csh-issue-13004-cleanup-custom-code

Remove apiScheme from GCS

GitOrigin-RevId: c948287cb00c7bc432c797bfdfa92a79b84d1bed
This commit is contained in:
Christopher Hoskin
2023-06-02 08:05:10 +00:00
committed by Copybot
parent 9ddc27d919
commit 5fbd5e21a2
15 changed files with 11 additions and 41 deletions
+2 -18
View File
@@ -16,21 +16,6 @@ module.exports = class GcsPersistor extends AbstractPersistor {
// endpoint settings will be null by default except for tests
// that's OK - GCS uses the locally-configured service account by default
this.storage = new Storage(this.settings.endpoint)
// workaround for broken uploads with custom endpoints:
// https://github.com/googleapis/nodejs-storage/issues/898
if (this.settings.endpoint && this.settings.endpoint.apiEndpoint) {
this.storage.interceptors.push({
request: reqOpts => {
const url = new URL(reqOpts.uri)
url.host = this.settings.endpoint.apiEndpoint
if (this.settings.endpoint.apiScheme) {
url.protocol = this.settings.endpoint.apiScheme
}
reqOpts.uri = url.toString()
return reqOpts
},
})
}
}
async sendFile(bucketName, key, fsPath) {
@@ -142,10 +127,9 @@ module.exports = class GcsPersistor extends AbstractPersistor {
if (this.settings.unsignedUrls) {
// Construct a direct URL to the object download endpoint
// (see https://cloud.google.com/storage/docs/request-endpoints#json-api)
const apiScheme = this.settings.endpoint.apiScheme || 'https://'
const apiEndpoint =
this.settings.endpoint.apiEndpoint || 'storage.googleapis.com'
return `${apiScheme}://${apiEndpoint}/download/storage/v1/b/${bucketName}/o/${key}?alt=media`
this.settings.endpoint.apiEndpoint || 'https://storage.googleapis.com'
return `${apiEndpoint}/download/storage/v1/b/${bucketName}/o/${key}?alt=media`
}
try {
const [url] = await this.storage