aiiinotate 0.4.1 → 0.4.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -229,7 +229,6 @@ class Annotations2 extends CollectionAbstract {
|
|
|
229
229
|
target.manifestUri
|
|
230
230
|
? await this.manifestsPlugin.getCanvasIdx(target.manifestUri, target.full)
|
|
231
231
|
: undefined;
|
|
232
|
-
// console.log(">>> #insertManifestsAndGetCanvasIdx: target", target);
|
|
233
232
|
return target;
|
|
234
233
|
})
|
|
235
234
|
)
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import fastifyPlugin from "fastify-plugin";
|
|
2
2
|
|
|
3
3
|
import CollectionAbstract from "#data/collectionAbstract.js";
|
|
4
|
-
import { getManifestShortId
|
|
4
|
+
import { getManifestShortId } from "#utils/iiif2Utils.js";
|
|
5
5
|
import { formatInsertResponse } from "#src/data/utils/routeUtils.js";
|
|
6
6
|
import { inspectObj, visibleLog, ajvCompile } from "#utils/utils.js";
|
|
7
7
|
import { IIIF_PRESENTATION_2_CONTEXT } from "#utils/iiifUtils.js";
|
|
@@ -211,6 +211,8 @@ class Manifests2 extends CollectionAbstract {
|
|
|
211
211
|
const r = await this.#fetchManifestFromUri(manifestUri);
|
|
212
212
|
if ( ! r.error ) {
|
|
213
213
|
manifestArray.push(r);
|
|
214
|
+
} else {
|
|
215
|
+
fetchErrorIds.push(r);
|
|
214
216
|
}
|
|
215
217
|
} catch (err) {
|
|
216
218
|
if ( throwOnError ) {
|
|
@@ -223,6 +225,9 @@ class Manifests2 extends CollectionAbstract {
|
|
|
223
225
|
const result = await this.insertManifestArray(manifestArray, throwOnError);
|
|
224
226
|
// if there has been an error but error-throwing was disabled, complete the response object with description of the errors
|
|
225
227
|
if ( !throwOnError ) {
|
|
228
|
+
if ( fetchErrorIds.length ) {
|
|
229
|
+
console.error(`${this.funcName(this.insertManifestsFromUriArray)}: error inserting ${fetchErrorIds} manifests`, fetchErrorIds);
|
|
230
|
+
}
|
|
226
231
|
result.fetchErrorIds = fetchErrorIds;
|
|
227
232
|
}
|
|
228
233
|
return result;
|
|
@@ -85,6 +85,26 @@ const getAnnotationTarget = (annotation) => {
|
|
|
85
85
|
return maybeToArray(annotation.on).map(getSingleAnnotationTarget);
|
|
86
86
|
}
|
|
87
87
|
|
|
88
|
+
/**
|
|
89
|
+
* @example "127.0.0.1:3000/data/2/wit9_man11_anno165/annotation/c26_abda6e3c-2926-4495-9787-cb3f3588e47c"
|
|
90
|
+
* @param {string} manifestShortId
|
|
91
|
+
* @param {string} canvasId
|
|
92
|
+
* @returns {string}
|
|
93
|
+
*/
|
|
94
|
+
const toAiiinotateAnnotationUri = (manifestShortId, canvasId) =>
|
|
95
|
+
`${process.env.AIIINOTATE_BASE_URL}/data/${IIIF_PRESENTATION_2}/${manifestShortId}/annotation/${canvasId}_${uuid4()}`;
|
|
96
|
+
|
|
97
|
+
const toAiiinotateManifestUri = (manifestShortId) =>
|
|
98
|
+
`${process.env.AIIINOTATE_BASE_URL}/data/${IIIF_PRESENTATION_2}/${manifestShortId}/manifest.json`;
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* if `canvasUri` follows the recommended IIIF 2.1 recommended URI pattern, convert it to a JSON manifest URI.
|
|
102
|
+
* @param {string} canvasUri
|
|
103
|
+
* @returns {string} : the manifest URI
|
|
104
|
+
*/
|
|
105
|
+
const canvasUriToManifestUri = (canvasUri) =>
|
|
106
|
+
canvasUri.split("/").slice(0,-2).join("/") + "/manifest.json";
|
|
107
|
+
|
|
88
108
|
/**
|
|
89
109
|
* convert the annotation's `on` to a SpecificResource
|
|
90
110
|
* reimplemented from SAS: https://github.com/glenrobson/SimpleAnnotationServer/blob/dc7c8c6de9f4693c678643db2a996a49eebfcbb0/src/main/java/uk/org/llgc/annotation/store/AnnotationUtils.java#L123-L135
|
|
@@ -128,7 +148,7 @@ const makeTarget = (annotation) => {
|
|
|
128
148
|
}
|
|
129
149
|
if ( objectHasKey(specificResource, "full") ) {
|
|
130
150
|
specificResource.manifestShortId = getManifestShortId(specificResource.full);
|
|
131
|
-
specificResource.manifestUri =
|
|
151
|
+
specificResource.manifestUri = canvasUriToManifestUri(specificResource.full);
|
|
132
152
|
}
|
|
133
153
|
return specificResource
|
|
134
154
|
}
|
|
@@ -157,29 +177,9 @@ const makeAnnotationId = (annotation, manifestShortId) => {
|
|
|
157
177
|
throw new Error(`${makeAnnotationId.name}: could not make an 'annotationId' (with manifestShortId=${manifestShortId}, annotation=${annotation})`)
|
|
158
178
|
}
|
|
159
179
|
|
|
160
|
-
return
|
|
180
|
+
return toAiiinotateAnnotationUri(manifestShortId, canvasId);
|
|
161
181
|
}
|
|
162
182
|
|
|
163
|
-
/**
|
|
164
|
-
* @example "127.0.0.1:3000/data/2/wit9_man11_anno165/annotation/c26_abda6e3c-2926-4495-9787-cb3f3588e47c"
|
|
165
|
-
* @param {string} manifestShortId
|
|
166
|
-
* @param {string} canvasId
|
|
167
|
-
* @returns {string}
|
|
168
|
-
*/
|
|
169
|
-
const annotationUri = (manifestShortId, canvasId) =>
|
|
170
|
-
`${process.env.AIIINOTATE_BASE_URL}/data/${IIIF_PRESENTATION_2}/${manifestShortId}/annotation/${canvasId}_${uuid4()}`;
|
|
171
|
-
|
|
172
|
-
const manifestUri = (manifestShortId) =>
|
|
173
|
-
`${process.env.AIIINOTATE_BASE_URL}/data/${IIIF_PRESENTATION_2}/${manifestShortId}/manifest.json`;
|
|
174
|
-
|
|
175
|
-
/**
|
|
176
|
-
* if `canvasUri` follows the recommended IIIF 2.1 recommended URI pattern, convert it to a JSON manifest URI.
|
|
177
|
-
* @param {string} canvasUri
|
|
178
|
-
* @returns {string} : the manifest URI
|
|
179
|
-
*/
|
|
180
|
-
const canvasUriToManifestUri = (canvasUri) =>
|
|
181
|
-
canvasUri.split("/").slice(0,-2).join("/") + "/manifest.json";
|
|
182
|
-
|
|
183
183
|
/**
|
|
184
184
|
*
|
|
185
185
|
* @param {object[]} resources: the annotatons
|
|
@@ -203,8 +203,8 @@ const toAnnotationList = (resources, annotationListId, label) => {
|
|
|
203
203
|
export {
|
|
204
204
|
makeTarget,
|
|
205
205
|
makeAnnotationId,
|
|
206
|
-
|
|
207
|
-
|
|
206
|
+
toAiiinotateAnnotationUri,
|
|
207
|
+
toAiiinotateManifestUri,
|
|
208
208
|
toAnnotationList,
|
|
209
209
|
getManifestShortId,
|
|
210
210
|
getCanvasShortId,
|