From 74b4f48405eba0506529bcc0a7d714b7a5f7bd5c Mon Sep 17 00:00:00 2001 From: Julian Gruber Date: Wed, 14 Sep 2016 10:44:37 +0200 Subject: [PATCH] fix issue with archive dir not existing --- app.js | 41 ++++++++++++++++++++++------------------- 1 file changed, 22 insertions(+), 19 deletions(-) diff --git a/app.js b/app.js index 55a90365..6d770f06 100644 --- a/app.js +++ b/app.js @@ -137,28 +137,31 @@ liveStream(db, { }) } } else { - const archive = createArchive(Object.assign({ key }, data.value)) - archive.open(refresh) - archive.swarm = swarm(archive) - archive.swarm.on('connection', peer => { - refresh() - peer.on('close', () => refresh()) - }) - archive.on('download', () => refresh()) - archive.on('content', () => refresh()) - archive.listStream = archive.list({ live: true }) - archive.listStream.on('data', entry => { - if (entry.name != 'dat.json') return - collect(archive.createFileReadStream('dat.json'), (err, raw) => { - if (err) return - const json = JSON.parse(raw.toString()) - archive.title = json.title + const path = `${root}/${link}` + fs.mkdir(path, () => { + const archive = createArchive(Object.assign({ key }, data.value)) + archive.open(refresh) + archive.swarm = swarm(archive) + archive.swarm.on('connection', peer => { refresh() + peer.on('close', () => refresh()) }) - }) - archive.progress = 0.5 + archive.on('download', () => refresh()) + archive.on('content', () => refresh()) + archive.listStream = archive.list({ live: true }) + archive.listStream.on('data', entry => { + if (entry.name != 'dat.json') return + collect(archive.createFileReadStream('dat.json'), (err, raw) => { + if (err) return + const json = JSON.parse(raw.toString()) + archive.title = json.title + refresh() + }) + }) + archive.progress = 0.5 - archives.set(link, archive) + archives.set(link, archive) + }) } refresh() })