|
1 | 1 | export const extractProjectIdFromAccessKey = (accessKey: string): number => { |
2 | | - // Convert URL-safe base64 string to standard base64 string |
3 | | - const base64String = accessKey.replace(/-/g, '+').replace(/_/g, '/'); |
4 | | - // Decode the base64 string to a binary string |
5 | | - const binaryString = atob(base64String); |
| 2 | + // Convert URL-safe base64 string to standard base64 string |
| 3 | + const base64String = accessKey.replace(/-/g, '+').replace(/_/g, '/') |
| 4 | + // Decode the base64 string to a binary string |
| 5 | + const binaryString = atob(base64String) |
6 | 6 |
|
7 | | - // Convert the binary string to a byte array (Uint8Array) |
8 | | - const byteArray = new Uint8Array(binaryString.length); |
9 | | - for (let i = 0; i < binaryString.length; i++) { |
10 | | - byteArray[i] = binaryString.charCodeAt(i); |
11 | | - } |
| 7 | + // Convert the binary string to a byte array (Uint8Array) |
| 8 | + const byteArray = new Uint8Array(binaryString.length) |
| 9 | + for (let i = 0; i < binaryString.length; i++) { |
| 10 | + byteArray[i] = binaryString.charCodeAt(i) |
| 11 | + } |
12 | 12 |
|
13 | | - if (byteArray[0] !== 1) { |
14 | | - throw new Error('UnsupportedVersion'); |
15 | | - } |
| 13 | + if (byteArray[0] !== 1) { |
| 14 | + throw new Error('UnsupportedVersion') |
| 15 | + } |
16 | 16 |
|
17 | | - // Extract the project ID from bytes 2 to 9 (8 bytes) |
18 | | - const projectIdBytes = byteArray.slice(1, 9); |
19 | | - const projectId = projectIdBytes[7] | projectIdBytes[6]<<8 | projectIdBytes[5]<<16 | projectIdBytes[4]<<24 | |
20 | | - projectIdBytes[3]<<32 | projectIdBytes[2]<<40 | projectIdBytes[1]<<48 | projectIdBytes[0]<<56; |
| 17 | + // Extract the project ID from bytes 2 to 9 (8 bytes) |
| 18 | + const projectIdBytes = byteArray.slice(1, 9) |
| 19 | + const projectId = |
| 20 | + projectIdBytes[7] | |
| 21 | + (projectIdBytes[6] << 8) | |
| 22 | + (projectIdBytes[5] << 16) | |
| 23 | + (projectIdBytes[4] << 24) | |
| 24 | + (projectIdBytes[3] << 32) | |
| 25 | + (projectIdBytes[2] << 40) | |
| 26 | + (projectIdBytes[1] << 48) | |
| 27 | + (projectIdBytes[0] << 56) |
21 | 28 |
|
22 | | - return projectId; |
| 29 | + return projectId |
23 | 30 | } |
0 commit comments