Skip to content
This repository has been archived by the owner on Dec 23, 2021. It is now read-only.

Commit

Permalink
Fix bugs with viewing an archive consistently
Browse files Browse the repository at this point in the history
  • Loading branch information
okdistribute committed Jun 2, 2017
1 parent dfaa2de commit dcbcaa5
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
2 changes: 1 addition & 1 deletion client/js/pages/archive/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ const archivePage = (state, prev, send) => {
var err = state.archive.error
if (err) {
if (err.message === 'Block not downloaded') err.message = 'timed out'
if (!module.parent) send('archive:getMetadata', {timeout: 60000})
if (!state.archive.entries.length) {
var props = ARCHIVE_ERRORS[err.message]
if (props) {
Expand All @@ -36,7 +37,6 @@ const archivePage = (state, prev, send) => {
err.message = 'Looking for dat.json metadata...'
}
}
if (!module.parent) send('archive:getMetadata', {timeout: 60000})
var peers = Math.max(state.archive.peers - 1, 0) // we don't count
var size = state.archive.size
var meta = state.archive.metadata
Expand Down
11 changes: 6 additions & 5 deletions server/dats.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,32 +44,33 @@ Dats.prototype.metadata = function (archive, opts, cb) {

var timeout = setTimeout(function () {
var msg = 'timed out'
if (cancelled) return
cancelled = true
return cb(new Error(msg), dat)
}, opts.timeout)
return done(new Error(msg), dat)
}, parseInt(opts.timeout))

function done (err, dat) {
clearTimeout(timeout)
if (cancelled) return
cancelled = true
return cb(err, dat)
}
archive.metadata.update()
archive.tree.list('/', {nodes: true}, function (err, entries) {
if (err) {
return archive.metadata.update(function () {
if (cancelled) return
cancelled = true
self.metadata(archive, opts, cb)
})
}
if (cancelled) return done(null, dat)

for (var i in entries) {
var entry = entries[i]
entries[i] = entry.value
entries[i].name = entry.name
entries[i].type = 'file'
}
dat.entries = entries
if (cancelled) return done(null, dat)
var filename = 'dat.json'
archive.stat(filename, function (err, entry) {
if (err || cancelled) return done(null, dat)
Expand Down

0 comments on commit dcbcaa5

Please sign in to comment.