From 37abd1a0b4d6e005ddd896733f2d6c2a13d27c61 Mon Sep 17 00:00:00 2001 From: Hayden Young Date: Fri, 12 Jan 2024 11:39:19 +0000 Subject: [PATCH] fix: Timeout is globally configurable for IPFSBlock. --- src/storage/ipfs-block.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/storage/ipfs-block.js b/src/storage/ipfs-block.js index 7375881..bbd4412 100644 --- a/src/storage/ipfs-block.js +++ b/src/storage/ipfs-block.js @@ -7,7 +7,7 @@ import { CID } from 'multiformats/cid' import { base58btc } from 'multiformats/bases/base58' -const DefaultTimeout = 5000 // 5 seconds +const DefaultTimeout = 30000 // 30 seconds /** * Creates an instance of IPFSBlockStorage. @@ -17,14 +17,17 @@ const DefaultTimeout = 5000 // 5 seconds * @param {IPFS} params.ipfs An IPFS instance. * @param {boolean} [params.pin=false] True, if the block should be pinned, * false otherwise. + * @param {number} [params.timeout=defaultTimeout] A timeout in ms. * @return {module:Storage.Storage-IPFS} An instance of IPFSBlockStorage. * @memberof module:Storage * @throw An instance of ipfs is required if params.ipfs is not specified. * @instance */ -const IPFSBlockStorage = async ({ ipfs, pin } = {}) => { +const IPFSBlockStorage = async ({ ipfs, pin, timeout } = {}) => { if (!ipfs) throw new Error('An instance of ipfs is required.') + timeout = timeout || DefaultTimeout + /** * Puts data to an IPFS block. * @function @@ -54,7 +57,7 @@ const IPFSBlockStorage = async ({ ipfs, pin } = {}) => { */ const get = async (hash) => { const cid = CID.parse(hash, base58btc) - const block = await ipfs.blockstore.get(cid, { signal: AbortSignal.timeout(DefaultTimeout) }) + const block = await ipfs.blockstore.get(cid, { signal: AbortSignal.timeout(timeout) }) if (block) { return block }