From f8a63fb4133cae147e103f3f889c939e66ac5608 Mon Sep 17 00:00:00 2001 From: funkydunc Date: Tue, 21 Jan 2025 16:33:40 +0000 Subject: [PATCH 1/2] local tweaked file to extract thumbnail --- apps/iiif/.iiifrc-base.yml | 7 ++- apps/iiif/scripts/extract-thumbnail-local.js | 56 ++++++++++++++++++++ 2 files changed, 62 insertions(+), 1 deletion(-) create mode 100644 apps/iiif/scripts/extract-thumbnail-local.js diff --git a/apps/iiif/.iiifrc-base.yml b/apps/iiif/.iiifrc-base.yml index dbe28ada..0d683ee2 100644 --- a/apps/iiif/.iiifrc-base.yml +++ b/apps/iiif/.iiifrc-base.yml @@ -9,13 +9,18 @@ run: - extract-slug-source - delft-extract-labels - extract-part-of-collection - - extract-thumbnail + - extract-thumbnail-local - manifest-sqlite - metadata-analysis - site-collections - delft-image-source - typesense-manifests +config: + extract-thumbnail-local: + width: 1080 + height: 1080 + stores: collective-access: type: iiif-json diff --git a/apps/iiif/scripts/extract-thumbnail-local.js b/apps/iiif/scripts/extract-thumbnail-local.js new file mode 100644 index 00000000..160fd626 --- /dev/null +++ b/apps/iiif/scripts/extract-thumbnail-local.js @@ -0,0 +1,56 @@ +import { createThumbnailHelper } from "@iiif/helpers"; +import { extract } from "iiif-hss"; + +extract({ + id: "extract-thumbnail-local", + name: "Extract Thumbnail", + types: ["Manifest"], + invalidate: async (resource, api, config) => { + const cache = await api.caches.value; + return !cache.extractThumbnail && cache.extractThumbnail !== false; + }}, + async (resource, api, config) => { + const vault = resource.vault; + const helper = createThumbnailHelper(vault); + const thumbnail = await helper.getBestThumbnailAtSize( + api.resource, + config.width + ? { + width: config.width, + height: config.height || config.width, + } + : { + width: 256, + height: 256, + }, + config.dereference || false + ); + + if (thumbnail?.best) { + return { + meta: { thumbnail: thumbnail.best }, + caches: { extractThumbnail: true }, + }; + } + else { + const thumbnail = await helper.getBestThumbnailAtSize( + api.resource, { + width: 256, + height: 256, + }, + config.dereference || false + ); + + if (thumbnail?.best) { + return { + meta: { thumbnail: thumbnail.best }, + caches: { extractThumbnail: true }, + }; + } + } + + return { + caches: { extractThumbnail: false }, + }; + }, +) \ No newline at end of file From 4e2001a42a2805af908f718d2251bef527db07d3 Mon Sep 17 00:00:00 2001 From: funkydunc Date: Wed, 22 Jan 2025 14:46:04 +0000 Subject: [PATCH 2/2] fix currently unused loadCollectionMeta --- apps/static-site/src/iiif.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/apps/static-site/src/iiif.ts b/apps/static-site/src/iiif.ts index b0341cc2..de4e28ae 100644 --- a/apps/static-site/src/iiif.ts +++ b/apps/static-site/src/iiif.ts @@ -24,8 +24,10 @@ export async function loadCollection(slug: string) { export async function loadCollectionMeta(slug: string) { const resp = await fetch(`${IIIF_URL}${slug}/meta.json`); + if (resp.ok) { - return resp.json(); + const json = await resp.json(); + return json; } }