From 01b57e2d6616631b2b4a484a46fd14e385aa8a0b Mon Sep 17 00:00:00 2001 From: Steven Vandevelde Date: Mon, 29 Aug 2022 16:50:01 +0200 Subject: [PATCH] Improve peer list storage (#415) * Improve peer list storage * Add entry to changelog * Fixes #416 * Update changelog --- CHANGELOG.md | 8 +++++++- src/ipfs/config.ts | 3 +-- src/ipfs/node.ts | 12 ++++++------ 3 files changed, 14 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 834479f94..fae5c4836 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,7 +4,9 @@ #### Bug fixes -Fixes the depedency-injected `lookupDnsLink` function +- Fixes the depedency-injected `lookupDnsLink` function +- Fixes issue with IPFS peer-list storage +- Removes Vite warning caused by a dynamic import ### v0.34.0 @@ -22,6 +24,7 @@ Enable new EXPERIMENTAL public file system version 3.0.0 using rs-wnfs. Use this - No longer uses a locally-shared IPFS client (was originally using a shared worker). This fixes various error messages you may have seen relating to CIDs. + ### v0.32.0 #### Features @@ -37,15 +40,18 @@ Fixes issue with loading private shares. Updated ipfs-related dependencies. + ### v0.31.1 Move `madge` and `typedoc-plugin-missing-exports` from `dependencies` into `devDependencies`. + ### v0.31.0 Fixes circular dependencies. + ### v0.30.0 #### Breaking Changes diff --git a/src/ipfs/config.ts b/src/ipfs/config.ts index e27c803fd..96dac697f 100644 --- a/src/ipfs/config.ts +++ b/src/ipfs/config.ts @@ -44,8 +44,7 @@ export const nodeWithPkg = (pkg: IPFSPackage): Promise => { */ export const pkgFromCDN = async (cdn_url: string): Promise => { if (!cdn_url) throw new Error("This function requires a URL to a CDN") - /* @vite-ignore */ - return import(/* webpackIgnore: true */ cdn_url).then(_ => (self as any).IpfsCore as IPFSPackage) + return import(/* @vite-ignore *//* webpackIgnore: true */ cdn_url).then(_ => (self as any).IpfsCore as IPFSPackage) } // /** diff --git a/src/ipfs/node.ts b/src/ipfs/node.ts index 8c6c11385..0f9a183c2 100644 --- a/src/ipfs/node.ts +++ b/src/ipfs/node.ts @@ -149,11 +149,11 @@ export async function createAndConnect(pkg: IPFSPackage): Promise { // PEERS // ----- -const STORAGE_KEY = "ipfs_peers_1660901513" +const STORAGE_KEY = "ipfs_peers_1661540056" export function fetchFissionPeers(): Promise { - const peersUrl = `${setup.getApiEndpoint()}/ipfs/peers` + const peersUrl = `${setup.endpoints.api}/ipfs/peers` return fetch(peersUrl) .then(r => r.json()) @@ -167,11 +167,11 @@ export async function listPeers(): Promise { let peers const maybePeers = await localforage.getItem(STORAGE_KEY) - if (t.isString(maybePeers)) { - peers = maybePeers.split(",") + if (t.isString(maybePeers) && maybePeers.trim() !== "") { + peers = JSON.parse(maybePeers) fetchFissionPeers().then(list => - localforage.setItem(STORAGE_KEY, list.join(",")) + localforage.setItem(STORAGE_KEY, JSON.stringify(list)) ).catch(err => { // don't throw console.error(err) @@ -179,7 +179,7 @@ export async function listPeers(): Promise { } else { peers = await fetchFissionPeers() - await localforage.setItem(STORAGE_KEY, peers.join(",")) + await localforage.setItem(STORAGE_KEY, JSON.stringify(peers)) }