Skip to content

Commit

Permalink
Update getRights and getLogo for v3 manifests (#133)
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesmisson authored Sep 23, 2024
1 parent 28a0afb commit cb4beb1
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 4 deletions.
4 changes: 3 additions & 1 deletion src/Canvas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,9 @@ export class Canvas extends Resource {
const on = resourceAnnotation.getProperty("on");
// IIIF v3
const target = resourceAnnotation.getProperty("target");
if (!on || !target) { return undefined; }
if (!on || !target) {
return undefined;
}
const fragmentMatch = (on || target).match(/xywh=(.*)$/);
if (!fragmentMatch) return undefined;
return fragmentMatch[1].split(",").map(str => parseInt(str, 10));
Expand Down
14 changes: 13 additions & 1 deletion src/IIIFResource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,9 @@ export class IIIFResource extends ManifestResource {
return null;
}

logo = provider.logo;
// get the first agent in the provider array with a logo
const agent = provider.find(item => item.logo !== undefined);
logo = typeof agent.logo === "undefined" ? null : agent.logo;
}

if (!logo) return null;
Expand All @@ -105,6 +107,16 @@ export class IIIFResource extends ManifestResource {
);
}

getRights(): string | null {
var rights = this.getProperty("rights");
if (!rights) return null;
if (typeof rights === "string") return rights;
if (Array.isArray(rights) && rights.length) {
rights = rights[0];
}
return rights["@id"] || rights.id;
}

getNavDate(): Date {
return new Date(this.getProperty("navDate"));
}
Expand Down
4 changes: 2 additions & 2 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ importTest('rijksmuseum-image-api-v3-thumbnails', './tests/rijksmuseum-image-api
// importTest('items-not-sequence', './tests/items-not-sequence');
// importTest('LabelValuePair', './tests/LabelValuePair.test');
// importTest('LanguageMap', './tests/LanguageMap.test');
// importTest('logo', './tests/logo');
importTest('logo', './tests/logo');
// importTest('lunchroommanners', './tests/lunchroommanners');
// importTest('manifest-with-thumbnail', './tests/manifest-with-thumbnail');
// importTest('members-collection', './tests/members-collection');
Expand All @@ -75,7 +75,7 @@ importTest('rijksmuseum-image-api-v3-thumbnails', './tests/rijksmuseum-image-api
// importTest('pres3-collection3', './tests/pres3-collection3');
// importTest('pres3-collection4', './tests/pres3-collection4');
// importTest('pres3-pdf', './tests/pres3-pdf');
// importTest('pres3', './tests/pres3');
importTest('pres3', './tests/pres3');
// importTest('presentation2-paging', './tests/presentation2-paging');
// importTest('presentation3-paging', './tests/presentation3-paging');
// importTest('PropertyValue', './tests/PropertyValue.test')
Expand Down
10 changes: 10 additions & 0 deletions test/tests/pres3.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,14 @@ describe('presentation 3', function() {
var labelValue = label.getValue();
expect(labelValue).to.equal('Page 1');
});

it('has a logo', function () {
var logo = manifest.getLogo();
expect(logo).to.equal('https://example.org/logos/institution1.jpg');
});

it('has a rights', function () {
var rights = manifest.getRights();
expect(rights).to.equal('http://example.org/license.html');
});
});

0 comments on commit cb4beb1

Please sign in to comment.