Skip to content

Commit

Permalink
formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
AmeanAsad committed Feb 1, 2024
1 parent c5577b7 commit fa4a194
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 29 deletions.
27 changes: 13 additions & 14 deletions container/shim/src/fetchers/lassie.js
Original file line number Diff line number Diff line change
Expand Up @@ -227,10 +227,10 @@ function createLassieURL(req, isRawFormat) {
}

const knownPeers = getKnownPeers(req);
const knownPeersLassieUrl = generatePeersLassieUrl(knownPeers)
const knownPeersLassieUrl = generatePeersLassieUrl(knownPeers);

if (knownPeersLassieUrl) {
lassieUrl.searchParams.set("providers", knownPeersLassieUrl)
lassieUrl.searchParams.set("providers", knownPeersLassieUrl);
}

return lassieUrl;
Expand Down Expand Up @@ -308,25 +308,24 @@ async function getRequestedBlockFromCar(streamIn, streamOut, cidObj, filename) {
}

function generatePeersLassieUrl(knownPeers) {

const peerUrls = []
const peerUrls = [];
if (knownPeers) {
const knownPeerList = []
const knownPeerList = [];
Object.values(knownPeers).forEach((peerList) => {
knownPeerList.push(...peerList)
})
knownPeerList.push(...peerList);
});

knownPeerList.forEach((peer, idx) => {
const { peerID, multiaddr, protocol } = peer
const { peerID, multiaddr, protocol } = peer;
if (!peerID || !multiaddr || !protocol) {
return
return;
}
const peerUrl = multiaddr.startsWith('http') ? multiaddr : `${multiaddr}/p2p/${peerID}+${protocol}`
peerUrls.push(peerUrl)
})
const peerUrl = multiaddr.startsWith("http") ? multiaddr : `${multiaddr}/p2p/${peerID}+${protocol}`;
peerUrls.push(peerUrl);
});
}
const urlString = peerUrls.join(',')
return urlString
const urlString = peerUrls.join(",");
return urlString;
}

async function queueMetricsReport(newMetric) {
Expand Down
29 changes: 14 additions & 15 deletions container/shim/src/utils/jwt.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,23 @@
import jwt from "jsonwebtoken";
import jwt from "jsonwebtoken";

export function findJWT(req) {
const jwtQuery = req.variables.arg_jwt;
const jwtQuery = req.variables.arg_jwt;

let jwtHeader = "";
const authHeader = req.variables.http_authorization;
if (authHeader) {
jwtHeader = authHeader.replace("Bearer ", "");
}
let jwtHeader = "";
const authHeader = req.variables.http_authorization;
if (authHeader) {
jwtHeader = authHeader.replace("Bearer ", "");
}

return jwtQuery || jwtHeader;
return jwtQuery || jwtHeader;
}


export function getKnownPeers(req) {
const reqJwt = findJWT(req)
const reqJwt = findJWT(req);
if (reqJwt) {
const jwtObject = jwt.decode(reqJwt)
const knownPeers = jwtObject.knownPeers
return knownPeers
const jwtObject = jwt.decode(reqJwt);
const knownPeers = jwtObject.knownPeers;
return knownPeers;
}
return null
}
return null;
}

0 comments on commit fa4a194

Please sign in to comment.