this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Debug (#8888)

* Swap URL

* Add debug

authored by

Eric Bailey and committed by
GitHub
3b7b93a4 99d75708

+50 -6
+2
src/logger/metrics.ts
··· 480 480 * Specifically for the `BlockedGeoOverlay` 481 481 */ 482 482 'blockedGeoOverlay:shown': {} 483 + 484 + 'geo:debug': {} 483 485 }
+48 -6
src/state/geolocation.tsx
··· 5 5 import {logger} from '#/logger' 6 6 import {type Device, device} from '#/storage' 7 7 8 + const IPCC_URL = `https://bsky.app/ipcc` 9 + const BAPP_CONFIG_URL = `https://bapp-config.bsky.workers.dev/config` 10 + 8 11 const events = new EventEmitter() 9 12 const EVENT = 'geolocation-updated' 10 13 const emitGeolocationUpdate = (geolocation: Device['geolocation']) => { ··· 29 32 isAgeRestrictedGeo: false, 30 33 } 31 34 32 - async function getGeolocation(): Promise<Device['geolocation']> { 33 - const res = await fetch(`https://bsky.app/ipcc`) 35 + function sanitizeGeolocation( 36 + geolocation: Device['geolocation'], 37 + ): Device['geolocation'] { 38 + return { 39 + countryCode: geolocation?.countryCode ?? undefined, 40 + isAgeBlockedGeo: geolocation?.isAgeBlockedGeo ?? false, 41 + isAgeRestrictedGeo: geolocation?.isAgeRestrictedGeo ?? false, 42 + } 43 + } 44 + 45 + async function getGeolocation(url: string): Promise<Device['geolocation']> { 46 + const res = await fetch(url) 34 47 35 48 if (!res.ok) { 36 49 throw new Error(`geolocation: lookup failed ${res.status}`) ··· 43 56 countryCode: json.countryCode, 44 57 isAgeBlockedGeo: json.isAgeBlockedGeo ?? false, 45 58 isAgeRestrictedGeo: json.isAgeRestrictedGeo ?? false, 59 + // @ts-ignore 60 + regionCode: json.regionCode ?? undefined, 46 61 } 47 62 } else { 48 63 return undefined 49 64 } 50 65 } 51 66 67 + async function compareWithIPCC(bapp: Device['geolocation']) { 68 + try { 69 + const ipcc = await getGeolocation(IPCC_URL) 70 + 71 + if (!ipcc || !bapp) return 72 + 73 + logger.metric( 74 + 'geo:debug', 75 + { 76 + bappCountryCode: bapp.countryCode, 77 + // @ts-ignore 78 + bappRegionCode: bapp.regionCode, 79 + bappIsAgeBlockedGeo: bapp.isAgeBlockedGeo, 80 + bappIsAgeRestrictedGeo: bapp.isAgeRestrictedGeo, 81 + ipccCountryCode: ipcc.countryCode, 82 + ipccIsAgeBlockedGeo: ipcc.isAgeBlockedGeo, 83 + ipccIsAgeRestrictedGeo: ipcc.isAgeRestrictedGeo, 84 + }, 85 + { 86 + statsig: false, 87 + }, 88 + ) 89 + } catch {} 90 + } 91 + 52 92 /** 53 93 * Local promise used within this file only. 54 94 */ ··· 81 121 82 122 try { 83 123 // Try once, fail fast 84 - const geolocation = await getGeolocation() 124 + const geolocation = await getGeolocation(BAPP_CONFIG_URL) 85 125 if (geolocation) { 86 - device.set(['geolocation'], geolocation) 126 + device.set(['geolocation'], sanitizeGeolocation(geolocation)) 87 127 emitGeolocationUpdate(geolocation) 88 128 logger.debug(`geolocation: success`, {geolocation}) 129 + compareWithIPCC(geolocation) 89 130 } else { 90 131 // endpoint should throw on all failures, this is insurance 91 132 throw new Error(`geolocation: nothing returned from initial request`) ··· 101 142 device.set(['geolocation'], DEFAULT_GEOLOCATION) 102 143 103 144 // retry 3 times, but don't await, proceed with default 104 - networkRetry(3, getGeolocation) 145 + networkRetry(3, () => getGeolocation(BAPP_CONFIG_URL)) 105 146 .then(geolocation => { 106 147 if (geolocation) { 107 - device.set(['geolocation'], geolocation) 148 + device.set(['geolocation'], sanitizeGeolocation(geolocation)) 108 149 emitGeolocationUpdate(geolocation) 109 150 logger.debug(`geolocation: success`, {geolocation}) 110 151 success = true 152 + compareWithIPCC(geolocation) 111 153 } else { 112 154 // endpoint should throw on all failures, this is insurance 113 155 throw new Error(`geolocation: nothing returned from retries`)