Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CMR-10042 and CMR-10043 #344

Merged
merged 8 commits into from
Aug 27, 2024
23 changes: 22 additions & 1 deletion src/domains/stac.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,27 @@
}, {} as AssetLinks);
};

/**
* Return browse assets if present.
*/
const browseAssets = (concept: Collection | Granule) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should add a unit test for this

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unit test added

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) => {

Check warning on line 109 in src/domains/stac.ts

View workflow job for this annotation

GitHub Actions / Lint (18)

'idx' is defined but never used. Allowed unused args must match /^_/u

Check warning on line 109 in src/domains/stac.ts

View workflow job for this annotation

GitHub Actions / Lint (18)

'available' is defined but never used. Allowed unused args must match /^_/u
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.
*/
Expand Down Expand Up @@ -144,7 +165,7 @@
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.
Expand Down
5 changes: 5 additions & 0 deletions src/routes/browse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,11 @@ export const collectionsHandler = async (req: Request, res: Response): Promise<v
href: encodeURI(stacRoot),
type: "application/json",
});
collection.links.push({
rel: "items",
href: `${self}/${encodeURIComponent(collection.id)}/items`,
type: "application/json",
});
});

const links = collectionLinks(req, cursor);
Expand Down
Loading