Skip to content

Commit 527f162

Browse files
committed
chore: apply minor fixes suggested by reviewer
1 parent d92fbb8 commit 527f162

File tree

10 files changed

+106
-114
lines changed

10 files changed

+106
-114
lines changed

package.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,10 @@
4545
"base-64": "^1.0.0",
4646
"crypto": "^1.0.1",
4747
"crypto-browserify": "^3.12.0",
48-
"crypto-js": "^4.2.0",
4948
"date-fns": "^2.29.3",
5049
"esbuild": "0.17.11",
51-
"husky": "^9.1.7",
50+
"fast-deep-equal": "^3.1.3",
5251
"ky": "^0.33.2",
53-
"lodash": "^4.17.21",
5452
"mapbox-gl": "^2.13.0",
5553
"mapbox-gl-draw-rectangle-mode": "^1.0.4",
5654
"mapbox-gl-draw-rectangle-restrict-area": "3.1.5",

src/archive-apis/search-apollo.tsx

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,24 @@ import { Providers, maxAbs, filterFeaturesWithSearchParams, processInChunks } fr
55
import { v4 as uuidv4 } from 'uuid'
66
import bboxPolygon from '@turf/bbox-polygon'
77
import { log } from '../utilities'
8-
import type GeoJSON from 'react-map-gl'
9-
import CryptoJS from "crypto-js";
108

11-
const APOLLO_API_URL = 'https://cors-anywhere.herokuapp.com/https://imagehunter-api.apollomapping.com'
9+
const APOLLO_API_URL = 'https://imagehunter-api.apollomapping.com'
1210
const APOLLO_DOMAIN = 'https://imagehunter.apollomapping.com'
1311

1412
const searchApollo = async (searchSettings, apolloApikey, searchPolygon: any | null = null, setters: any | null = null): Promise<any> => {
1513

16-
const generateXAuthToken = (): string => {
14+
const generateXAuthToken = async (): Promise<string> => {
1715
const now = new Date();
1816
const day = now.getUTCDate();
1917
const hour = now.getUTCHours();
2018
const secret = "iGsZ1wMw8xERUZrxNPvBt2TlFTFcN3P2";
2119
const raw = `${day}${hour}${secret}`;
22-
const hash = CryptoJS.SHA256(raw).toString();
23-
return hash;
20+
const msgUint8 = new TextEncoder().encode(raw); // encode string to Uint8Array
21+
const hashBuffer = await window.crypto.subtle.digest("SHA-256", msgUint8); // hash
22+
const hashArray = Array.from(new Uint8Array(hashBuffer)); // buffer -> byte array
23+
const hashHex = hashArray.map(b => b.toString(16).padStart(2, "0")).join(""); // byte array -> hex string
24+
25+
return hashHex;
2426
}
2527

2628
const apolloPayload = {
@@ -39,6 +41,7 @@ const searchApollo = async (searchSettings, apolloApikey, searchPolygon: any | n
3941
stereo: false,
4042
seasonal: false,
4143
}
44+
4245
const apolloPayloadBody = new URLSearchParams(apolloPayload as any).toString()
4346
// Better have a look at maxar payload construction
4447

@@ -48,8 +51,7 @@ const searchApollo = async (searchSettings, apolloApikey, searchPolygon: any | n
4851
// Tried using a CORS proxy, with no luck like [cors-anywhere](https://github.com/Rob--W/cors-anywhere/#documentation) public one or [allorigins](https://allorigins.win/) or any recent one listed [here](https://nordicapis.com/10-free-to-use-cors-proxies/)
4952

5053
const apolloRequest = `${APOLLO_API_URL}/ajax/search`
51-
const token = generateXAuthToken();
52-
54+
const token = await generateXAuthToken()
5355
const apolloResultsRaw = await ky
5456
.post(apolloRequest, {
5557
headers: {
@@ -58,7 +60,7 @@ const searchApollo = async (searchSettings, apolloApikey, searchPolygon: any | n
5860
Referer: APOLLO_DOMAIN,
5961
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
6062
'Content-Length': `${apolloPayloadBody.length}`,
61-
"x-auth-token": token,
63+
"X-Auth-Token": token,
6264
},
6365
body: apolloPayloadBody,
6466
})

src/archive-apis/search-skyfi.tsx

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ import { parse as wkt_parse, stringify as wkt_stringify } from 'wellknown'
1717
console.log('start');
1818

1919
// const SKYFI_SEARCH_URL = 'https://app.skyfi.com/api/archive-available'
20-
const SKYFI_SEARCH_URL ='https://app.skyfi.com/platform-api/archives'
20+
const SKYFI_SEARCH_URL = 'https://app.skyfi.com/platform-api/archives'
2121
const pageSize = 25
2222
const lookForNextPage = true
23-
const skyfiApiKey = '0ce62eb53c044ce78872b301810962f8'
23+
const skyfiApiKey = process.env.SKYFI_API_KEY
2424

2525
// Not useful at the moment
2626
// const getSkyfiBearer = (apikey): string => {
@@ -61,12 +61,12 @@ const searchSkyfi = async (searchSettings, skyfiApikey, searchPolygon = null, se
6161
toDate: searchSettings.endDate.toISOString(), // "2023-01-24T10:21:44.465Z",
6262
maxCloudCoveragePercent: searchSettings.cloudCoverage,
6363
resolutions: resolutionArray,
64-
// isOpendata: false,
65-
// bandsCount: [
66-
// 1,
67-
// 3,
68-
// 4
69-
// ],
64+
// isOpendata: false,
65+
// bandsCount: [
66+
// 1,
67+
// 3,
68+
// 4
69+
// ],
7070
openData: false,
7171
// clientType: 'DESKTOP',
7272
// sensors: ['DAY', 'NIGHT', 'MULTISPECTRAL'],
@@ -81,7 +81,7 @@ const searchSkyfi = async (searchSettings, skyfiApikey, searchPolygon = null, se
8181
"VEXCEL",
8282
"NSL",
8383
"UMBRA"
84-
],
84+
],
8585
// imageCropping: {
8686
// wktString: coordinatesWkt,
8787
// },

src/archive-apis/search-skywatch.tsx

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@ const SKYWATCH_SEARCH_URL_JWT = 'https://api.skywatch.co/auth0-jwt/earthcache/ar
1414
const performSkywatchSearch = async (skywatchApikey, searchId): Promise<any> =>
1515
skywatchApikey?.includes('Bearer')
1616
? await ky.get(`${SKYWATCH_SEARCH_URL_JWT}/${searchId.data.id as string}/search_results`, {
17-
headers: { authorization: skywatchApikey },
18-
})
17+
headers: { authorization: skywatchApikey },
18+
})
1919
: await ky.get(`${SKYWATCH_SEARCH_URL}/${searchId.data.id as string}/search_results`, {
20-
headers: { 'x-api-key': skywatchApikey },
21-
})
20+
headers: { 'x-api-key': skywatchApikey },
21+
})
2222

2323
const MAX_QUERY_COUNT = 8
2424

@@ -50,20 +50,20 @@ const searchSkywatch = async (searchSettings, skywatchApikey, searchPolygon = nu
5050

5151
const searchId = skywatchApikey?.includes('Bearer')
5252
? await ky
53-
.post(SKYWATCH_SEARCH_URL_JWT, {
54-
headers: {
55-
authorization: skywatchApikey,
56-
'content-length': `${JSON.stringify(skywatchPayload).length}`,
57-
},
58-
json: skywatchPayload,
59-
})
60-
.json()
53+
.post(SKYWATCH_SEARCH_URL_JWT, {
54+
headers: {
55+
authorization: skywatchApikey,
56+
'content-length': `${JSON.stringify(skywatchPayload).length}`,
57+
},
58+
json: skywatchPayload,
59+
})
60+
.json()
6161
: await ky
62-
.post(SKYWATCH_SEARCH_URL, {
63-
headers: { 'x-api-key': skywatchApikey },
64-
json: skywatchPayload,
65-
})
66-
.json()
62+
.post(SKYWATCH_SEARCH_URL, {
63+
headers: { 'x-api-key': skywatchApikey },
64+
json: skywatchPayload,
65+
})
66+
.json()
6767
log('SKYWATCH searchId: \n', searchId, '\n')
6868

6969
let searchResultsRaw

src/archive-apis/search-up42.tsx

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
// Code for searching UP42 STAC APIpost
1+
// Code for searching UP42 STAC API
22

33
import ky from 'ky'
4-
import { getImageryPrice, up42ConstellationDict, providersDict, Providers, up42ProducersNames, processInChunks, extractUp42HostsWithGsd } from './search-utilities'
4+
import { getImageryPrice, up42ConstellationDict, providersDict, Providers, up42ProducersNames, processInChunks } from './search-utilities'
55
import { v4 as uuidv4 } from 'uuid'
66
import { log } from '../utilities'
77

@@ -289,12 +289,12 @@ async function getUp42PreviewsAsync(up42Results, up42BearerJson, chunkSize, sett
289289
const [thumbBlob, previewBlob] = await Promise.all([
290290
ky.get(previewUrls.thumbnail_uri, {
291291
headers: { Authorization: up42BearerJson },
292-
timeout: 30000,
292+
timeout: 3000,
293293
retry: 2
294294
}).blob(),
295295
ky.get(previewUrls.preview_uri, {
296296
headers: { Authorization: up42BearerJson },
297-
timeout: 30000,
297+
timeout: 3000,
298298
retry: 2
299299
}).blob()
300300
]);
@@ -312,7 +312,6 @@ async function getUp42PreviewsAsync(up42Results, up42BearerJson, chunkSize, sett
312312
{
313313
items: up42Results.features || [],
314314
chunkSize,
315-
delayBetweenChunks: 100,
316315
usePromiseAllSettled: true,
317316
onChunkComplete: () => {
318317
setters?.setSearchResults({
@@ -447,7 +446,6 @@ const getUp42PricesAsync = async (
447446
{
448447
items: up42Results.features,
449448
chunkSize,
450-
delayBetweenChunks: 0,
451449
usePromiseAllSettled: true,
452450
onChunkComplete: () => {
453451
if (setters?.setSearchResults) {
@@ -508,4 +506,28 @@ const formatUp42Results = (up42ResultsRaw, searchPolygon): GeoJSON.FeatureCollec
508506
}
509507
}
510508

511-
export { searchUp42, getUp42Bearer, getDataCollections }
509+
// utils/up42DataBuilder.js
510+
const extractUp42HostsWithGsd = (collectionsData) => {
511+
const hostMap = new Map() // Use Map to avoid duplicates and store GSD
512+
513+
collectionsData.forEach(collection => {
514+
collection.providers?.forEach(provider => {
515+
if (provider.roles?.includes('HOST')) {
516+
const hostTitle = provider.title
517+
const gsd = collection.metadata?.resolutionValue?.minimum || null
518+
// Only keep the best (smallest) GSD for each host
519+
if (!hostMap.has(hostTitle) || hostMap.get(hostTitle).gsd > gsd) {
520+
hostMap.set(hostTitle, {
521+
title: hostTitle,
522+
gsd: gsd,
523+
satellites: []
524+
})
525+
}
526+
}
527+
})
528+
})
529+
530+
return Array.from(hostMap.values())
531+
}
532+
533+
export { searchUp42, getUp42Bearer, getDataCollections, extractUp42HostsWithGsd }

src/archive-apis/search-utilities.tsx

Lines changed: 8 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -118,11 +118,11 @@ enum Providers {
118118
UP42 = 'UP42',
119119
MAXAR_DIGITALGLOBE = 'MAXAR',
120120
EOS = 'EOS',
121-
SKYWATCH = 'SKYWATCH',
121+
SKYWATCH = 'SKYWATCH - SLOW V1 API',
122122
SKYFI = 'SKYFI',
123123
OAM = 'OpenAerialMap',
124124
ARLULA = 'ARLULA',
125-
APOLLO = 'APOLLO MAPPING',
125+
// APOLLO = 'APOLLO MAPPING',
126126
STAC = 'STAC',
127127
}
128128

@@ -153,11 +153,11 @@ const providersDict = {
153153
Constellation.TripleSat,
154154
// TODO LatConnect 60
155155
],
156-
[Providers.APOLLO]: [
157-
Constellation.Pleiades,
158-
Constellation.PleiadesNeo,
159-
// TODO COMPLETE
160-
],
156+
// [Providers.APOLLO]: [
157+
// Constellation.Pleiades,
158+
// Constellation.PleiadesNeo,
159+
// // TODO COMPLETE
160+
// ],
161161
[Providers.STAC]: [Constellation.STAC],
162162
// 'SENTINELHUB': [Constellation.Pleiades, Constellation.Worldview],
163163
}
@@ -453,7 +453,6 @@ const maxarConstellationDict = providersDict[Providers.MAXAR_DIGITALGLOBE].reduc
453453
interface ChunkProcessorOptions<T> {
454454
items: T[];
455455
chunkSize: number;
456-
delayBetweenChunks?: number; // in milliseconds
457456
onChunkComplete?: (processedItems: T[], chunkIndex: number, totalChunks: number) => void | Promise<void>;
458457
usePromiseAllSettled?: boolean; // true = continue on errors, false = stop on first error
459458
}
@@ -465,7 +464,6 @@ async function processInChunks<T>(
465464
const {
466465
items,
467466
chunkSize,
468-
delayBetweenChunks = 0,
469467
onChunkComplete,
470468
usePromiseAllSettled = true
471469
} = options;
@@ -492,37 +490,10 @@ async function processInChunks<T>(
492490
if (onChunkComplete) {
493491
await onChunkComplete(chunk, chunkIndex, totalChunks);
494492
}
495-
496-
// Add delay between chunks (except for the last one)
497-
if (delayBetweenChunks > 0 && i + chunkSize < items.length) {
498-
await new Promise(resolve => setTimeout(resolve, delayBetweenChunks));
499-
}
500493
}
501494
}
502495

503-
// utils/up42DataBuilder.js
504-
export const extractUp42HostsWithGsd = (collectionsData) => {
505-
const hostMap = new Map() // Use Map to avoid duplicates and store GSD
506-
507-
collectionsData.forEach(collection => {
508-
collection.providers?.forEach(provider => {
509-
if (provider.roles?.includes('HOST')) {
510-
const hostTitle = provider.title
511-
const gsd = collection.metadata?.resolutionValue?.minimum || null
512-
// Only keep the best (smallest) GSD for each host
513-
if (!hostMap.has(hostTitle) || hostMap.get(hostTitle).gsd > gsd) {
514-
hostMap.set(hostTitle, {
515-
title: hostTitle,
516-
gsd: gsd,
517-
satellites: []
518-
})
519-
}
520-
}
521-
})
522-
})
523-
524-
return Array.from(hostMap.values())
525-
}
496+
526497

527498
export { processInChunks, type ChunkProcessorOptions };
528499

src/control-panel/api-keys-modal-component.tsx

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -77,21 +77,7 @@ function ApiKeysModalComponent(props): React.ReactElement {
7777
</Link>
7878
</Typography>
7979
</ListItem>
80-
<ListItem sx={{ display: 'list-item' }}>
81-
<Typography variant="h6">
82-
<Link href="https://imagehunter.apollomapping.com/" target="_blank">
83-
Apollo Mapping Image Hunter
84-
</Link>
85-
</Typography>
86-
</ListItem>
8780
</List>
88-
<ListItem sx={{ display: 'list-item' }}>
89-
<Typography variant="h6">
90-
<Link href="https://discover.maxar.com/" target="_blank">
91-
Maxar Discover
92-
</Link>
93-
</Typography>
94-
</ListItem>
9581

9682
<Divider variant="middle" />
9783

@@ -238,26 +224,46 @@ function ApiKeysModalComponent(props): React.ReactElement {
238224
</List>
239225

240226
<Divider variant="middle" />
227+
<List>
228+
<ListItem sx={{ display: 'list-item' }}>
229+
<Typography>Discontinued, API not maintained for APIs:</Typography>
230+
</ListItem>
231+
<ListItem sx={{ display: 'list-item' }}>
232+
<Typography variant="h6">
233+
<Link href="https://imagehunter.apollomapping.com/" target="_blank">
234+
Apollo Mapping Image Hunter
235+
</Link>
236+
</Typography>
237+
</ListItem>
238+
<ListItem sx={{ display: 'list-item' }}>
239+
<Typography variant="h6">
240+
<Link href="https://discover.maxar.com/" target="_blank">
241+
Maxar Discover
242+
</Link>
243+
</Typography>
244+
</ListItem>
245+
</List>
246+
241247
{/* <List sx={{listStyleType: 'disc' }}> */}
242248
<List>
243249
<ListItem sx={{ display: 'list-item' }}>
244-
UP42: Project ID and Project API Key can be found in the Developers section of the selected project, on the
250+
UP42: Project ID and Project API Key can be found in the Developers section of the selected project, on the{" "}
245251
<Link href="https://console.up42.com/" target="_blank">
246252
console
247253
</Link>
248254
</ListItem>
249255
<ListItem sx={{ display: 'list-item' }}>
250-
EOS api key can be found on your
256+
EOS api key can be found on your{" "}
251257
<Link href="https://api-connect.eos.com/user-dashboard/" target="_blank">
252258
user dashboard
253259
</Link>
254-
. See the
260+
. See the{" "}
255261
<Link href="https://doc.eos.com/api/#authorization-api" target="_blank">
256262
API section of the docs
257263
</Link>
258264
</ListItem>
259265
<ListItem sx={{ display: 'list-item' }}>
260-
Skywatch API key can be found on your user
266+
Skywatch API key can be found on your user {" "}
261267
<Link href="https://dashboard.skywatch.co/account/profile" target="_blank">
262268
account profile
263269
</Link>

0 commit comments

Comments
 (0)