[FIX] File had redirect delay when using external storage services and no option to proxy only avatars

pull/10272/head
Rodrigo Nascimento 8 years ago
parent 2e5d1877f0
commit dd092f9e18
No known key found for this signature in database
GPG Key ID: CFCE33B7B01AC335
  1. 17
      package-lock.json
  2. 4
      packages/rocketchat-file-upload/server/config/AmazonS3.js
  3. 4
      packages/rocketchat-file-upload/server/config/GoogleStorage.js
  4. 18
      packages/rocketchat-file-upload/server/startup/settings.js
  5. 14
      packages/rocketchat-i18n/i18n/en.i18n.json
  6. 16
      server/startup/migrations/v109.js

17
package-lock.json generated

@ -1680,7 +1680,7 @@
"bcrypt": {
"version": "1.0.3",
"resolved": "https://registry.npmjs.org/bcrypt/-/bcrypt-1.0.3.tgz",
"integrity": "sha1-sC3cbAtS6ha40883XVoy54DatUg=",
"integrity": "sha512-pRyDdo73C8Nim3jwFJ7DWe3TZCgwDfWZ6nHS5LSdU77kWbj1frruvdndP02AOavtD4y8v6Fp2dolbHgp4SDrfg==",
"requires": {
"nan": "2.6.2",
"node-pre-gyp": "0.6.36"
@ -3599,6 +3599,7 @@
"version": "0.1.6",
"resolved": "https://registry.npmjs.org/errno/-/errno-0.1.6.tgz",
"integrity": "sha512-IsORQDpaaSwcDP4ZZnHxgE85werpo34VYn1Ud3mq+eUsF593faR8oCZNXrROVkpFu2TsbrNhHin0aUrTsQ9vNw==",
"optional": true,
"requires": {
"prr": "1.0.1"
}
@ -5420,7 +5421,7 @@
"glob": {
"version": "7.1.2",
"resolved": "https://registry.npmjs.org/glob/-/glob-7.1.2.tgz",
"integrity": "sha1-wZyd+aAocC1nhhI4SmVSQExjbRU=",
"integrity": "sha512-MJTUg1kjuLeQCJ+ccE4Vpa6kKVXkPYJ2mOCQyUuKLcLQsdrMCpBPUi8qVE6+YuaJkozeA9NusTAw3hLr8Xe5EQ==",
"requires": {
"fs.realpath": "1.0.0",
"inflight": "1.0.6",
@ -8276,7 +8277,7 @@
"minimatch": {
"version": "3.0.4",
"resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.0.4.tgz",
"integrity": "sha1-UWbihkV/AzBgZL5Ul+jbsMPTIIM=",
"integrity": "sha512-yJHVQEhyqPLUTgt9B83PXu6W3rx4MvvHvSUvToogpwoGDOUQ+yDrR0HRot+yOCdCO7u4hX3pWft6kWBBcqh0UA==",
"requires": {
"brace-expansion": "1.1.11"
}
@ -8529,7 +8530,8 @@
"natives": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/natives/-/natives-1.1.1.tgz",
"integrity": "sha512-8eRaxn8u/4wN8tGkhlc2cgwwvOLMLUMUn4IYTexMgWd+LyUDfeXVkk2ygQR0hvIHbJQXgHujia3ieUUDwNGkEA=="
"integrity": "sha512-8eRaxn8u/4wN8tGkhlc2cgwwvOLMLUMUn4IYTexMgWd+LyUDfeXVkk2ygQR0hvIHbJQXgHujia3ieUUDwNGkEA==",
"optional": true
},
"natural-compare": {
"version": "1.4.0",
@ -8649,7 +8651,7 @@
"npmlog": {
"version": "4.1.2",
"resolved": "https://registry.npmjs.org/npmlog/-/npmlog-4.1.2.tgz",
"integrity": "sha1-CKfyqL9zRgR3mp76StXMcXq7lUs=",
"integrity": "sha512-2uUqazuKlTaSI/dC8AzicUck7+IrEaOnN/e0jd3Xtt1KcGpwx30v50mL7oPyr/h9bL3E4aZccVwpwP+5W9Vjkg==",
"requires": {
"are-we-there-yet": "1.1.4",
"console-control-strings": "1.1.0",
@ -10108,7 +10110,8 @@
"prr": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/prr/-/prr-1.0.1.tgz",
"integrity": "sha1-0/wRS6BplaRexok/SEzrHXj19HY="
"integrity": "sha1-0/wRS6BplaRexok/SEzrHXj19HY=",
"optional": true
},
"pump": {
"version": "2.0.1",
@ -13080,7 +13083,7 @@
"wide-align": {
"version": "1.1.2",
"resolved": "https://registry.npmjs.org/wide-align/-/wide-align-1.1.2.tgz",
"integrity": "sha1-Vx4PGwYEY268DfwhsDObvjE0FxA=",
"integrity": "sha512-ijDLlyQ7s6x1JgCLur53osjm/UXUYD9+0PbYKrBsYisYXzCxN+HC3mYDNy/dWdmf3AwqwU3CXwDCvsNgGK1S0w==",
"requires": {
"string-width": "1.0.2"
}

@ -10,10 +10,12 @@ const get = function(file, req, res) {
const fileUrl = this.store.getRedirectURL(file);
if (fileUrl) {
if (RocketChat.settings.get('FileUpload_S3_Proxy')) {
const storeType = file.store.split(':').pop();
if (RocketChat.settings.get(`FileUpload_S3_Proxy_${ storeType }`)) {
const request = /^https:/.test(fileUrl) ? https : http;
request.get(fileUrl, fileRes => fileRes.pipe(res));
} else {
res.removeHeader('Content-Length');
res.setHeader('Location', fileUrl);
res.writeHead(302);
res.end();

@ -13,10 +13,12 @@ const get = function(file, req, res) {
}
if (fileUrl) {
if (RocketChat.settings.get('FileUpload_GoogleStorage_Proxy')) {
const storeType = file.store.split(':').pop();
if (RocketChat.settings.get(`FileUpload_GoogleStorage_Proxy_${ storeType }`)) {
const request = /^https:/.test(fileUrl) ? https : http;
request.get(fileUrl, fileRes => fileRes.pipe(res));
} else {
res.removeHeader('Content-Length');
res.setHeader('Location', fileUrl);
res.writeHead(302);
res.end();

@ -112,7 +112,14 @@ RocketChat.settings.addGroup('FileUpload', function() {
},
i18nDescription: 'FileUpload_S3_URLExpiryTimeSpan_Description'
});
this.add('FileUpload_S3_Proxy', false, {
this.add('FileUpload_S3_Proxy_Avatars', false, {
type: 'boolean',
enableQuery: {
_id: 'FileUpload_Storage_Type',
value: 'AmazonS3'
}
});
this.add('FileUpload_S3_Proxy_Uploads', false, {
type: 'boolean',
enableQuery: {
_id: 'FileUpload_Storage_Type',
@ -147,7 +154,14 @@ RocketChat.settings.addGroup('FileUpload', function() {
value: 'GoogleCloudStorage'
}
});
this.add('FileUpload_GoogleStorage_Proxy', false, {
this.add('FileUpload_GoogleStorage_Proxy_Avatars', false, {
type: 'boolean',
enableQuery: {
_id: 'FileUpload_Storage_Type',
value: 'GoogleCloudStorage'
}
});
this.add('FileUpload_GoogleStorage_Proxy_Uploads', false, {
type: 'boolean',
enableQuery: {
_id: 'FileUpload_Storage_Type',

@ -741,8 +741,10 @@
"FileUpload_GoogleStorage_AccessId_Description": "The Access Id is generally in an email format, for example: \"example-test@example.iam.gserviceaccount.com\"",
"FileUpload_GoogleStorage_Bucket": "Google Storage Bucket Name",
"FileUpload_GoogleStorage_Bucket_Description": "The name of the bucket which the files should be uploaded to.",
"FileUpload_GoogleStorage_Proxy": "Proxy",
"FileUpload_GoogleStorage_Proxy_Description": "Proxy all file transmissions through your server instead of direct access to the asset's URL",
"FileUpload_GoogleStorage_Proxy_Avatars": "Proxy Avatars",
"FileUpload_GoogleStorage_Proxy_Avatars_Description": "Proxy avatar file transmissions through your server instead of direct access to the asset's URL",
"FileUpload_GoogleStorage_Proxy_Uploads": "Proxy Uploads",
"FileUpload_GoogleStorage_Proxy_Uploads_Description": "Proxy upload file transmissions through your server instead of direct access to the asset's URL",
"FileUpload_GoogleStorage_Secret": "Google Storage Secret",
"FileUpload_GoogleStorage_Secret_Description": "Please follow <a href=\"https://github.com/CulturalMe/meteor-slingshot#google-cloud\">these instructions</a> and paste the result here.",
"FileUpload_MaxFileSize": "Maximum File Upload Size (in bytes)",
@ -758,8 +760,10 @@
"FileUpload_S3_BucketURL": "Bucket URL",
"FileUpload_S3_CDN": "CDN Domain for Downloads",
"FileUpload_S3_ForcePathStyle": "Force Path Style",
"FileUpload_S3_Proxy": "Proxy",
"FileUpload_S3_Proxy_Description": "Proxy all file transmissions through your server instead of direct access to the asset's URL",
"FileUpload_S3_Proxy_Avatars": "Proxy Avatars",
"FileUpload_S3_Proxy_Avatars_Description": "Proxy avatar file transmissions through your server instead of direct access to the asset's URL",
"FileUpload_S3_Proxy_Uploads": "Proxy Uploads",
"FileUpload_S3_Proxy_Uploads_Description": "Proxy upload file transmissions through your server instead of direct access to the asset's URL",
"FileUpload_S3_Region": "Region",
"FileUpload_S3_SignatureVersion": "Signature Version",
"FileUpload_S3_URLExpiryTimeSpan": "URLs Expiration Timespan",
@ -2242,4 +2246,4 @@
"your_message_optional": "your message (optional)",
"Your_password_is_wrong": "Your password is wrong!",
"Your_push_was_sent_to_s_devices": "Your push was sent to %s devices"
}
}

@ -0,0 +1,16 @@
RocketChat.Migrations.add({
version: 109,
up() {
const FileUpload_GoogleStorage_Proxy = (RocketChat.models.Settings.findOne({_id: 'FileUpload_GoogleStorage_Proxy'}) || {}).value === true;
const FileUpload_S3_Proxy = (RocketChat.models.Settings.findOne({_id: 'FileUpload_S3_Proxy'}) || {}).value === true;
RocketChat.models.Settings.update({_id: 'FileUpload_GoogleStorage_Proxy_Avatars'}, {$set: {value: FileUpload_GoogleStorage_Proxy}});
RocketChat.models.Settings.update({_id: 'FileUpload_GoogleStorage_Proxy_Uploads'}, {$set: {value: FileUpload_GoogleStorage_Proxy}});
RocketChat.models.Settings.update({_id: 'FileUpload_S3_Proxy_Avatars'}, {$set: {value: FileUpload_S3_Proxy}});
RocketChat.models.Settings.update({_id: 'FileUpload_S3_Proxy_Uploads'}, {$set: {value: FileUpload_S3_Proxy}});
RocketChat.models.Settings.remove({_id: 'FileUpload_GoogleStorage_Proxy'});
RocketChat.models.Settings.remove({_id: 'FileUpload_S3_Proxy'});
}
});
Loading…
Cancel
Save