Skip to content

Commit

Permalink
use only BYOC bands that are returned by both Metadata API and Catalo…
Browse files Browse the repository at this point in the history
…g API
  • Loading branch information
zcernigoj committed Oct 9, 2024
1 parent b3392c5 commit 13f13c6
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 13f13c6

Please sign in to comment.