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] Importers no longer working due to the FileUpload changes #9850

Merged
merged 3 commits into from
Feb 26, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 1 addition & 1 deletion packages/rocketchat-file-upload/globalFileRestrictions.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const slingShotConfig = {

const maxFileSize = RocketChat.settings.get('FileUpload_MaxFileSize');

if (maxFileSize && maxFileSize < file.size) {
if (maxFileSize >= -1 && maxFileSize < file.size) {
throw new Meteor.Error(TAPi18n.__('File_exceeds_allowed_size_of_bytes', { size: filesize(maxFileSize) }));
}

Expand Down
11 changes: 8 additions & 3 deletions packages/rocketchat-file-upload/lib/FileUpload.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,15 @@ FileUpload = {
throw new Meteor.Error('error-direct-message-file-upload-not-allowed', reason);
}

if (file.size > maxFileSize) {
// -1 maxFileSize means there is no limit
if (maxFileSize >= -1 && file.size > maxFileSize) {
const reason = TAPi18n.__('File_exceeds_allowed_size_of_bytes', {
size: filesize(maxFileSize)
}, user.language);
throw new Meteor.Error('error-file-too-large', reason);
}

if (parseInt(maxFileSize) > 0) {
if (maxFileSize > 0) {
if (file.size > maxFileSize) {
const reason = TAPi18n.__('File_exceeds_allowed_size_of_bytes', {
size: filesize(maxFileSize)
Expand All @@ -56,5 +57,9 @@ FileUpload = {
};

RocketChat.settings.get('FileUpload_MaxFileSize', function(key, value) {
maxFileSize = value;
try {
maxFileSize = parseInt(value);
} catch (e) {
maxFileSize = 2097152; // the default value
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there anyway to maybe fetch that? Do we want to have this value hard coded here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This value is returned when the setting is updated. Should they manage to set an invalid integer as the value of that setting (which shouldn't happen in theory) then this is a fail safe and thus I believe hard coded is just fine.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, I understand when it's returned. My question is instead of hard coding would it be possible to grab the settings default value? Another words grab from the other place it's hard coded so we don't have it a second place.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure we can, I'm just not sure the best way of doing it. Recommendations?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no idea 😛 so I guess proceed 😄

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@graywolf336 You can do RocketChat.models.Settings.findOneById('FileUpload_MaxFileSize').packageValue

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah derp, I completely forgot about that.

}
});
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ export class Base {
RocketChat.models.Settings.updateValueById('Accounts_AllowUsernameChange', true);

this.oldSettings.FileUpload_MaxFileSize = RocketChat.models.Settings.findOneById('FileUpload_MaxFileSize').value;
RocketChat.models.Settings.updateValueById('FileUpload_MaxFileSize', 0);
RocketChat.models.Settings.updateValueById('FileUpload_MaxFileSize', -1);
break;
case ProgressStep.DONE:
case ProgressStep.ERROR:
Expand Down