Skip to content

Commit

Permalink
Update: tweaks on multiple archives loading
Browse files Browse the repository at this point in the history
  • Loading branch information
dpaez committed Jun 13, 2019
1 parent 24c1814 commit a04b28e
Showing 1 changed file with 20 additions and 12 deletions.
32 changes: 20 additions & 12 deletions packages/datviewer/src/p2p/datHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,21 @@ const defaultState = () => ({

function getArchive (url, opts={}) {
return new Promise((resolve, reject) => {
const archive = dat.get(url, opts)
if (archive.content) {
resolve({ archive, swarm: dat.swarm })
} else {
archive.on('content', () => {
resolve({ archive, swarm: dat.swarm })
})
}
url = url.replace(/\/$/, '')
const hd = dat.get(url, opts)
hd.ready(() => {
console.log({ key: hd.key })
if (hd.content) {
resolve({ archive: hd, swarm: dat.swarm })
} else {
hd.on('syncing', () => {console.log('syncing content...')})
hd.on('content', () => {
const archive = dat.archives.find(h => h.key.toString('hex') === url || h.url === url)
console.log({archive})
resolve({ archive, swarm: dat.swarm })
})
}
})
})
}

Expand Down Expand Up @@ -109,12 +116,10 @@ async function getChildrens (explorerState, archive, item) {
}

async function loadDat (options={}) {
console.log('dat handler options', options)
const alreadyLoaded = dat.has(options.dat)
console.log('alreadyLoaded', alreadyLoaded)
try {
const { archive, swarm } = await getArchive(options.dat)
console.log({archive})
const { archive, swarm } = await getArchive(options.dat)
const content = await renderContentBasic(archive, options.path || '/')
return {
content,
Expand All @@ -127,7 +132,10 @@ async function loadDat (options={}) {
}
}

const archives = dat.archives

export default {
loadDat,
getChildrens
getChildrens,
archives
}

0 comments on commit a04b28e

Please sign in to comment.