-
Notifications
You must be signed in to change notification settings - Fork 149
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1496 from RoboSats/fix-robohash-generator
Fix Robohash generation on web
- Loading branch information
Showing
2 changed files
with
61 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 8 additions & 10 deletions
18
frontend/src/services/Roboidentities/RoboidentitiesWebClient/robohash.worker.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,15 @@ | ||
import { async_generate_robohash } from 'robo-identities-wasm'; | ||
|
||
// Listen for messages from the main thread | ||
self.addEventListener('message', (event) => { | ||
void (async () => { | ||
const { hash, size, cacheKey } = event.data; | ||
|
||
self.onmessage = async (event) => { | ||
if (!event.data) return; | ||
try { | ||
const { hash, size, cacheKey } = event.data.robohash; | ||
// Generate the image using async_image_base | ||
const t0 = performance.now(); | ||
const avatarB64: string = await async_generate_robohash(hash, size === 'small' ? 80 : 256); | ||
const imageUrl = `data:image/png;base64,${avatarB64}`; | ||
const t1 = performance.now(); | ||
console.log(`Avatar generated in: ${t1 - t0} ms`); | ||
// Send the result back to the main thread | ||
self.postMessage({ cacheKey, imageUrl }); | ||
})(); | ||
}); | ||
} catch (error) { | ||
console.error('Wasm error:', error); | ||
} | ||
}; |