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: Fail intentionally when preview image files with deleted reps #964

Merged
merged 5 commits into from
Mar 27, 2019
Merged

Fix: Fail intentionally when preview image files with deleted reps #964

merged 5 commits into from
Mar 27, 2019

Conversation

jeremypress
Copy link
Contributor

@jeremypress jeremypress commented Mar 26, 2019

This download strategy can be applied to other "simple" viewers. We're now able to determine the http status in a 202 case, and caching still works as expected.

todo:

  • tests

@boxcla
Copy link

boxcla commented Mar 26, 2019

Verified that @jeremypress has signed the CLA. Thanks for the pull request!

src/lib/util.js Outdated
* @param {string} contentUrl - a representation's authenticated content URL
* @return {Promise} - Resolves with the representation data, rejects with a deleted rep error
*/
export function fetchRepresentationAsBlob(contentUrl) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added this to util because the DocPreloader will need it when fetching first page images. That class lives outside of the normal viewer inheritance hierarchy.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Is it possible for us to share the response handler function only, rather than the api call itself? That seems to fit more as a util, to me.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's possible, but I like the idea of keeping the response type in one place so that it's not repeated every time we use it.

fetchRepresentationAsBlob(imageUrl)
.then((blob) => {
const srcUrl = URL.createObjectURL(blob);
this.singleImageEls[index].src = srcUrl;
Copy link
Contributor Author

@jeremypress jeremypress Mar 26, 2019

Choose a reason for hiding this comment

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

Now that we're using axios, we can optimize here in the future by cancelling subsequent requests after we detect an initial failure.

jstoffan
jstoffan previously approved these changes Mar 26, 2019

this.bindDOMListeners();
return this.getRepStatus()
.getPromise()
.then(() => this.handleAssetAndRepLoad(downloadUrl))
.then(() => this.handleAssetAndRepLoad())
Copy link
Collaborator

Choose a reason for hiding this comment

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

You should be able to remove the wrapping arrow function.

src/lib/util.js Outdated
* @param {string} contentUrl - a representation's authenticated content URL
* @return {Promise} - Resolves with the representation data, rejects with a deleted rep error
*/
export function fetchRepresentationAsBlob(contentUrl) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is it possible for us to share the response handler function only, rather than the api call itself? That seems to fit more as a util, to me.

// Display a generic error message but log the real one
const error = new PreviewError(ERROR_CODE.CONTENT_DOWNLOAD, __('error_refresh'), {}, err.message);
super.handleDownloadError(error, imgUrl);
const genericDownloadError = new PreviewError(ERROR_CODE.CONTENT_DOWNLOAD, __('error_refresh'));
Copy link
Contributor

Choose a reason for hiding this comment

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

do we not need the extra params passed into the PreviewError constructor?

Copy link
Contributor

Choose a reason for hiding this comment

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

Nope, they're optional past the first param (error code)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

true, but this one should stay since it was there previously. I had modified this function before but it's not necessary anymore.

src/lib/util.js Outdated
* @return {Promise} - Resolves with the representation data, rejects with a deleted rep error
*/
export function fetchRepresentationAsBlob(contentUrl) {
return api.get(contentUrl, { type: 'blob' }).then((response) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you pull out the callback into a method? It'll allow for easy testing

// Display a generic error message but log the real one
const error = new PreviewError(ERROR_CODE.CONTENT_DOWNLOAD, __('error_refresh'), {}, err.message);
super.handleDownloadError(error, imgUrl);
const genericDownloadError = new PreviewError(ERROR_CODE.CONTENT_DOWNLOAD, __('error_refresh'));
Copy link
Contributor

Choose a reason for hiding this comment

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

Nope, they're optional past the first param (error code)

jstoffan
jstoffan previously approved these changes Mar 26, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants