Skip to content
This repository was archived by the owner on Jan 12, 2024. It is now read-only.

Commit 948ad3b

Browse files
authored
fix: update examples to run with latest js-ipfs (#232)
Updates all examples to the latest deps
1 parent 14bf2c2 commit 948ad3b

File tree

43 files changed

+130
-113
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+130
-113
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ jobs:
5252
- uses: actions/checkout@v2
5353
- uses: actions/setup-node@v2
5454
with:
55-
node-version: 16
55+
node-version: lts/*
5656
- run: npm install
5757
- uses: GabrielBB/xvfb-action@v1
5858
name: Run tests
@@ -67,7 +67,7 @@ jobs:
6767
- uses: actions/checkout@v2
6868
- uses: actions/setup-node@v2
6969
with:
70-
node-version: 16
70+
node-version: lts/*
7171
- name: Install dependencies
7272
run: npm install
7373
- uses: GabrielBB/xvfb-action@v1

examples/browser-add-readable-stream/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
},
1515
"browserslist": "last 1 Chrome version",
1616
"dependencies": {
17-
"ipfs-core": "^0.12.2"
17+
"ipfs-core": "^0.14.0"
1818
},
1919
"devDependencies": {
2020
"@babel/core": "^7.14.8",

examples/browser-angular/package.json

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,26 +12,26 @@
1212
"test": "npm run build && playwright test tests"
1313
},
1414
"dependencies": {
15-
"@angular/animations": "~12.2.0",
16-
"@angular/common": "~12.2.0",
17-
"@angular/compiler": "~12.2.0",
18-
"@angular/core": "~12.2.0",
19-
"@angular/forms": "~12.2.0",
20-
"@angular/platform-browser": "~12.2.0",
21-
"@angular/platform-browser-dynamic": "~12.2.0",
22-
"@angular/router": "~12.2.0",
15+
"@angular/animations": "^13.2.0",
16+
"@angular/common": "^13.2.0",
17+
"@angular/compiler": "^13.2.0",
18+
"@angular/core": "^13.2.0",
19+
"@angular/forms": "^13.2.0",
20+
"@angular/platform-browser": "^13.2.0",
21+
"@angular/platform-browser-dynamic": "^13.2.0",
22+
"@angular/router": "^13.2.0",
2323
"global": "^4.4.0",
24-
"ipfs-core": "^0.12.2",
25-
"ipfs-core-types": "^0.8.0",
26-
"rxjs": "~7.4.0",
24+
"ipfs-core": "^0.14.0",
25+
"ipfs-core-types": "^0.10.0",
26+
"rxjs": "^7.5.2",
2727
"tslib": "^2.3.0",
2828
"zone.js": "~0.11.4"
2929
},
3030
"devDependencies": {
31-
"@angular-builders/custom-webpack": "^12.1.0",
32-
"@angular-devkit/build-angular": "~12.2.2",
33-
"@angular/cli": "~12.2.2",
34-
"@angular/compiler-cli": "~12.2.0",
31+
"@angular-builders/custom-webpack": "^13.0.0",
32+
"@angular-devkit/build-angular": "^13.2.0",
33+
"@angular/cli": "^13.2.0",
34+
"@angular/compiler-cli": "^13.2.0",
3535
"@playwright/test": "^1.12.3",
3636
"@types/jasmine": "~3.10.2",
3737
"@types/node": "^16.6.2",
@@ -45,6 +45,6 @@
4545
"playwright": "^1.12.3",
4646
"rimraf": "^3.0.2",
4747
"test-util-ipfs-example": "^1.0.2",
48-
"typescript": "~4.3.5"
48+
"typescript": "^4.5.5"
4949
}
5050
}

examples/browser-browserify/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"test": "npm run build && playwright test tests"
1414
},
1515
"dependencies": {
16-
"ipfs-core": "^0.12.2"
16+
"ipfs-core": "^0.14.0"
1717
},
1818
"devDependencies": {
1919
"@playwright/test": "^1.12.3",

examples/browser-create-react-app/package.json

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,19 +36,20 @@
3636
"@testing-library/jest-dom": "^5.14.1",
3737
"@testing-library/react": "^12.1.2",
3838
"@testing-library/user-event": "^13.5.0",
39-
"dot-prop": "^6.0.1",
40-
"ipfs-core": "^0.12.2",
39+
"dot-prop": "^7.1.1",
40+
"ipfs-core": "^0.14.0",
4141
"ipfs-css": "^1.3.0",
4242
"react": "^17.0.2",
4343
"react-dom": "^17.0.2",
44-
"react-scripts": "4.0.3",
44+
"react-scripts": "5.0.0",
4545
"tachyons": "^4.12.0",
4646
"web-vitals": "^2.1.2"
4747
},
4848
"devDependencies": {
4949
"@playwright/test": "^1.12.3",
5050
"playwright": "^1.12.3",
5151
"rimraf": "^3.0.2",
52-
"test-util-ipfs-example": "^1.0.2"
52+
"test-util-ipfs-example": "^1.0.2",
53+
"util": "^0.12.4"
5354
}
5455
}

examples/browser-create-react-app/src/hooks/use-ipfs.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { useState, useEffect } from 'react'
2-
import dotProp from 'dot-prop'
2+
import { getProperty } from 'dot-prop'
33
// dot-prop: used to obtain a property of an object when the name of property is a string
44
// here we get ipfs.id when calling dotProp.get(ipfs, cmd), with cmd = 'id'
55
// and we get ipfs.hash when calling with cmd = 'hash' etc.
@@ -22,7 +22,7 @@ export default function useIpfs (ipfs, cmd, opts) {
2222
async function callIpfs (ipfs, cmd, setRes, ...opts) {
2323
if (!ipfs) return null
2424
console.log(`Call ipfs.${cmd}`)
25-
const ipfsCmd = dotProp.get(ipfs, cmd)
25+
const ipfsCmd = getProperty(ipfs, cmd)
2626
const res = await ipfsCmd(...opts)
2727
console.log(`Result ipfs.${cmd}`, res)
2828
setRes(res)

examples/browser-exchange-files/package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,17 @@
1212
},
1313
"browserslist": "last 1 Chrome version",
1414
"dependencies": {
15-
"ipfs-core": "^0.12.2",
15+
"ipfs-core": "^0.14.0",
1616
"it-all": "^1.0.4",
1717
"libp2p-websockets": "^0.16.1",
1818
"uint8arrays": "^3.0.0"
1919
},
2020
"devDependencies": {
2121
"@babel/core": "^7.14.8",
2222
"@playwright/test": "^1.12.3",
23-
"ipfs": "^0.60.2",
24-
"ipfs-core-types": "^0.8.0",
25-
"ipfs-http-client": "^54.0.2",
23+
"ipfs": "^0.62.0",
24+
"ipfs-core-types": "^0.10.0",
25+
"ipfs-http-client": "^56.0.0",
2626
"libp2p-webrtc-star-signalling-server": "^0.1.0",
2727
"parcel": "latest",
2828
"playwright": "^1.12.3",

examples/browser-ipns-publish/index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,7 @@ <h1 class="aqua fw2 montserrat dib ma0 pv2 ph1 v-mid fr f3 lh-copy">
198198
<input
199199
id="topic"
200200
class="dib w-50 ph1 pv2 monospace input-reset ba b--black-20 border-box"
201+
placeholder="/ipfs/QmFoo"
201202
disabled="disabled"
202203
/>
203204
<button

examples/browser-ipns-publish/package.json

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,12 @@
1818
"build": "parcel build index.html --no-scope-hoist",
1919
"serve": "parcel serve index.html --open -p 8888",
2020
"start": "npm run serve",
21-
"test": "npm run build && playwright test tests --retries=3"
21+
"test": "npm run build && playwright test tests --retries=3 --timeout=120000"
2222
},
2323
"browserslist": "last 1 Chrome version",
2424
"dependencies": {
25-
"human-crypto-keys": "^0.1.4",
26-
"ipfs-core": "^0.12.2",
27-
"ipfs-http-client": "^54.0.2",
25+
"ipfs-core": "^0.14.0",
26+
"ipfs-http-client": "^56.0.0",
2827
"ipfs-utils": "^9.0.2",
2928
"ipns": "^0.16.0",
3029
"it-last": "^1.0.4",
@@ -38,7 +37,7 @@
3837
"@playwright/test": "^1.12.3",
3938
"delay": "^5.0.0",
4039
"execa": "^6.0.0",
41-
"go-ipfs": "0.10.0",
40+
"go-ipfs": "^0.11.0",
4241
"ipfsd-ctl": "^10.0.3",
4342
"parcel": "latest",
4443
"playwright": "^1.12.3",

examples/browser-ipns-publish/src/index.js

Lines changed: 35 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,8 @@ const ipns = require("ipns");
55
const IPFS = require("ipfs-core");
66
const pRetry = require("p-retry");
77
const last = require("it-last");
8-
const cryptoKeys = require("human-crypto-keys"); // { getKeyPairFromSeed }
98
const { toString: uint8ArrayToString } = require('uint8arrays/to-string')
109
const { fromString: uint8ArrayFromString } = require('uint8arrays/from-string')
11-
const { sha256 } = require('multiformats/hashes/sha2')
1210
const { base58btc } = require('multiformats/bases/base58')
1311
const { base36 } = require('multiformats/bases/base36')
1412
const { CID } = require('multiformats/cid')
@@ -17,7 +15,7 @@ const WS = require('libp2p-websockets')
1715
const transportKey = WS.prototype[Symbol.toStringTag]
1816
const filters = require('libp2p-websockets/src/filters')
1917

20-
const { sleep, Logger, onEnterPress, catchAndLog } = require("./util");
18+
const { Logger, onEnterPress, catchAndLog } = require("./util");
2119

2220
async function main() {
2321
const apiUrlInput = document.getElementById("api-url");
@@ -88,8 +86,20 @@ async function main() {
8886
await ipfsBrowser.swarm.connect(addr);
8987
log(`<span class="green">Success!</span>`);
9088
log("Listing swarm peers...");
91-
await sleep();
92-
const peers = await ipfsBrowser.swarm.peers();
89+
90+
const peers = await pRetry(async () => {
91+
const peers = await ipfsBrowser.swarm.peers();
92+
93+
if (peers.find(peer => addr.endsWith(peer.peer))) {
94+
return peers
95+
}
96+
97+
throw new Error('Could not find go-ipfs peer in swarm peers')
98+
})
99+
.catch(err => {
100+
sLog(`<span class="red">[Fail] ${err.message}</span>`);
101+
})
102+
93103
peers.forEach((peer) => {
94104
//console.log(`peer: ${JSON.stringify(peer, null, 2)}`);
95105
const fullAddr = `${peer.addr}/ipfs/${peer.peer}`;
@@ -157,14 +167,11 @@ async function main() {
157167
async function createKey(keyName) {
158168
return new Promise(async (resolve, reject) => {
159169
try {
160-
// quick and dirty key gen, don't do this in real life
161-
const key = await sha256.digest(
162-
uint8ArrayFromString(keyName + Math.random().toString(36).substring(2))
163-
);
164-
const keyPair = await cryptoKeys.getKeyPairFromSeed(key.bytes, "rsa");
170+
// generate a key on the browser IPNS keychain with the specified name
171+
await ipfsAPI.key.gen(keyName, {
172+
type: 'ed25519'
173+
})
165174

166-
// put it on the browser IPNS keychain and name it
167-
await ipfsBrowser.key.import(keyName, keyPair.privateKey);
168175
// now this key can be used to publish to this ipns publicKey
169176
resolve(true);
170177
} catch (err) {
@@ -179,6 +186,10 @@ async function main() {
179186
throw new Error("Missing ipns content to publish");
180187
}
181188

189+
if (!content.startsWith('/ipfs/')) {
190+
throw new Error("Content should start with /ipfs/");
191+
}
192+
182193
if (!ipfsAPI) {
183194
throw new Error("Connect to a go-server node first");
184195
}
@@ -232,17 +243,23 @@ async function main() {
232243
sLog(`[Pass] Pubsub.ls`);
233244
}
234245

235-
let remListSubs = await ipfsAPI.name.pubsub.subs(); // API
236246
const multihash = uint8ArrayFromString(keys.id, 'base58btc')
237247
const digest = Digest.decode(multihash)
238248
const libp2pKey = CID.createV1(0x72, digest)
239249
const ipnsName = `/ipns/${libp2pKey.toString(base36)}`
240250

241-
if (!remListSubs.includes(ipnsName)) {
242-
sLog(`<span class="red">[Fail] !Name.Pubsub.subs ${ipnsName}</span>`);
243-
} else {
244-
sLog(`[Pass] Name.Pubsub.subs`);
245-
}
251+
await pRetry(async () => {
252+
let remListSubs = await ipfsAPI.name.pubsub.subs(); // API
253+
254+
if (!remListSubs.includes(ipnsName)) {
255+
throw new Error(`!Name.Pubsub.subs ${ipnsName}`)
256+
} else {
257+
sLog(`[Pass] Name.Pubsub.subs`);
258+
}
259+
})
260+
.catch(err => {
261+
sLog(`<span class="red">[Fail] ${err.message}</span>`);
262+
})
246263

247264
// publish will send a pubsub msg to the server to update their ipns record
248265
log(`Publishing ${content} to ${keyName} ${ipnsName}`);

examples/browser-ipns-publish/src/util.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
exports.sleep = (ms = 1000) => new Promise(resolve => setTimeout(resolve, ms))
2-
31
exports.Logger = outEl => {
42
outEl.innerHTML = ''
53
return message => {

examples/browser-ipns-publish/tests/test.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ play.describe('http ipns publish:', () => {
7171
.filter(addr => addr.includes("/ws/p2p/"))
7272
.pop()
7373

74+
await page.waitForSelector(`${consoleDOM}:has-text('Browser IPFS ready!')`);
75+
7476
await page.waitForSelector(apiSelector);
7577
await page.fill(apiSelector, apiAddress);
7678
await page.click(nodeConnect);

examples/browser-lit/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
},
1515
"browserslist": "last 1 Chrome version",
1616
"dependencies": {
17-
"ipfs-core": "^0.12.2",
17+
"ipfs-core": "^0.14.0",
1818
"ipfs-css": "^1.3.0",
1919
"lit": "^2.0.2",
2020
"tachyons": "^4.12.0"

examples/browser-mfs/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
},
1515
"browserslist": "last 1 Chrome version",
1616
"dependencies": {
17-
"ipfs-core": "^0.12.2",
17+
"ipfs-core": "^0.14.0",
1818
"mime-sniffer": "~0.0.3"
1919
},
2020
"devDependencies": {

examples/browser-nextjs/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,15 @@
1212
"test": "npm run build && playwright test tests"
1313
},
1414
"dependencies": {
15-
"ipfs-core": "^0.12.2",
15+
"ipfs-core": "^0.14.0",
1616
"next": "^12.0.7",
1717
"react": "^17.0.2",
1818
"react-dom": "^17.0.2"
1919
},
2020
"devDependencies": {
2121
"@playwright/test": "^1.12.3",
22-
"eslint": "^7.20.0",
23-
"eslint-config-next": "^11.0.0",
22+
"eslint": "^8.7.0",
23+
"eslint-config-next": "^12.0.9",
2424
"playwright": "^1.12.3",
2525
"rimraf": "^3.0.2",
2626
"test-util-ipfs-example": "^1.0.0"

examples/browser-parceljs/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
},
1616
"browserslist": "last 1 Chrome version",
1717
"dependencies": {
18-
"ipfs-core": "^0.12.2"
18+
"ipfs-core": "^0.14.0"
1919
},
2020
"devDependencies": {
2121
"@babel/core": "^7.14.8",

examples/browser-readablestream/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
},
1515
"browserslist": "last 1 Chrome version",
1616
"dependencies": {
17-
"ipfs-core": "^0.12.2",
17+
"ipfs-core": "^0.14.0",
1818
"it-to-stream": "^1.0.0",
1919
"videostream": "^3.2.0"
2020
},

examples/browser-service-worker/package.json

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,10 @@
1616
"last 1 Chrome version"
1717
],
1818
"dependencies": {
19-
"ipfs-core": "^0.12.2",
20-
"ipfs-message-port-client": "^0.10.2",
21-
"ipfs-message-port-protocol": "^0.10.0",
22-
"ipfs-message-port-server": "^0.10.0",
23-
"process": "0.11.10"
19+
"ipfs-core": "^0.14.0",
20+
"ipfs-message-port-client": "^0.11.0",
21+
"ipfs-message-port-protocol": "^0.11.0",
22+
"ipfs-message-port-server": "^0.11.0"
2423
},
2524
"devDependencies": {
2625
"@babel/core": "^7.13.10",

examples/browser-sharing-node-across-tabs/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@
1414
},
1515
"browserslist": "last 1 Chrome version",
1616
"dependencies": {
17-
"ipfs-core": "^0.12.2",
18-
"ipfs-message-port-client": "^0.10.2",
19-
"ipfs-message-port-server": "^0.10.0"
17+
"ipfs-core": "^0.14.0",
18+
"ipfs-message-port-client": "^0.11.0",
19+
"ipfs-message-port-server": "^0.11.0"
2020
},
2121
"devDependencies": {
2222
"@babel/core": "^7.14.8",

examples/browser-video-streaming/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
"dependencies": {
1717
"hls.js": "^0.14.17",
1818
"hlsjs-ipfs-loader": "^0.3.0",
19-
"ipfs-core": "^0.12.2"
19+
"ipfs-core": "^0.14.0"
2020
},
2121
"devDependencies": {
2222
"@babel/core": "^7.14.8",

0 commit comments

Comments
 (0)