aiiinotate 0.4.0 → 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/docs/endpoints.md
CHANGED
|
@@ -38,7 +38,7 @@ Implementation of the [IIIF Search API](https://iiif.io/api/search/2.0/), to sea
|
|
|
38
38
|
- if `iiif_version=1`, `q` is searched in the fields: `@id`, `resource.@id` or `resource.chars` fields
|
|
39
39
|
- `motivation` (`painting | non-painting | commenting | describing | tagging | linking`): values for the `motivation` field of an annotation
|
|
40
40
|
|
|
41
|
-
####
|
|
41
|
+
#### Response
|
|
42
42
|
|
|
43
43
|
Returns a JSON. If `iiif_version` is `1`, an `AnnotationList` is returned. Otherwise, an `AnnotationPage` is returned.
|
|
44
44
|
|
|
@@ -69,7 +69,7 @@ DELETE /{collection_name}/{iiif_version}/delete
|
|
|
69
69
|
- `manifestShortId`: a manifest's identifier, to delete all annotations for a manifest
|
|
70
70
|
- `canvasUri`: the full URI to an annotation's target canvas, to delete all annotatons for the canvas
|
|
71
71
|
|
|
72
|
-
####
|
|
72
|
+
#### Response
|
|
73
73
|
|
|
74
74
|
```
|
|
75
75
|
{ deletedCount: <integer> }
|
|
@@ -92,7 +92,7 @@ Returns a Collection of all manifests in your **aiiinotate** instance.
|
|
|
92
92
|
- Variables:
|
|
93
93
|
- `iiif_version` (`2 | 3`): the IIIF Presentation API version
|
|
94
94
|
|
|
95
|
-
####
|
|
95
|
+
#### Response
|
|
96
96
|
|
|
97
97
|
A IIIF `Collection`, following the IIIF Presentation API 2 or 3, depending of the value of `iiif_version`.
|
|
98
98
|
|
|
@@ -110,7 +110,7 @@ POST /manifests/{iiif_version}/create
|
|
|
110
110
|
- `iiif_version` (`2 | 3`): the IIIF Presentation API version of your manifest
|
|
111
111
|
- Body (`JSON`): the manifest to index in the database
|
|
112
112
|
|
|
113
|
-
####
|
|
113
|
+
#### Response
|
|
114
114
|
|
|
115
115
|
```
|
|
116
116
|
{
|
|
@@ -142,12 +142,35 @@ GET /annotations/{iiif_version}/search
|
|
|
142
142
|
- `uri` (`string`): the URI of the target canvas
|
|
143
143
|
- `asAnnotationList` (`true | false`): format of the response
|
|
144
144
|
|
|
145
|
-
####
|
|
145
|
+
#### Response
|
|
146
146
|
|
|
147
147
|
`Object[] | Object`: if `true`, return an array of annotations. Otherwise, return an `AnnotationList`.
|
|
148
148
|
|
|
149
149
|
---
|
|
150
150
|
|
|
151
|
+
### Count annotations
|
|
152
|
+
|
|
153
|
+
```
|
|
154
|
+
GET /annotations/{iiif_version}/count
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
#### Request
|
|
158
|
+
|
|
159
|
+
- Variables:
|
|
160
|
+
- `iiif_version` (`2 | 3`): the IIIF Presentation API of your manifests
|
|
161
|
+
- Parameters:
|
|
162
|
+
- `uri` (`string`): the annotation's `@id`
|
|
163
|
+
- `canvasUri` (`string`): the annotation's target canvas (`on.full`)
|
|
164
|
+
- `manifestShortId` (`string`): the short ID of the annotation's target manifest (`on.manifestShortId`)
|
|
165
|
+
|
|
166
|
+
#### Response
|
|
167
|
+
|
|
168
|
+
```
|
|
169
|
+
{ count: integer }
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
---
|
|
173
|
+
|
|
151
174
|
### Get a single annotation
|
|
152
175
|
|
|
153
176
|
```
|
|
@@ -163,7 +186,7 @@ This route allows to query an annotation by its ID by defering its `@id | id` fi
|
|
|
163
186
|
- `manifest_short_id` (`string`): the identifier of the manifest the annotation is related to
|
|
164
187
|
- `annotation_short_id`: the unique part of the annotation URL
|
|
165
188
|
|
|
166
|
-
####
|
|
189
|
+
#### Response
|
|
167
190
|
|
|
168
191
|
`Object`: the annotation. Its format follows the IIIF Presentation specification 2 or 3, based on the value of `iiif_version`.
|
|
169
192
|
|
|
@@ -184,7 +207,7 @@ Create or update a single annotation
|
|
|
184
207
|
- `action` (`create | update`): the action to perform: create or update an annotation
|
|
185
208
|
- Body (`Object`): a IIIF annotation that follows the IIIF Presentation API 2 or 3 (depending on the value of `iiif_version`)
|
|
186
209
|
|
|
187
|
-
####
|
|
210
|
+
#### Response
|
|
188
211
|
|
|
189
212
|
```
|
|
190
213
|
{
|
|
@@ -226,7 +249,7 @@ Batch insert multiple annotations.
|
|
|
226
249
|
- `{ uri: string }`: an object containing a reference to an `AnnotationList` or `AnnotationPage`
|
|
227
250
|
- `{ uri: string }[]`: an array of objects containing a reference to an `AnnotationList` or `AnnotationPage`.
|
|
228
251
|
|
|
229
|
-
####
|
|
252
|
+
#### Response
|
|
230
253
|
|
|
231
254
|
```
|
|
232
255
|
{
|
package/package.json
CHANGED
|
@@ -201,7 +201,7 @@ class Annotations2 extends CollectionAbstract {
|
|
|
201
201
|
// 1. get all distinct manifest URIs
|
|
202
202
|
const manifestUris = [];
|
|
203
203
|
annotationData.map((ann) => ann.on.map((target) => {
|
|
204
|
-
if ( target.manifestUri
|
|
204
|
+
if ( target.manifestUri != null && !manifestUris.includes(target.manifestUri) ) {
|
|
205
205
|
manifestUris.push(target.manifestUri);
|
|
206
206
|
}
|
|
207
207
|
}));
|
|
@@ -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";
|
|
@@ -147,9 +147,11 @@ class Manifests2 extends CollectionAbstract {
|
|
|
147
147
|
const
|
|
148
148
|
mongoResponse =
|
|
149
149
|
await this.collection.find(
|
|
150
|
-
{
|
|
151
|
-
|
|
152
|
-
|
|
150
|
+
{
|
|
151
|
+
"@id": {
|
|
152
|
+
$in: cleanManifestArray.map((manifest) => manifest["@id"])
|
|
153
|
+
}
|
|
154
|
+
},
|
|
153
155
|
{ projection: { "@id": 1 } }
|
|
154
156
|
)
|
|
155
157
|
.toArray(),
|
|
@@ -206,7 +208,12 @@ class Manifests2 extends CollectionAbstract {
|
|
|
206
208
|
await Promise.all(
|
|
207
209
|
manifestUriArray.map(async (manifestUri) => {
|
|
208
210
|
try {
|
|
209
|
-
|
|
211
|
+
const r = await this.#fetchManifestFromUri(manifestUri);
|
|
212
|
+
if ( ! r.error ) {
|
|
213
|
+
manifestArray.push(r);
|
|
214
|
+
} else {
|
|
215
|
+
fetchErrorIds.push(r);
|
|
216
|
+
}
|
|
210
217
|
} catch (err) {
|
|
211
218
|
if ( throwOnError ) {
|
|
212
219
|
throw err;
|
|
@@ -218,6 +225,9 @@ class Manifests2 extends CollectionAbstract {
|
|
|
218
225
|
const result = await this.insertManifestArray(manifestArray, throwOnError);
|
|
219
226
|
// if there has been an error but error-throwing was disabled, complete the response object with description of the errors
|
|
220
227
|
if ( !throwOnError ) {
|
|
228
|
+
if ( fetchErrorIds.length ) {
|
|
229
|
+
console.error(`${this.funcName(this.insertManifestsFromUriArray)}: error inserting ${fetchErrorIds} manifests`, fetchErrorIds);
|
|
230
|
+
}
|
|
221
231
|
result.fetchErrorIds = fetchErrorIds;
|
|
222
232
|
}
|
|
223
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,
|