Skip to content

Commit 2023b0c

Browse files
committed
refactor: clean up and reorganize code
1 parent 527f162 commit 2023b0c

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

src/archive-apis/search-apollo.tsx

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Code for searching APOLLO MAPPING API
22

33
import ky from 'ky'
4-
import { Providers, maxAbs, filterFeaturesWithSearchParams, processInChunks } from './search-utilities'
4+
import { Providers, maxAbs, filterFeaturesWithSearchParams, processInChunks, ComputeSha256Hash } from './search-utilities'
55
import { v4 as uuidv4 } from 'uuid'
66
import bboxPolygon from '@turf/bbox-polygon'
77
import { log } from '../utilities'
@@ -17,10 +17,7 @@ const searchApollo = async (searchSettings, apolloApikey, searchPolygon: any | n
1717
const hour = now.getUTCHours();
1818
const secret = "iGsZ1wMw8xERUZrxNPvBt2TlFTFcN3P2";
1919
const raw = `${day}${hour}${secret}`;
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
20+
const hashHex = await ComputeSha256Hash(raw)
2421

2522
return hashHex;
2623
}

src/archive-apis/search-utilities.tsx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -493,6 +493,14 @@ async function processInChunks<T>(
493493
}
494494
}
495495

496+
async function ComputeSha256Hash(message) {
497+
const msgUint8 = new TextEncoder().encode(message); // encode string to Uint8Array
498+
const hashBuffer = await window.crypto.subtle.digest("SHA-256", msgUint8); // hash
499+
const hashArray = Array.from(new Uint8Array(hashBuffer)); // buffer -> byte array
500+
const hashHex = hashArray.map(b => b.toString(16).padStart(2, "0")).join(""); // byte array -> hex string
501+
502+
return hashHex;
503+
}
496504

497505

498506
export { processInChunks, type ChunkProcessorOptions };
@@ -505,6 +513,7 @@ export {
505513
maxAbs,
506514
getConstellationName,
507515
getSatellitesRespectingGsd,
516+
ComputeSha256Hash,
508517

509518
// Enums
510519
Satellites,

0 commit comments

Comments
 (0)