Skip to content

Commit 3e57cf4

Browse files
committed
Just check version in MiradorDownloadDialog, decide on behavior in CanvasDownloadLinks
1 parent 7f4ee07 commit 3e57cf4

File tree

3 files changed

+13
-13
lines changed

3 files changed

+13
-13
lines changed

__tests__/CanvasDownloadLinks.test.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ function createWrapper(props) {
1212
canvasId="abc123"
1313
canvasLabel="My Canvas Label"
1414
classes={{}}
15-
fullSizeParam="max_full"
15+
isVersion3={false}
1616
infoResponse={{}}
1717
restrictDownloadOnSizeDefinition={false}
1818
viewType="single"
@@ -180,15 +180,15 @@ describe('CanvasDownloadLinks', () => {
180180

181181
const link = screen.getByRole('link', { name: /Whole image \(4000 x 1000px\)/i });
182182
expect(link).toBeInTheDocument();
183-
expect(link).toHaveAttribute('href', 'http://example.com/iiif/abc123/full/max_full/0/default.jpg?download=true');
183+
expect(link).toHaveAttribute('href', 'http://example.com/iiif/abc123/full/full/0/default.jpg?download=true');
184184
});
185185

186186
describe('For Images Wider Than 1000px', () => {
187187
it('renders links for both full-size and 1000px wide versions', () => {
188188
createWrapper({ canvas });
189189

190190
const link1 = screen.getByRole('link', { name: /Whole image \(4000 x 1000px\)/i });
191-
expect(link1).toHaveAttribute('href', 'http://example.com/iiif/abc123/full/max_full/0/default.jpg?download=true');
191+
expect(link1).toHaveAttribute('href', 'http://example.com/iiif/abc123/full/full/0/default.jpg?download=true');
192192

193193
const link2 = screen.getByRole('link', { name: /Whole image \(1000 x 250px\)/i });
194194
expect(link2).toHaveAttribute('href', 'http://example.com/iiif/abc123/full/1000,/0/default.jpg?download=true');

src/CanvasDownloadLinks.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,30 +34,31 @@ export default class CanvasDownloadLinks extends Component {
3434
}
3535

3636
zoomedImageUrl() {
37-
const { canvas, fullSizeParam } = this.props;
37+
const { canvas, isVersion3 } = this.props;
3838
const bounds = this.currentBounds();
3939
const boundsUrl = canvas
4040
.getCanonicalImageUri()
4141
.replace(
4242
/\/full\/.*\/0\//,
43-
`/${bounds.x},${bounds.y},${bounds.width},${bounds.height}/${fullSizeParam}/0/`,
43+
`/${bounds.x},${bounds.y},${bounds.width},${bounds.height}/${isVersion3 ? `${bounds.width},${bounds.height}` : 'full'}/0/`,
4444
);
4545

4646
return `${boundsUrl}?download=true`;
4747
}
4848

4949
imageUrlForSize(size) {
50-
const { canvas } = this.props;
50+
const { canvas, isVersion3 } = this.props;
5151

52-
return `${canvas.getCanonicalImageUri(size.width)}?download=true`;
52+
return isVersion3 ? `${canvas.getCanonicalImageUri().replace(/\/full\/.*\/0\//, `/full/${size.width},${size.height}/0/`)}?download=true`
53+
: `${canvas.getCanonicalImageUri(size.width)}?download=true`;
5354
}
5455

5556
fullImageUrl() {
56-
const { canvas, fullSizeParam } = this.props;
57+
const { canvas, isVersion3 } = this.props;
5758

5859
return `${canvas
5960
.getCanonicalImageUri()
60-
.replace(/\/full\/.*\/0\//, `/full/${fullSizeParam}/0/`)}?download=true`;
61+
.replace(/\/full\/.*\/0\//, `/full/${isVersion3 ? 'max' : 'full'}/0/`)}?download=true`;
6162
}
6263

6364
thousandPixelWideImage() {
@@ -223,7 +224,6 @@ CanvasDownloadLinks.propTypes = {
223224
getWidth: PropTypes.func.isRequired,
224225
}).isRequired,
225226
canvasLabel: PropTypes.string.isRequired, // canvasLabel is passed because we need access to redux
226-
fullSizeParam: PropTypes.string.isRequired,
227227
infoResponse: PropTypes.shape({
228228
json: PropTypes.shape({
229229
height: PropTypes.number,
@@ -233,6 +233,7 @@ CanvasDownloadLinks.propTypes = {
233233
width: PropTypes.number,
234234
}),
235235
}).isRequired,
236+
isVersion3: PropTypes.bool.isRequired,
236237
restrictDownloadOnSizeDefinition: PropTypes.bool.isRequired,
237238
viewType: PropTypes.string.isRequired,
238239
windowId: PropTypes.string.isRequired,

src/MiradorDownloadDialog.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,14 +92,13 @@ export class MiradorDownloadDialog extends Component {
9292
} else if (typeof context === 'string') {
9393
contextArray = [context];
9494
}
95-
const fullSizeParam = contextArray && contextArray.indexOf('http://iiif.io/api/image/3/context.json') > -1
96-
? 'max' : 'full';
95+
const isVersion3 = contextArray && contextArray.indexOf('http://iiif.io/api/image/3/context.json') > -1;
9796

9897
return (
9998
<CanvasDownloadLinks
10099
canvas={canvas}
101100
canvasLabel={canvasLabel(canvas.id)}
102-
fullSizeParam={fullSizeParam}
101+
isVersion3={isVersion3}
103102
infoResponse={infoResponse(canvas.id)}
104103
restrictDownloadOnSizeDefinition={
105104
restrictDownloadOnSizeDefinition

0 commit comments

Comments
 (0)