Skip to content

Add video block size validation in the Media Library#2755

Merged
swissspidy merged 37 commits intodevelopfrom
add/video-block-size-validation
Jul 16, 2019
Merged

Add video block size validation in the Media Library#2755
swissspidy merged 37 commits intodevelopfrom
add/video-block-size-validation

Conversation

@kienstra
Copy link
Copy Markdown
Contributor

@kienstra kienstra commented Jul 8, 2019

  • In the Media Library, on selecting a video with the wrong size, this displays a notice
  • Applies to the Media Library for the Video block and 'Background Media'
  • Doesn't disable the 'Select' button
  • Branched off Enforce the file type of the featured image, background media, and video block #2737, as that refactored the Media Library logic
  • If/when that PR is merged, I'll probably rebase this PR to develop and target this PR to develop

in-video

Closes #2560

kienstra added 18 commits July 2, 2019 19:51
This doesn't disable the 'Select' button now,
though it shows a notice both in the AMP Story
editor and the normal post or page block editor.
Before, this simply displayed a notice.
Now, it actually disables the button.
…tion

I didn't write this originally, but I used this
same logic for the file type notice.

So instead of simply copy and pasting it,
this extracts it into a separate function.
Refactor much of the existing logic,
which was for featured images.
Rename a file and many functions.
There was duplicated logic,
so use that function in place of the copy-pasted code.
It looks like that wasn't preventing .mov files from appearing.
Also, the new logic uses ALLOWED_MEDIA_TYPES as passed in allowedTypes.
It checks that the attachment.get( 'type' ) matches that,
and the attachment.get( 'type' ) is never 'video/mp4'.
That is only the attachment.get( 'mime' ).
There was a file that should have been moved,
but I forgot to delete it.
There an error:
fatal: Path 'amp.php' exists on disk, but not in 'eb9bb06b77d811ba80ca70ec60fbe551aea4ca73'.
Pascal had suggested an empty commit for this.
It looks like this needed a 'select' handler.
So add one here.
Add a mockClasses.js file to store some mocks.
And use this for the tests in isFileTypeAllowed.js.
That seems to have caused .mov files to appear
in the Background Media.
So revert the change to that,
and instead change isFileTypeAllowed()
to return true whene a mime type matches
a value in the allowedTypes array.
This PR already blocked selecting uploading them.
But if they were uploaded before, they would
still display in the 'Media Library' tab of the
Media Library.
So this blocks displaying them in that tab if they
were uploaded before.
This caused a failed Travis build,
as it was imported but not used.
Before, some of these were joined using a comma.
Instead, keep to the convention in the rest of this PR.
There shouldn't have been a period
in the middle of the sentence.
These functions will be useful in displaying the
notice for video size,
and that logic is in commmon/.
So move all of this to common/.
This applies to the Core Video block and
the AMP Stories 'Background Media' component.
Also, add unit tests for the helper methods.
@googlebot googlebot added the cla: yes Signed the Google CLA label Jul 8, 2019
kienstra added 2 commits July 8, 2019 19:43
The heading mentioned the file size,
where it should have been type.
When there were 2 notices, like for the wrong
video type and file size,
the notices overlapped some of the media.
So add a class to the media library
if there are 2 notices.
And add a style rule for that class.
@kienstra
Copy link
Copy Markdown
Contributor Author

kienstra commented Jul 9, 2019

Steps To Test

  1. Create a new story
  2. For the 'Background Media' of a page, upload or select from the 'Media Library' tab a video with more than 1 MB per second, like this
  3. Expected: the 'Select' button is not disabled, but there is a notice like:

A video size of less than 1 MB per second is recommended. The selected video is 10 MB per second.

notice-appears

Here's the notice:
select-button

  1. Repeat steps 2-3, but for the Video block (using the 'Media Library' button)
  2. Edge case: for the Video block, upload via the Media Library a .mov file with more than 1 MB per second, like this
  3. Expected: there are two notices: one for the wrong file type and one for the wrong file size:

video-notices

@kienstra
Copy link
Copy Markdown
Contributor Author

kienstra commented Jul 9, 2019

This isn't quite ready for review, as it's still branched off the fix/upload-file-type branch. If and when that branch is merged into develop, I'll probably rebase this to develop and target that branch.

@westonruter westonruter changed the base branch from fix/upload-file-type to develop July 11, 2019 20:55
@googlebot
Copy link
Copy Markdown

So there's good news and bad news.

👍 The good news is that everyone that needs to sign a CLA (the pull request submitter and all commit authors) have done so. Everything is all good there.

😕 The bad news is that it appears that one or more commits were authored or co-authored by someone other than the pull request submitter. We need to confirm that all authors are ok with their commits being contributed to this project. Please have them confirm that here in the pull request.

Note to project maintainer: This is a terminal state, meaning the cla/google commit status will not change from this state. It's up to you to confirm consent of all the commit author(s), set the cla label to yes (if enabled on your project), and then merge this pull request when appropriate.

ℹ️ Googlers: Go here for more info.

@googlebot googlebot added cla: no Has not signed the Google CLA and removed cla: yes Signed the Google CLA labels Jul 11, 2019
@westonruter westonruter changed the base branch from develop to fix/upload-file-type July 11, 2019 20:55
@westonruter westonruter force-pushed the add/video-block-size-validation branch from cf596ab to e2e81c0 Compare July 11, 2019 20:57
@googlebot
Copy link
Copy Markdown

CLAs look good, thanks!

ℹ️ Googlers: Go here for more info.

@swissspidy
Copy link
Copy Markdown
Collaborator

Added a warning now when pasting a video URL:

Screenshot 2019-07-16 at 11 26 18

@miina
Copy link
Copy Markdown
Contributor

miina commented Jul 16, 2019

I'm seeing 0 at the place of the notice if there is no error (see below "Replace Image")

Screenshot 2019-07-16 at 13 05 35

@miina
Copy link
Copy Markdown
Contributor

miina commented Jul 16, 2019

Likely not the most common use case but looks like displaying the warning based on URL stops showing when I do the following:

  • Add a video from URL that exceeds the limits.
  • Click "Edit Video" icon.
  • Choose "Insert from URL".
  • Don't change anything, leave the same URL, submit.

@miina
Copy link
Copy Markdown
Contributor

miina commented Jul 16, 2019

I guess the only place where the warning is missing then is when a previous video is changed via "Edit Video" and "Upload".

Actually, there is no need to change a previous video, just using "Upload" directly and choosing a video exceeding the limits won't show the warning since the Media Library doesn't open then.

@swissspidy
Copy link
Copy Markdown
Collaborator

swissspidy commented Jul 16, 2019

Likely not the most common use case but looks like displaying the warning based on URL stops showing when I do the following

Cannot reproduce this.

I'm seeing 0 at the place of the notice if there is no error (see below "Replace Image")

Cannot reproduce either.

Edit: now I can see it 🤷‍♂

Since 4 is used for every test, maybe for readability we could use a general descriptive variable for the seconds

Made the tests much more readable now in 3ce5e76.

@swissspidy
Copy link
Copy Markdown
Collaborator

Actually, there is no need to change a previous video, just using "Upload" directly and choosing a video exceeding the limits won't show the warning since the Media Library doesn't open then.

I guess we can then just show the warning in the sidebar.

@swissspidy
Copy link
Copy Markdown
Collaborator

@miina Mind checking again?

@miina
Copy link
Copy Markdown
Contributor

miina commented Jul 16, 2019

Awesome, the issues mentioned before are gone now!

One more oddity that I just saw, the same video shows different values in the Media Library vs in the sidebar.
Sidebar (8MB):
Screenshot 2019-07-16 at 15 10 24

Media Library (10MB):
Screenshot 2019-07-16 at 15 10 13

Thoughts?

@swissspidy
Copy link
Copy Markdown
Collaborator

One more oddity that I just saw, the same video shows different values in the Media Library vs in the sidebar.

Interesting. Will try to reproduce.

@miina
Copy link
Copy Markdown
Contributor

miina commented Jul 16, 2019

Interesting. Will try to reproduce.

Note that I was using this video.

@swissspidy
Copy link
Copy Markdown
Collaborator

Looks like it was a rounding issue.

@swissspidy swissspidy requested a review from miina July 16, 2019 13:04
Copy link
Copy Markdown
Contributor

@miina miina left a comment

Choose a reason for hiding this comment

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

🎉

@swissspidy swissspidy merged commit 715ecb2 into develop Jul 16, 2019
@swissspidy swissspidy deleted the add/video-block-size-validation branch July 16, 2019 14:10
@swissspidy swissspidy added this to the v1.2.1 milestone Jul 18, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla: yes Signed the Google CLA

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Display a notice if a video in the video block is over 1 MB per second

5 participants