Skip to content

Commit 3831e95

Browse files
authored
disable thumbnail by default (#889)
* disable thumbnail by default * add test for disabling thumbnails
1 parent fcca9d5 commit 3831e95

File tree

3 files changed

+34
-5
lines changed

3 files changed

+34
-5
lines changed

README.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
- [Architecture](#architecture)
1010
- [Migration](#migration)
1111
- [Warnings](#warnings)
12+
- [4.1.0](#410)
13+
- [Thumbnails feature disabled by default](#thumbnails-feature-disabled-by-default)
1214
- [4.0.0](#400)
1315
- [Context Extension disabled by default](#context-extension-disabled-by-default)
1416
- [Node 22 update](#node-22-update)
@@ -170,6 +172,13 @@ apiLambda --> opensearch
170172
name, reindex the existing index into the newly-created index, delete and re-created
171173
the existing index by creating a collection, and reindex back into the index.
172174

175+
### 4.1.0
176+
177+
#### Thumbnails feature disabled by default
178+
179+
The thumbnails behavior is now disabled by default, and can be enabled with
180+
`ENABLE_THUMBNAILS` = `true`.
181+
173182
### 4.0.0
174183

175184
#### Context Extension disabled by default
@@ -417,7 +426,8 @@ Properties: . . .
417426
#### Granting Access for Thumbnails
418427

419428
The new experimental endpoint `/collections/{c_id}/items/{item_id}/thumbnail` will
420-
redirect to a URL providing a thumbnail as determined by the assets in an item. If the
429+
redirect to a URL providing a thumbnail as determined by the assets in an item. This is
430+
enabled only if `ENABLE_THUMBNAILS` is set to `true`. If the
421431
href for this is an AWS S3 ARN, IAM permissions must be granted for the API Lambda to
422432
generate a pre-signed HTTP URL instead. For example:
423433

@@ -599,6 +609,7 @@ There are some settings that should be reviewed and updated as needeed in the se
599609
| CORS_METHODS | Configure whether or not to send the `Access-Control-Allow-Methods` CORS header. Expects a comma-delimited string, e.g., `GET,PUT,POST`. | `GET,HEAD,PUT,PATCH,POST,DELETE` |
600610
| CORS_HEADERS | Configure whether or not to send the `Access-Control-Allow-Headers` CORS header. Expects a comma-delimited string, e.g., `Content-Type,Authorization`. If not specified, defaults to reflecting the headers specified in the request’s `Access-Control-Request-Headers` header. | none |
601611
| ENABLE_COLLECTIONS_AUTHX | Enables support for hidden `_collections` query parameter / field when set to `true`. | none |
612+
| ENABLE_THUMBNAILS | Enables support for presigned thumnails. | none |
602613

603614
Additionally, the credential for OpenSearch must be configured, as decribed in the
604615
section [Populating and accessing credentials](#populating-and-accessing-credentials).

src/lib/api.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -484,10 +484,12 @@ export const addItemLinks = function (results, endpoint) {
484484
type: 'application/json',
485485
href: `${endpoint}`
486486
})
487-
links.push({
488-
rel: 'thumbnail',
489-
href: `${endpoint}/collections/${collection}/items/${id}/thumbnail`
490-
})
487+
if (process.env['ENABLE_THUMBNAILS'] === 'true') {
488+
links.push({
489+
rel: 'thumbnail',
490+
href: `${endpoint}/collections/${collection}/items/${id}/thumbnail`
491+
})
492+
}
491493
result.type = 'Feature'
492494
return result
493495
})
@@ -1312,6 +1314,10 @@ const deleteItem = async function (collectionId, itemId, backend) {
13121314
}
13131315

13141316
const getItemThumbnail = async function (collectionId, itemId, backend, queryParameters) {
1317+
if (process.env['ENABLE_THUMBNAILS'] !== 'true') {
1318+
return new NotFoundError()
1319+
}
1320+
13151321
if (!isCollectionIdAllowed(extractAllowedCollectionIds(queryParameters), collectionId)) {
13161322
return new NotFoundError()
13171323
}

tests/system/test-api-item-get.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ test('GET /collections/:collectionId/items/:itemId with restriction returns filt
122122

123123
test('GET /collections/:collectionId/items/:itemId/thumbnail with restriction returns filtered collections', async (t) => {
124124
process.env['ENABLE_COLLECTIONS_AUTHX'] = 'true'
125+
process.env['ENABLE_THUMBNAILS'] = 'true'
125126

126127
const { collectionId, itemId } = t.context
127128

@@ -159,3 +160,14 @@ test('GET /collections/:collectionId/items/:itemId/thumbnail with restriction re
159160
searchParams: { _collections: 'not-a-collection' }
160161
})).statusCode, 404)
161162
})
163+
164+
test('GET /collections/:collectionId/items/:itemId/thumbnail disabled', async (t) => {
165+
process.env['ENABLE_THUMBNAILS'] = 'false'
166+
167+
const { collectionId, itemId } = t.context
168+
169+
const path = `collections/${collectionId}/items/${itemId}/thumbnail`
170+
171+
t.is((await t.context.api.client.get(path,
172+
{ resolveBodyOnly: false, throwHttpErrors: false })).statusCode, 404)
173+
})

0 commit comments

Comments
 (0)