open dbs in index.js

This commit is contained in:
2021-04-05 23:27:56 +02:00
parent 70290eac93
commit a143c8de26
5 changed files with 52312 additions and 8801 deletions

2
.gitignore vendored
View File

@@ -21,3 +21,5 @@
npm-debug.log* npm-debug.log*
yarn-debug.log* yarn-debug.log*
yarn-error.log* yarn-error.log*
/orbitdb

41068
package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -6,6 +6,8 @@
"@testing-library/jest-dom": "^5.11.4", "@testing-library/jest-dom": "^5.11.4",
"@testing-library/react": "^11.1.0", "@testing-library/react": "^11.1.0",
"@testing-library/user-event": "^12.1.10", "@testing-library/user-event": "^12.1.10",
"ipfs-http-client": "^49.0.4",
"orbit-db": "^0.26.1",
"react": "^17.0.2", "react": "^17.0.2",
"react-dom": "^17.0.2", "react-dom": "^17.0.2",
"react-scripts": "4.0.3", "react-scripts": "4.0.3",

View File

@@ -4,6 +4,46 @@ import './index.css';
import App from './App'; import App from './App';
import reportWebVitals from './reportWebVitals'; import reportWebVitals from './reportWebVitals';
import OrbitDB from "orbit-db"
import IpfsClient from "ipfs-http-client"
var ipfs
var orbitdb
async function init() {
ipfs = IpfsClient({ host: 'localhost', port: '5001', protocol: 'http' })
orbitdb = await OrbitDB.createInstance(ipfs)
}
// Loads a number of feed dbs from their addresses
async function openManyDbs(addresses) {
await init()
let data = []
let dbs = []
for (let address of addresses) {
let db = await orbitdb.open(address)
await db.load()
dbs.push(db)
let elements = await db.iterator({ reverse: true, limit: -1 }).collect()
let myData = elements.map((element) => element.payload.value.text)
data.push({ name: db.dbname, data: myData })
}
console.log(data)
}
const addresses = [
'/orbitdb/zdpuAtxMYsxuT68bJKaRQpJq2y9bCkUghtebx6HaTfvamwLUJ/Test0',
'/orbitdb/zdpuAuA1Cc9PLWLgZnf8qj8MJSq6XSDsYxbB8jX4UcRv45Diz/Test1',
'/orbitdb/zdpuAo2UiSF4V9qJuDJBBahBbQP2LSFV2uFrEVkEXN3uwry3P/Test2',
'/orbitdb/zdpuB18Mry92AwT3AX29fujNEGMzH8oihd4soCsekGQwLa54A/Test3'
]
openManyDbs(addresses)
ReactDOM.render( ReactDOM.render(
<React.StrictMode> <React.StrictMode>
<App /> <App />

20001
yarn.lock

File diff suppressed because it is too large Load Diff