Skip to content

Commit

Permalink
update production to uHTTP v3
Browse files Browse the repository at this point in the history
  • Loading branch information
esterlus committed May 30, 2024
1 parent 0825072 commit 8541274
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 32 deletions.
2 changes: 1 addition & 1 deletion frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"version": "0.2.0",
"private": true,
"dependencies": {
"@hoprnet/phttp-lib": "^2.0.4",
"@hoprnet/phttp-lib": "^3.0.1",
"@testing-library/jest-dom": "^5.17.0",
"@testing-library/react": "^13.4.0",
"@testing-library/user-event": "^13.5.0",
Expand Down
26 changes: 8 additions & 18 deletions frontend/src/Icon.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,9 @@ function Icon(props) {
set_ethAddress(ethAddress);
try {
const rez = await fetch(`https://${props.serverurl}/logo/${ethAddress}`, { cache: "no-store" })
const base64 = await rez.text();
if(base64 && base64.includes('base64')) {
console.log('Got icon', ethAddress, base64);
set_icon(base64);
}
const blob = await rez.blob();
const icon = URL.createObjectURL(blob);
set_icon(icon);
} catch (e) {
console.warn(`No icon for ${ethAddress}`, e)
}
Expand All @@ -32,20 +30,12 @@ function Icon(props) {
async function getIcon_uHTTP(ethAddress) {
set_ethAddress(ethAddress);
try {
props.uHTTP
.fetch(`https://${props.serverurl}/logo/${ethAddress}`)
.then(async (resp) => {
const base64 = resp.text;
if(base64 && base64.includes('base64')) {
console.log('Got icon through uHTTP', ethAddress, base64);
set_icon(base64);
}
})
.catch((err) => {
console.error('uHTTP error:', err);
});
const rez = await props.uHTTP.fetch(`https://${props.serverurl}/logo/${ethAddress}`)
const blob = await rez.blob();
const icon = URL.createObjectURL(blob);
set_icon(icon);
} catch (e) {
console.warn(`No icon for ${ethAddress}`, e)
console.warn(`[uHTTP] No icon for ${ethAddress}`, e)
}
}

Expand Down
8 changes: 4 additions & 4 deletions frontend/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1319,10 +1319,10 @@
"@noble/curves" "^1.3.0"
"@noble/hashes" "^1.3.3"

"@hoprnet/phttp-lib@^2.0.4":
version "2.0.4"
resolved "https://registry.yarnpkg.com/@hoprnet/phttp-lib/-/phttp-lib-2.0.4.tgz#8d7c70f749ee396f5296720d899afe969feffac9"
integrity sha512-+slydvfmr0X/k/rUO7CHPpSrXkmtIPwsMOOWhuTLNCBonf/PcupQQNipF/fKSrB0z3oOUqxyRuvOv/P8Qe4WXg==
"@hoprnet/phttp-lib@^3.0.1":
version "3.0.1"
resolved "https://registry.yarnpkg.com/@hoprnet/phttp-lib/-/phttp-lib-3.0.1.tgz#2204a45c08829db85b009d5fd9d504a6c59f460f"
integrity sha512-+YIYJjetF/oxj06pAuHxjPlffQcMiXoJJRn2QStiriV8IarRL/bm4OnS3GOiqacLrHIt6vVrARCgTb0cagkC4Q==
dependencies:
"@hoprnet/phttp-crypto" "^1.0.0"
debug "^4.3.4"
Expand Down
12 changes: 3 additions & 9 deletions server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,15 +74,9 @@ export async function handleRequest(

async function fetchLogo(url: string, request: WorkerRequest) {
return fetch(url, request).then(async function (response) {
const blob = await response.blob();
let buffer = Buffer.from(await blob.arrayBuffer());
const base64 = "data:" + blob.type + ';base64,' + buffer.toString('base64');
return new Response(base64, {
status: 200,
headers: {
'Access-Control-Allow-Origin': '*',
}
});
const headers = new Headers(response.headers);
headers.set('Access-Control-Allow-Origin', '*');
return new Response(response.body, { headers });
});
}

Expand Down

0 comments on commit 8541274

Please sign in to comment.