Skip to content

Commit

Permalink
Remove add annotations workaround in IIIF response
Browse files Browse the repository at this point in the history
  • Loading branch information
adamjarling committed Jan 11, 2024
1 parent c09a14d commit b96ef85
Show file tree
Hide file tree
Showing 7 changed files with 5,823 additions and 3,190 deletions.
4 changes: 2 additions & 2 deletions lambdas/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8,761 changes: 5,689 additions & 3,072 deletions package-lock.json

Large diffs are not rendered by default.

59 changes: 19 additions & 40 deletions src/api/response/iiif/manifest.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const {
buildImageResourceId,
buildImageService,
isAudioVideo,
buildSupplementingAnnotation,
} = require("./presentation-api/items");
const { metadataLabelFields } = require("./presentation-api/metadata");
const {
Expand All @@ -21,11 +22,15 @@ function transform(response) {

const manifestId = `${dcApiEndpoint()}/works/${source.id}?as=iiif`;

const annotationsToTagOnAtEnd = [];

const normalizedFlatManifestObj = builder.createManifest(
manifestId,
(manifest) => {
/**
* Build out canvas from a Work's Fileset
* @param {object} fileSet
* @param {number} index
* @param {boolean} isAuxiliary
*/
function buildCanvasFromFileSet(fileSet, index, isAuxiliary) {
const canvasId = `${manifestId}/canvas/${fileSet.role.toLowerCase()}/${index}`;
manifest.createCanvas(canvasId, (canvas) => {
Expand All @@ -50,6 +55,7 @@ function transform(response) {
canvas.addThumbnail(canvasThumbnail);
}

/** Add "painting" annotation */
const annotationId = `${canvasId}/annotation/0`;
canvas.createAnnotation(annotationId, {
id: annotationId,
Expand All @@ -61,29 +67,17 @@ function transform(response) {
),
});

/** Add "supplementing" annotation */
if (!isAuxiliary && fileSet.webvtt) {
const annotations = {
id: `${canvasId}/annotations/page/0`,
type: "AnnotationPage",
items: [
{
id: `${canvasId}/annotations/page/0/a0`,
type: "Annotation",
motivation: "supplementing",
body: {
id: fileSet.webvtt,
type: "Text",
format: "text/vtt",
label: {
en: ["Chapters"],
},
language: "none",
},
target: canvasId,
},
],
};
annotationsToTagOnAtEnd.push(annotations);
canvas.createAnnotationPage(
`${canvasId}/annotations/page/0`,
(annotationPageBuilder) => {
annotationPageBuilder.createAnnotation(
buildSupplementingAnnotation({ canvasId, fileSet })
);
},
true
);
}
});
}
Expand Down Expand Up @@ -219,27 +213,12 @@ function transform(response) {
type: "Manifest",
});

/**
* Workaround to add webVTT annotations
* (iiif-builder package currently doesn't support it)
*/

annotationsToTagOnAtEnd.forEach((a) => {
const matched = jsonManifest.items.find(
(canvas) => canvas.id === a.items[0].target
);

if (matched) {
matched.annotations = [a];
}
});

/**
* Add a placeholderCanvas property to a Canvas if the annotation body is of type "Image"
* (iiif-builder package currently doesn't support adding this property)
*/
for (let i = 0; i < jsonManifest.items.length; i++) {
if (jsonManifest.items[i].items[0].items[0].body.type === "Image") {
if (jsonManifest.items[i]?.items[0]?.items[0]?.body.type === "Image") {
const { id, thumbnail } = jsonManifest.items[i];
const placeholderFileSet = source.file_sets.find(
(fileSet) =>
Expand Down
19 changes: 19 additions & 0 deletions src/api/response/iiif/presentation-api/items.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,24 @@ function buildImageService(representativeImageUrl) {
];
}

function buildSupplementingAnnotation({ canvasId, fileSet }) {
return {
id: `${canvasId}/annotations/page/0/a0`,
type: "Annotation",
motivation: "supplementing",
body: {
id: fileSet?.webvtt,
type: "Text",
format: "text/vtt",
label: {
en: ["Chapters"],
},
language: "none",
},
target: canvasId,
};
}

function isAudioVideo(type) {
return ["Audio", "Video", "Sound"].includes(type);
}
Expand All @@ -56,6 +74,7 @@ module.exports = {
buildAnnotationBodyId,
buildImageResourceId,
buildImageService,
buildSupplementingAnnotation,
isAudioVideo,
isImage,
};
Loading

0 comments on commit b96ef85

Please sign in to comment.