fix(autobase-todo): correct Autobase constructor, open/apply signatures, bootstrap addWriter logic, remove crashing view log
docs: update hyperdrive-fileshare index.js (reader key arg)
This commit is contained in:
@@ -25,32 +25,38 @@ async function main() {
|
||||
console.log('w1 key:', w1.key.toString('hex'))
|
||||
console.log('w2 key:', w2.key.toString('hex')) // random per storage, replicate to share
|
||||
|
||||
async function open (store) {
|
||||
async function open (store, host) {
|
||||
return store.get({ name: 'merged-todos', valueEncoding: 'json' })
|
||||
}
|
||||
|
||||
async function apply (nodes, view) {
|
||||
for (const { value } of nodes) {
|
||||
async function apply (nodes, view, host) {
|
||||
for (const node of nodes) {
|
||||
const { value } = node
|
||||
if (value === null) continue // skip acks
|
||||
if (value.addWriter) {
|
||||
await host.addWriter(value.addWriter, { indexer: true })
|
||||
continue
|
||||
}
|
||||
await view.append(value)
|
||||
}
|
||||
}
|
||||
|
||||
let localInput = null
|
||||
if (mode === 'writer1') {
|
||||
localInput = w1
|
||||
} else if (mode === 'writer2') {
|
||||
localInput = w2
|
||||
}
|
||||
|
||||
const base = new Autobase([w1, w2], {
|
||||
localInput,
|
||||
const base = new Autobase(corestore, null, {
|
||||
open,
|
||||
apply
|
||||
})
|
||||
await base.ready()
|
||||
console.log('Autobase view key:', base.view.key.toString('hex'))
|
||||
// console.log('Autobase view key:', base.view?.key?.toString('hex') || 'not ready')
|
||||
console.log('Autobase ready, length:', base.length)
|
||||
|
||||
// Bootstrap writers
|
||||
if (mode === 'writer1') {
|
||||
await base.append({ addWriter: w2.key })
|
||||
console.log('Bootstrapped writer2')
|
||||
} else if (mode === 'writer2') {
|
||||
await base.append({ addWriter: w1.key })
|
||||
console.log('Bootstrapped writer1')
|
||||
}
|
||||
|
||||
// Fixed swarm topic
|
||||
const topic = crypto.createHash('sha256').update('autobase-todo-test').digest()
|
||||
|
||||
@@ -22,8 +22,8 @@ async function main() {
|
||||
|
||||
if (isWriter) {
|
||||
const content = 'Test P2P file share content\n'
|
||||
await drive.put('test.txt', Buffer.from(content))
|
||||
console.log('✅ File written: test.txt')
|
||||
await drive.put('/test.txt', Buffer.from(content))
|
||||
console.log('✅ File written: /test.txt')
|
||||
console.log('📤 Share this drive key with readers: ' + drive.key.toString('hex'))
|
||||
} else {
|
||||
console.log('🔍 Connecting to drive key: ' + process.argv[2])
|
||||
@@ -41,7 +41,7 @@ async function main() {
|
||||
if (!isWriter) {
|
||||
const checkFile = async () => {
|
||||
try {
|
||||
const content = await drive.get('test.txt')
|
||||
const content = await drive.get('/test.txt')
|
||||
if (content) {
|
||||
console.log('📥 File received successfully:')
|
||||
console.log(content.toString())
|
||||
|
||||
Reference in New Issue
Block a user