Skip to content
This repository was archived by the owner on May 22, 2021. It is now read-only.

Show Warning, Cancel and Redirect on size > 2GB ; fixes #578 #695

Merged
merged 1 commit into from
Jan 9, 2018

Conversation

shikhar-scs
Copy link
Contributor

@shikhar-scs shikhar-scs commented Jan 3, 2018

As mentioned by @SoftVision-CosminMuntean and @johngruen at #578, this PR resolves issues related to file uploads of sizes > 2GB. It displays the warning message, cancels the upload and further redirects back to the home page.

The following preview has been generated for file sizes > 200MB as my laptop crashes for any file having size > 1 GB. However, this limit can be very easily altered as per our needs.

Here is the preview (its a gif file so please be patient while it loads)

filesize

@dannycoates @SoftVision-CosminMuntean @johngruen Please review and suggest changes.

Copy link
Contributor

@dannycoates dannycoates left a comment

Choose a reason for hiding this comment

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

A better location to check the file size is in welcome.js. We can simply show an alert return early from that function.

@shikhar-scs
Copy link
Contributor Author

A better location to check the file size is in welcome.js. We can simply show an alert return early from that function.

Yeah, even I realized that right now. I'll have a look at it and make the necessary changes here itself.

@shikhar-scs
Copy link
Contributor Author

@dannycoates Although welcome.js is a much better location to check for the file size, so is the cancellation procedure. As it is done in case of file.size===0, all it takes is just a return statement to be executed.

However displaying the relevant warning to the user in such a case is what is causing the problem. Though I've managed to do that using some script statements in the welcome.js file, its not looking good. I can do that if you want to OR maybe let it be as it is, as displayed in the gif file above as it equally solves the problem too. Whatsay?

@dannycoates
Copy link
Contributor

However displaying the relevant warning to the user in such a case is what is causing the problem.

Let's have the check in welcome.js. A javascript alert(msg) is enough ui for this. There's already a localization string for this named fileTooBig.

@shikhar-scs
Copy link
Contributor Author

@dannycoates Ok, I'll put that in place. Should I also include one for a 0 byte file ?

@dannycoates
Copy link
Contributor

Should I also include one for a 0 byte file ?

That one can stay how it is

@shikhar-scs
Copy link
Contributor Author

OK no problem 👍

@shikhar-scs
Copy link
Contributor Author

@dannycoates I've now finally introduced alert warnings. I guess this might be it. Here's a preview

The demo has been performed on a file size of 200MB (though the final commit contains the limit for 2GB) , reasons for which have been stated above.

upload2gb

Please review

Copy link
Contributor

@dannycoates dannycoates left a comment

Choose a reason for hiding this comment

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

pretty close

`;
return fileSizeExceededDiv;
}
*/
Copy link
Contributor

Choose a reason for hiding this comment

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

please delete the commented code

@@ -64,6 +64,14 @@ module.exports = function(state, emit) {
if (file.size === 0) {
return;
}
if (file.size > 2000000000) {
Copy link
Contributor

Choose a reason for hiding this comment

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

please use the MAXFILESIZE global variable instead of 2000000000

@@ -64,6 +64,14 @@ module.exports = function(state, emit) {
if (file.size === 0) {
return;
}
if (file.size > 2000000000) {
window.alert(
Copy link
Contributor

Choose a reason for hiding this comment

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

please use state.translate('fileTooBig', { size: bytes(MAXFILESIZE) }) instead of the hardcoded string. Where bytes is from app/utils.js

@shikhar-scs
Copy link
Contributor Author

shikhar-scs commented Jan 8, 2018

I've made the required changes @dannycoates. Please review.

P.S. why is the build test failing ?

Copy link
Contributor

@dannycoates dannycoates left a comment

Choose a reason for hiding this comment

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

almost

@@ -1,5 +1,7 @@
const html = require('choo/html');
const assets = require('../../common/assets');
const bytes = require('../utils');
const config = require('../../server/config');
const fileList = require('./fileList');
const { fadeOut } = require('../utils');
Copy link
Contributor

Choose a reason for hiding this comment

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

add bytes here const { bytes, fadeOut } = require('../utils'); instead of a separate require

@@ -59,11 +61,17 @@ module.exports = function(state, emit) {

async function upload(event) {
event.preventDefault();
const MAXFILESIZE = config.max_file_size;
Copy link
Contributor

Choose a reason for hiding this comment

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

not quite. The server path in the require is a clue that we shouldn't use that file here. MAXFILESIZE gets set globally in the browser window by https://send.firefox.com/jsconfig.js so we can use it directly here.

Copy link
Contributor Author

@shikhar-scs shikhar-scs Jan 9, 2018

Choose a reason for hiding this comment

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

Using the variable directly gives the following error

67:21  error    'MAXFILESIZE' is not defined  no-undef
  68:7   warning  Unexpected alert              no-alert
  68:64  error    'MAXFILESIZE' is not defined  no-undef

And this prevents any commits.
So, we need to do something different I guess

However, If this is the correct approach maybe then I shall edit the file directly on github itself

Copy link
Contributor

Choose a reason for hiding this comment

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

This is the linter complaining. Try adding /* global MAXFILESIZE */ as the first line of the file.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Correct, Its working now. I've pushed the commit please have a look.

Copy link
Contributor Author

@shikhar-scs shikhar-scs Jan 9, 2018

Choose a reason for hiding this comment

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

Also, I would squash my commits (if you want) once the PR is ready to be merged.

included global MAXFILESIZE
@shikhar-scs shikhar-scs force-pushed the warning-for-high-file-size branch from ffb7bb9 to 9501c1c Compare January 9, 2018 03:59
@shikhar-scs
Copy link
Contributor Author

shikhar-scs commented Jan 9, 2018

@dannycoates All the commits have been squashed, this PR is ready to be merged.

@dannycoates dannycoates merged commit 4f1ccf8 into mozilla:master Jan 9, 2018
@dannycoates
Copy link
Contributor

Thanks @shikhar-scs 😄

# for free to subscribe to this conversation on GitHub. Already have an account? #.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants