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: Download watermarked #746

Merged
merged 3 commits into from
Mar 28, 2018
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/lib/Preview.js
Original file line number Diff line number Diff line change
Expand Up @@ -505,9 +505,11 @@ class Preview extends EventEmitter {
return;
}

// This allows the browser to download representation content
const params = Object.assign({ response_content_disposition_type: 'attachment' }, queryParams);
const downloadUrl = appendQueryParams(
this.viewer.createContentUrlWithAuthParams(contentUrlTemplate, this.viewer.options.viewer.ASSET),
queryParams
this.viewer.createContentUrlWithAuthParams(contentUrlTemplate, this.viewer.getAssetPath()),
params
);

DownloadReachability.downloadWithReachabilityCheck(downloadUrl);
Expand Down
9 changes: 6 additions & 3 deletions src/lib/__tests__/Preview-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -766,6 +766,7 @@ describe('lib/Preview', () => {
};
preview.viewer = {
getRepresentation: sandbox.stub(),
getAssetPath: sandbox.stub(),
createContentUrlWithAuthParams: sandbox.stub(),
options: {
viewer: {
Expand Down Expand Up @@ -815,12 +816,14 @@ describe('lib/Preview', () => {
const url = 'someurl';

preview.viewer.getRepresentation.returns(representation);
preview.viewer.createContentUrlWithAuthParams.withArgs(template, '').returns(url);
preview.viewer.getAssetPath.returns('1.jpg');
preview.viewer.createContentUrlWithAuthParams.withArgs(template, '1.jpg').returns(url);

util.appendQueryParams.withArgs(url).returns(url);
util.appendQueryParams.returns(url);

preview.download();

expect(util.appendQueryParams).to.be.calledWith(url, { response_content_disposition_type: 'attachment' });
expect(DownloadReachability.downloadWithReachabilityCheck).to.be.calledWith(url);
});

Expand All @@ -829,7 +832,7 @@ describe('lib/Preview', () => {
file.shouldDownloadWM.returns(false);

const url = 'someurl';
util.appendQueryParams.withArgs(url).returns(url);
util.appendQueryParams.returns(url);

const promise = Promise.resolve({
download_url: url
Expand Down
27 changes: 18 additions & 9 deletions src/lib/viewers/BaseViewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -783,6 +783,24 @@ class BaseViewer extends EventEmitter {
}
}

/**
* Returns the representation used for Preview.
*
* @return {Object} Box representation used/to be used by Preview
*/
getRepresentation() {
return this.options.representation;
}

/**
* Returns the asset path to access representation content for Preview.
*
* @return {string} Asset path
*/
getAssetPath() {
return getProp(this, 'options.viewer.ASSET', '');
}

//--------------------------------------------------------------------------
// Annotations
//--------------------------------------------------------------------------
Expand Down Expand Up @@ -1028,15 +1046,6 @@ class BaseViewer extends EventEmitter {
})
);
}

/**
* Returns the representation used for Preview.
*
* @return {Object} Box representation used/to be used by Preview
*/
getRepresentation() {
return this.options.representation;
}
}

export default BaseViewer;
28 changes: 21 additions & 7 deletions src/lib/viewers/__tests__/BaseViewer-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -954,6 +954,27 @@ describe('lib/viewers/BaseViewer', () => {
});
});

describe('getRepresentation()', () => {
it('should return the representation the viewer is/will use to preview', () => {
base.options.representation = { some: 'stuff' };
expect(base.getRepresentation()).to.equal(base.options.representation);
});
});

describe('getAssetPath()', () => {
it('should return the asset path the viewer is/will use for preview representation content', () => {
base.options.viewer = {
ASSET: '1.jpg'
};
expect(base.getAssetPath()).to.equal(base.options.viewer.ASSET);
});

it('should return empty string if viewer does not have a special asset path', () => {
base.options.viewer = {};
expect(base.getAssetPath()).to.equal('');
});
});

describe('loadAnnotator()', () => {
const conf = {
annotationsEnabled: true,
Expand Down Expand Up @@ -1325,11 +1346,4 @@ describe('lib/viewers/BaseViewer', () => {
expect(combinedOptions.localizedStrings).to.not.be.undefined;
});
});

describe('getRepresentation()', () => {
it('should return the representation the viewer is/will use to preview', () => {
base.options.representation = { some: 'stuff' };
expect(base.getRepresentation()).to.equal(base.options.representation);
});
});
});