-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
local tweaked file to extract thumbnail
- Loading branch information
Showing
2 changed files
with
62 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 }, | ||
}; | ||
}, | ||
) |