mirror of
https://github.com/orbitdb/orbitdb.git
synced 2025-06-03 20:56:37 +00:00
refactor: Use hash instead of path when referencing orbitdb addresses.
This commit is contained in:
parent
cdbe76d708
commit
44752a464e
@ -58,21 +58,21 @@ const parseAddress = (address) => {
|
||||
}
|
||||
|
||||
const OrbitDBAddress = (address) => {
|
||||
if (address && address.protocol === 'orbitdb' && address.path) {
|
||||
if (address && address.protocol === 'orbitdb' && address.hash) {
|
||||
return address
|
||||
}
|
||||
|
||||
const protocol = 'orbitdb'
|
||||
|
||||
const path = address.replace('/orbitdb/', '').replace('\\orbitdb\\', '')
|
||||
const hash = address.replace('/orbitdb/', '').replace('\\orbitdb\\', '')
|
||||
|
||||
const toString = () => {
|
||||
return posixJoin('/', protocol, path)
|
||||
return posixJoin('/', protocol, hash)
|
||||
}
|
||||
|
||||
return {
|
||||
protocol,
|
||||
path,
|
||||
hash,
|
||||
address,
|
||||
toString
|
||||
}
|
||||
|
@ -115,7 +115,7 @@ const OrbitDB = async ({ ipfs, id, identities, directory } = {}) => {
|
||||
if (isValidAddress(address)) {
|
||||
// If the address given was a valid OrbitDB address, eg. '/orbitdb/zdpuAuK3BHpS7NvMBivynypqciYCuy2UW77XYBPUYRnLjnw13'
|
||||
const addr = OrbitDBAddress(address)
|
||||
manifest = await manifestStore.get(addr.path)
|
||||
manifest = await manifestStore.get(addr.hash)
|
||||
const acType = manifest.accessController.split('/', 2).pop()
|
||||
const acAddress = manifest.accessController.replaceAll(`/${acType}/`, '')
|
||||
AccessController = getAccessController(acType)()
|
||||
|
@ -18,7 +18,7 @@ describe('Address', function () {
|
||||
it('has a path', () => {
|
||||
const address = '/orbitdb/zdpuAuK3BHpS7NvMBivynypqciYCuy2UW77XYBPUYRnLjnw13'
|
||||
const addr = OrbitDBAddress(address)
|
||||
strictEqual(addr.path, 'zdpuAuK3BHpS7NvMBivynypqciYCuy2UW77XYBPUYRnLjnw13')
|
||||
strictEqual(addr.hash, 'zdpuAuK3BHpS7NvMBivynypqciYCuy2UW77XYBPUYRnLjnw13')
|
||||
})
|
||||
})
|
||||
|
||||
@ -38,7 +38,7 @@ describe('Address', function () {
|
||||
it('has a path', () => {
|
||||
const address = 'zdpuAuK3BHpS7NvMBivynypqciYCuy2UW77XYBPUYRnLjnw13'
|
||||
const addr = OrbitDBAddress(address)
|
||||
strictEqual(addr.path, 'zdpuAuK3BHpS7NvMBivynypqciYCuy2UW77XYBPUYRnLjnw13')
|
||||
strictEqual(addr.hash, 'zdpuAuK3BHpS7NvMBivynypqciYCuy2UW77XYBPUYRnLjnw13')
|
||||
})
|
||||
})
|
||||
|
||||
@ -61,7 +61,7 @@ describe('Address', function () {
|
||||
})
|
||||
|
||||
it('has a path', () => {
|
||||
strictEqual(addr2.path, 'zdpuAuK3BHpS7NvMBivynypqciYCuy2UW77XYBPUYRnLjnw13')
|
||||
strictEqual(addr2.hash, 'zdpuAuK3BHpS7NvMBivynypqciYCuy2UW77XYBPUYRnLjnw13')
|
||||
})
|
||||
})
|
||||
|
||||
@ -128,7 +128,7 @@ describe('Address', function () {
|
||||
const result = parseAddress(address)
|
||||
|
||||
strictEqual(result.protocol, 'orbitdb')
|
||||
strictEqual(result.path, 'zdpuAuK3BHpS7NvMBivynypqciYCuy2UW77XYBPUYRnLjnw13')
|
||||
strictEqual(result.hash, 'zdpuAuK3BHpS7NvMBivynypqciYCuy2UW77XYBPUYRnLjnw13')
|
||||
|
||||
strictEqual(result.toString().indexOf('/orbitdb'), 0)
|
||||
strictEqual(result.toString().indexOf('zdpuAuK3BHpS7NvMBivynypqciYCuy2UW77XYBPUYRnLjnw13'), 9)
|
||||
@ -139,7 +139,7 @@ describe('Address', function () {
|
||||
const result = parseAddress(address)
|
||||
|
||||
strictEqual(result.protocol, 'orbitdb')
|
||||
strictEqual(result.path, 'Qmdgwt7w4uBsw8LXduzCd18zfGXeTmBsiR8edQ1hSfzcJC')
|
||||
strictEqual(result.hash, 'Qmdgwt7w4uBsw8LXduzCd18zfGXeTmBsiR8edQ1hSfzcJC')
|
||||
|
||||
strictEqual(result.toString().indexOf('/orbitdb'), 0)
|
||||
strictEqual(result.toString().indexOf('Qmdgwt7w4uBsw8LXduzCd18zfGXeTmBsiR8edQ1hSfzcJC'), 9)
|
||||
|
Loading…
x
Reference in New Issue
Block a user