open dbs in index.js
This commit is contained in:
2
.gitignore
vendored
2
.gitignore
vendored
@@ -21,3 +21,5 @@
|
||||
npm-debug.log*
|
||||
yarn-debug.log*
|
||||
yarn-error.log*
|
||||
|
||||
/orbitdb
|
||||
41068
package-lock.json
generated
Normal file
41068
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
@@ -6,6 +6,8 @@
|
||||
"@testing-library/jest-dom": "^5.11.4",
|
||||
"@testing-library/react": "^11.1.0",
|
||||
"@testing-library/user-event": "^12.1.10",
|
||||
"ipfs-http-client": "^49.0.4",
|
||||
"orbit-db": "^0.26.1",
|
||||
"react": "^17.0.2",
|
||||
"react-dom": "^17.0.2",
|
||||
"react-scripts": "4.0.3",
|
||||
|
||||
40
src/index.js
40
src/index.js
@@ -4,6 +4,46 @@ import './index.css';
|
||||
import App from './App';
|
||||
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(
|
||||
<React.StrictMode>
|
||||
<App />
|
||||
|
||||
Reference in New Issue
Block a user