Skip to content

Don't lie about the preview mimetype - #7692

Merged
rullzer merged 2 commits into
masterfrom
dont_lie_preview_mimetype
Jan 8, 2018
Merged

Don't lie about the preview mimetype#7692
rullzer merged 2 commits into
masterfrom
dont_lie_preview_mimetype

Conversation

@rullzer

Copy link
Copy Markdown
Member

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

codecovBot commented Jan 4, 2018

Copy link
Copy Markdown

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 FilesCoverage ΔComplexity Δ
lib/private/legacy/image.php37.95% <0%> (-0.57%)213 <5> (+5)
lib/private/Preview/Generator.php78.44% <51.85%> (-6.13%)50 <7> (+6)
core/js/js.js65.88% <0%> (+0.55%)0% <0%> (ø)⬇️

@MorrisJobke

MorrisJobke commented Jan 4, 2018

Copy link
Copy Markdown
Member

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
Copy Markdown
MemberAuthor

@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.

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

@MorrisJobkeMorrisJobke left a comment

Copy link
Copy Markdown
Member

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) 👍

@MorrisJobkeMorrisJobke added this to the Nextcloud 13 milestone Jan 4, 2018
@MorrisJobkeMorrisJobke mentioned this pull request Jan 4, 2018
30 tasks
Comment threadlib/private/Preview/Generator.php Outdated
case 'image/gif':
return 'gif';
default:
return null;

Copy link
Copy Markdown
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?

Comment threadlib/public/IImage.php
public function resource();

/**
* @return string Returns the raw data mimetype

Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
Member

Thumbnails for png and jpg work fine 👍

@MorrisJobke

Copy link
Copy Markdown
Member

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

@MorrisJobkeMorrisJobke 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
rullzerforce-pushed the dont_lie_preview_mimetype branch from 6241374 to 048c1fdCompareJanuary 7, 2018 10:47
@rullzer

Copy link
Copy Markdown
MemberAuthor

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.

@rullzerrullzer 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
Copy Markdown
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
Copy Markdown
MemberAuthor

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
rullzerforce-pushed the dont_lie_preview_mimetype branch from 048c1fd to faa68b2CompareJanuary 7, 2018 13:36
@rullzer

Copy link
Copy Markdown
MemberAuthor

@nickvergessen is this ok for you now?

@rullzer
rullzer merged commit 7d87e83 into masterJan 8, 2018
@rullzer
rullzer deleted the dont_lie_preview_mimetype branch January 8, 2018 19:38
@MorrisJobkeMorrisJobke mentioned this pull request Jan 9, 2018
18 tasks
Sign up for freeto 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

@rullzer@MorrisJobke@nickvergessen