Skip to content

Commit

Permalink
Merge pull request #284 from sentinel-hub/feature/get-bands-from-cata…
Browse files Browse the repository at this point in the history
…log-api

cleanup bands returned by BYOCLayer.getAvailableBands()
  • Loading branch information
zcernigoj authored Oct 11, 2024
2 parents b3392c5 + 13f13c6 commit 7aca5c0
Showing 1 changed file with 17 additions and 8 deletions.
25 changes: 17 additions & 8 deletions src/layer/BYOCLayer.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { AxiosRequestConfig } from 'axios';
import moment from 'moment';
import axios from 'axios';
import axios, { ResponseType } from 'axios';
import { Geometry } from '@turf/helpers';

import { getAuthToken } from '../auth';
Expand Down Expand Up @@ -296,14 +296,23 @@ export class BYOCLayer extends AbstractSentinelHubV3Layer {
throw new Error('Fetching available bands for ZARR not supported.');
}

const url = `${this.getSHServiceRootUrl()}api/v1/metadata/collection/${this.getTypeId()}`;
const headers = { Authorization: `Bearer ${getAuthToken()}` };
const res = await axios.get(url, {
responseType: 'json',
headers: headers,
const commonReqConfig = {
responseType: 'json' as ResponseType,
headers: { Authorization: `Bearer ${getAuthToken()}` },
...getAxiosReqParams(innerReqConfig, CACHE_CONFIG_30MIN),
});
return res.data.bands;
};

const metadataUrl = `${this.getSHServiceRootUrl()}api/v1/metadata/collection/${this.getTypeId()}`;
const metadataRes = await axios.get(metadataUrl, commonReqConfig);
const metadataBands: BYOCBand[] = metadataRes.data.bands;

const catalogUrl = `${metadataRes.data.location.catalogUrl}/collections/${this.getTypeId()}`;
const catalogRes = await axios.get(catalogUrl, commonReqConfig);
const catalogBands: { name: string }[] = catalogRes.data.summaries['eo:bands'];

// we need bands' sampleTypes that are returned from Metadata API
// but want to use only bands that are also returned from Catalog API
return metadataBands.filter((mb) => !!catalogBands.find((cb) => cb.name === mb.name));
}, reqConfig);
return bandsResponseData;
}
Expand Down

0 comments on commit 7aca5c0

Please sign in to comment.