Skip to content
This repository was archived by the owner on Aug 30, 2022. It is now read-only.

Commit cadbc27

Browse files
add timeout for source fetching
1 parent e57956b commit cadbc27

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

src/common/feature-detection.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,9 +288,17 @@ export async function fetchSourceFilesFromMetadata(
288288
const ipfsLink = urls.find((url) => url.includes("ipfs"));
289289
if (ipfsLink) {
290290
const ipfsHash = ipfsLink.split("ipfs/")[1];
291+
// 5 sec timeout for sources that haven't been uploaded to ipfs
292+
const timeout = new Promise<string>((_r, rej) =>
293+
setTimeout(() => rej("timeout"), 5000),
294+
);
295+
const source = await Promise.race([
296+
storage.getRaw(`ipfs://${ipfsHash}`),
297+
timeout,
298+
]);
291299
return {
292300
filename: path,
293-
source: await storage.getRaw(`ipfs://${ipfsHash}`),
301+
source,
294302
};
295303
} else {
296304
return {

0 commit comments

Comments
 (0)