File tree Expand file tree Collapse file tree 2 files changed +34
-5
lines changed Expand file tree Collapse file tree 2 files changed +34
-5
lines changed Original file line number Diff line number Diff line change 1+ import { NormalizedEntity } from "@iiif/vault/*" ;
2+ import { useViewerState } from "src/context/viewer-context" ;
3+
4+ declare type ExtendedNormalizedEntity = NormalizedEntity & { id : string } ;
5+
6+ export default function useGetVaultEntityId ( id ?: string ) : string | undefined {
7+ const { vault } = useViewerState ( ) ;
8+
9+ try {
10+ const entity : ExtendedNormalizedEntity | undefined | "" =
11+ id && vault . get ( id ) ;
12+
13+ if ( ! entity ) throw new Error ( `Vault entity ${ id } not found.` ) ;
14+
15+ /**
16+ * Vault seems to handle storage `id` and `@id` differently based on the entity type.
17+ * Ex: Manifest level rendering items use `id` while Canvas level rendering items use `@id`.
18+ * The following logic returns `@id` if it exists, otherwise falls back to `id`.
19+ */
20+ return entity ?. [ "@id" ] || entity ?. id ;
21+ } catch ( error ) {
22+ console . error ( error ) ;
23+ return id ;
24+ }
25+ }
Original file line number Diff line number Diff line change 11import { RenderingItem } from "src/types/presentation-3" ;
22import { getLabelAsString } from "src/lib/label-helpers" ;
3+ import useGetVaultEntityId from "src/hooks/useGetVaultEntityId" ;
34import useRendering from "src/hooks/use-iiif/useRendering" ;
45
56type DownloadItem = {
@@ -12,11 +13,14 @@ function prepareDownloadLinks(
1213 items : RenderingItem [ ] ,
1314 defaultLabel : string ,
1415) : DownloadItem [ ] {
15- return items . map ( ( { format, id, label } ) => ( {
16- format,
17- id,
18- label : getLabelAsString ( label ) || defaultLabel ,
19- } ) ) ;
16+ return items . map ( ( { format, id, label } ) => {
17+ const resourceId = useGetVaultEntityId ( id ) ;
18+ return {
19+ format,
20+ id : resourceId ,
21+ label : getLabelAsString ( label ) || defaultLabel ,
22+ } ;
23+ } ) ;
2024}
2125
2226export default function useViewerDownload ( ) {
You can’t perform that action at this time.
0 commit comments