diff --git a/src/domains/stac.ts b/src/domains/stac.ts index ad627df4..ce35778b 100644 --- a/src/domains/stac.ts +++ b/src/domains/stac.ts @@ -97,6 +97,27 @@ const thumbnailAssets = (concept: Collection | Granule) => { }, {} as AssetLinks); }; +/** + * Return browse assets if present. + */ +const browseAssets = (concept: Collection | Granule) => { + const browseTypes = [RelatedUrlType.GET_RELATED_VISUALIZATION]; + return (concept.relatedUrls ?? []) + .filter((relatedUrl) => + browseTypes.find((browseType) => (browseType === relatedUrl["type"] && relatedUrl.url.startsWith("http"))) + ) + .reduce((metadataAssets, relatedUrl, idx, available) => { + const browseAsset: AssetLinks = {}; + browseAsset[`browse`] = { + href: relatedUrl.url, + title: `Download ${relatedUrl.url.split("/").at(-1)}`, + type: "image/jpeg", + roles: ["browse"], + }; + return { ...metadataAssets, ...browseAsset }; + }, {} as AssetLinks); + }; + /** * Reducer for s3 buckets. */ @@ -144,7 +165,7 @@ const s3Assets = (concept: Collection | Granule) => { return s3Assets; }; -const defaultExtractors = [thumbnailAssets, downloadAssets, metadataAssets, s3Assets]; +const defaultExtractors = [browseAssets, thumbnailAssets, downloadAssets, metadataAssets, s3Assets]; /** * Given a concept and a list of asset extractors return available assets.