Skip to content

Commit 2fcc0b9

Browse files
committed
Fix reference errors around hyperbee keys (close #30)
1 parent 2d6ae63 commit 2fcc0b9

File tree

7 files changed

+16
-7
lines changed

7 files changed

+16
-7
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22
node_modules
33
npm-debug.log
44
package-lock.json
5+
.DS_Store

lib/commands/create.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export default {
2222
process.exit(1)
2323
}
2424

25-
await getMirroringClient().mirror(struct.api.key, struct.type)
25+
await getMirroringClient().mirror(struct.key, struct.type)
2626
console.log('Seeding', struct.type)
2727
process.exit(0)
2828
}

lib/commands/drive/sync.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ async function createTarget (source) {
171171
}
172172
// If the source is a local directory, create a new drive to copy into.
173173
let drive = await HyperStruct.create('hyperdrive')
174-
await getMirroringClient().mirror(drive.api.key, drive.type)
174+
await getMirroringClient().mirror(drive.key, drive.type)
175175
return {fs: drive.api, path: '/', raw: drive.url + '/'}
176176
}
177177

lib/commands/info.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ export default {
117117
await tracker.loadStructPromise
118118
}
119119
if (tracker.struct) {
120-
;({ mirror, network } = await getStatus(key, tracker.struct.type, tracker.struct.api.discoveryKey))
120+
;({ mirror, network } = await getStatus(key, tracker.struct.type, tracker.struct.discoveryKey))
121121
}
122122
} catch (e) {
123123
if (e.toString().includes('RPC stream destroyed')) {

lib/commands/seed.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export default {
2929

3030
for (const key of keys) {
3131
var struct = await HyperStruct.get(key)
32-
await mirroringClient.mirror(struct.api.key, struct.type)
32+
await mirroringClient.mirror(struct.key, struct.type)
3333
console.log(`Seeding ${chalk.bold(short(key))}`)
3434
}
3535
process.exit(0)

lib/commands/unseed.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export default {
2929

3030
for (const key of keys) {
3131
var struct = await HyperStruct.get(key)
32-
await mirroringClient.unmirror(struct.api.key, struct.type)
32+
await mirroringClient.unmirror(struct.key, struct.type)
3333
console.log(`No longer seeding ${chalk.bold(short(key))}`)
3434
}
3535
process.exit(0)

lib/hyper/struct.js

+10-2
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,14 @@ class HyperStructure extends EventEmitter {
2424
this.api = undefined
2525
}
2626

27+
get key () {
28+
return this.core?.key
29+
}
30+
31+
get discoveryKey () {
32+
return this.core?.discoveryKey
33+
}
34+
2735
get url () {
2836
return `hyper://${this.keyStr}`
2937
}
@@ -99,15 +107,15 @@ class HyperStructure extends EventEmitter {
99107
if (this.type === 'hyperdrive') {
100108
this.api = hyperdrive(getClient().corestore(), null, {extension: false})
101109
await this.api.promises.ready()
102-
this.keyStr = this.api.key.toString('hex')
110+
this.keyStr = this.key.toString('hex')
103111
} else if (this.type === 'hyperbee') {
104112
let core = getClient().corestore().get(null)
105113
this.api = new Hyperbee(core, {
106114
keyEncoding: 'binary',
107115
valueEncoding: 'json'
108116
})
109117
await this.api.ready()
110-
this.keyStr = this.api.feed.key.toString('hex')
118+
this.keyStr = this.key.toString('hex')
111119
}
112120

113121
if (!noNetConfig) getClient().network.configure(this.core, {lookup: true, announce: true})

0 commit comments

Comments
 (0)