From 83bcf00701c3c08941db9e038b9ce7b033228164 Mon Sep 17 00:00:00 2001 From: William Valencia Date: Thu, 22 Aug 2024 18:04:56 -0400 Subject: [PATCH] CMR-10043: Adding browse asset to items --- src/domains/stac.ts | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) 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.