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

Don't lie about the preview mimetype #7692

Merged
merged 2 commits into from
Jan 8, 2018
Merged

Conversation

rullzer
Copy link
Member

@rullzer rullzer commented Jan 4, 2018

For legacy reasons we stored all the previews with a png extention.
However we did not put png data in them all the time.

This caused the preview endpoints to always report that a preview is a
png file. Which was a lie.

Since we abstract away from the storage etc in the previewmanager. There
is no need anymore to store them as .png files and instead we can use
the actual file extention.

@codecov
Copy link

codecov bot commented Jan 4, 2018

Codecov Report

Merging #7692 into master will decrease coverage by <.01%.
The diff coverage is 37.83%.

@@             Coverage Diff              @@
##             master    #7692      +/-   ##
============================================
- Coverage     51.17%   51.17%   -0.01%     
- Complexity    24948    24959      +11     
============================================
  Files          1605     1605              
  Lines         94923    94951      +28     
  Branches       1376     1376              
============================================
+ Hits          48579    48589      +10     
- Misses        46344    46362      +18
Impacted Files Coverage Δ Complexity Δ
lib/private/legacy/image.php 37.95% <0%> (-0.57%) 213 <5> (+5)
lib/private/Preview/Generator.php 78.44% <51.85%> (-6.13%) 50 <7> (+6)
core/js/js.js 65.88% <0%> (+0.55%) 0% <0%> (ø) ⬇️

@MorrisJobke
Copy link
Member

MorrisJobke commented Jan 4, 2018

How to reproduce this? I guess it is about to upload a JPG and a PNG and then look into the activity stream. In Firefox/Chrome it showed the previews and in IE it did not show the previews?

@rullzer
Copy link
Member Author

rullzer commented Jan 4, 2018

@MorrisJobke yep. IE11 I tested it.

Basically FF and Chrome say well you told me it was a PNG but I see it is a JPEG so I just display it as a jpeg. While IE says nope not a PNG so I won't show you anything.

@rullzer rullzer added 3. to review Waiting for reviews and removed 2. developing Work in progress labels Jan 4, 2018
Copy link
Member

@MorrisJobke MorrisJobke left a comment

Choose a reason for hiding this comment

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

Tested and works (for new files only obviously) 👍

@MorrisJobke MorrisJobke added this to the Nextcloud 13 milestone Jan 4, 2018
@MorrisJobke MorrisJobke requested a review from danxuliu January 4, 2018 16:11
@MorrisJobke MorrisJobke mentioned this pull request Jan 4, 2018
30 tasks
case 'image/gif':
return 'gif';
default:
return null;
Copy link
Member

Choose a reason for hiding this comment

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

Why not return ''? Then we don't have this nasty null?

@@ -102,6 +102,12 @@ public function save($filePath = null, $mimeType = null);
*/
public function resource();

/**
* @return string Returns the raw data mimetype
Copy link
Member

Choose a reason for hiding this comment

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

Could also return null. Either return empty string in error case or point out the null here as well. I would vote for one type of return value.

$path .= '.png';

$ext = $this->getExtention($mimeType);
$path .= '.' . $ext;
Copy link
Member

Choose a reason for hiding this comment

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

if ext is null or '' (after morris change), the path is weird. so without any extension.

@nickvergessen
Copy link
Member

Thumbnails for png and jpg work fine 👍

@MorrisJobke
Copy link
Member

Okay - let's wait with this after beta 4 and fix it until then.

@MorrisJobke MorrisJobke added 2. developing Work in progress and removed 3. to review Waiting for reviews labels Jan 5, 2018
For legacy reasons we stored all the previews with a png extention.
However we did not put png data in them all the time.

This caused the preview endpoints to always report that a preview is a
png file. Which was a lie.

Since we abstract away from the storage etc in the previewmanager. There
is no need anymore to store them as .png files and instead we can use
the actual file extention.

Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
@rullzer rullzer force-pushed the dont_lie_preview_mimetype branch from 6241374 to 048c1fd Compare January 7, 2018 10:47
@rullzer
Copy link
Member Author

rullzer commented Jan 7, 2018

Now just 1 return type.

Also in the preview generation an exception will be thrown. Which will get converted into a NotFoundException. Thus showing a proper 404 to the user.

@rullzer rullzer added 3. to review Waiting for reviews and removed 2. developing Work in progress labels Jan 7, 2018
case 'image/gif':
return 'gif';
default:
throw new \InvalidArgumentException('Not a valid mimetype');
Copy link
Member

Choose a reason for hiding this comment

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

Add this to the PHPDoc please

Copy link
Member Author

Choose a reason for hiding this comment

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

Done

Throw proper exception if we can't get the mimetype for a preview. Catch
it later on so we can just return a not found for the preview.

Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
@rullzer rullzer force-pushed the dont_lie_preview_mimetype branch from 048c1fd to faa68b2 Compare January 7, 2018 13:36
@rullzer
Copy link
Member Author

rullzer commented Jan 8, 2018

@nickvergessen is this ok for you now?

@rullzer rullzer merged commit 7d87e83 into master Jan 8, 2018
@rullzer rullzer deleted the dont_lie_preview_mimetype branch January 8, 2018 19:38
@MorrisJobke MorrisJobke mentioned this pull request Jan 9, 2018
18 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants