Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 2 commits into from
Mar 30, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion packages/rocketchat-file-upload/server/config/AmazonS3.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
18 changes: 16 additions & 2 deletions packages/rocketchat-file-upload/server/startup/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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',
Expand Down
14 changes: 9 additions & 5 deletions packages/rocketchat-i18n/i18n/en.i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -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)",
Expand All @@ -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",
Expand Down Expand Up @@ -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"
}
}
16 changes: 16 additions & 0 deletions server/startup/migrations/v109.js
Original file line number Diff line number Diff line change
@@ -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'});
}
});