Skip to content

Commit

Permalink
Use correct full size parameter for version 3 (#63)
Browse files Browse the repository at this point in the history
  • Loading branch information
lutzhelm committed Nov 8, 2024
1 parent 85774ae commit 6415ae0
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 19 deletions.
5 changes: 3 additions & 2 deletions __tests__/CanvasDownloadLinks.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ function createWrapper(props) {
canvasId="abc123"
canvasLabel="My Canvas Label"
classes={{}}
fullSizeParam="max_full"
infoResponse={{}}
restrictDownloadOnSizeDefinition={false}
viewType="single"
Expand Down Expand Up @@ -179,15 +180,15 @@ describe('CanvasDownloadLinks', () => {

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

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

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

const link2 = screen.getByRole('link', { name: /Whole image \(1000 x 250px\)/i });
expect(link2).toHaveAttribute('href', 'http://example.com/iiif/abc123/full/1000,/0/default.jpg?download=true');
Expand Down
9 changes: 5 additions & 4 deletions src/CanvasDownloadLinks.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,13 @@ export default class CanvasDownloadLinks extends Component {
}

zoomedImageUrl() {
const { canvas } = this.props;
const { canvas, fullSizeParam } = this.props;
const bounds = this.currentBounds();
const boundsUrl = canvas
.getCanonicalImageUri()
.replace(
/\/full\/.*\/0\//,
`/${bounds.x},${bounds.y},${bounds.width},${bounds.height}/full/0/`,
`/${bounds.x},${bounds.y},${bounds.width},${bounds.height}/${fullSizeParam}/0/`,
);

return `${boundsUrl}?download=true`;
Expand All @@ -53,11 +53,11 @@ export default class CanvasDownloadLinks extends Component {
}

fullImageUrl() {
const { canvas } = this.props;
const { canvas, fullSizeParam } = this.props;

return `${canvas
.getCanonicalImageUri()
.replace(/\/full\/.*\/0\//, '/full/full/0/')}?download=true`;
.replace(/\/full\/.*\/0\//, `/full/${fullSizeParam}/0/`)}?download=true`;
}

thousandPixelWideImage() {
Expand Down Expand Up @@ -223,6 +223,7 @@ CanvasDownloadLinks.propTypes = {
getWidth: PropTypes.func.isRequired,
}).isRequired,
canvasLabel: PropTypes.string.isRequired, // canvasLabel is passed because we need access to redux
fullSizeParam: PropTypes.string.isRequired,
infoResponse: PropTypes.shape({
json: PropTypes.shape({
height: PropTypes.number,
Expand Down
40 changes: 27 additions & 13 deletions src/MiradorDownloadDialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,19 +87,33 @@ export class MiradorDownloadDialog extends Component {
<Typography variant="h2" component="span">Download</Typography>
</DialogTitle>
<ScrollIndicatedDialogContent>
{canvases.map((canvas) => (
<CanvasDownloadLinks
canvas={canvas}
canvasLabel={canvasLabel(canvas.id)}
infoResponse={infoResponse(canvas.id)}
restrictDownloadOnSizeDefinition={
restrictDownloadOnSizeDefinition
}
key={canvas.id}
viewType={viewType}
windowId={windowId}
/>
))}
{canvases.map((canvas) => {
const imageInfo = infoResponse(canvas.id);
const context = imageInfo.json && imageInfo.json['@context'];
let contextArray;
if (Array.isArray(context)) {
contextArray = context;
} else if (typeof context === 'string') {
contextArray = [context];
}
const fullSizeParam = contextArray && contextArray.indexOf('http://iiif.io/api/image/3/context.json') > -1
? 'max' : 'full';

return (
<CanvasDownloadLinks
canvas={canvas}
canvasLabel={canvasLabel(canvas.id)}
fullSizeParam={fullSizeParam}
infoResponse={infoResponse(canvas.id)}
restrictDownloadOnSizeDefinition={
restrictDownloadOnSizeDefinition
}
key={canvas.id}
viewType={viewType}
windowId={windowId}
/>
);
})}
{this.renderings().length > 0 && (
<ManifestDownloadLinks
renderings={this.renderings()}
Expand Down

0 comments on commit 6415ae0

Please sign in to comment.