Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 13 additions & 10 deletions commands/download.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,24 @@ var ui = require('../lib/ui')
module.exports = function (args) {
if (args && args.exit) args.upload = false
var dat = Dat(args)
var log = logger(args)

var messages = []
var progressLines = []
var log = logger([messages, progressLines], {debug: args.debug, quiet: args.quiet})

var downloadTxt = 'Downloading '
var finished = false

dat.stats.rateUp = speedometer()
dat.stats.rateDown = speedometer()

log.status('Starting Dat...\n', 0)
log.status('Connecting...', 1)
progressLines[0] = 'Starting Dat...\n'
progressLines[1] = 'Connecting...'

dat.on('error', onerror)

dat.open(function () {
log.message('Downloading in ' + dat.dir + '\n')
messages.push('Downloading in ' + dat.dir + '\n')
dat.download(function (err) {
if (err) onerror(err)
})
Expand All @@ -35,7 +38,7 @@ module.exports = function (args) {
})

dat.once('key', function (key) {
log.message(ui.keyMsg(key))
messages.push(ui.keyMsg(key))
if (args.quiet) console.log(ui.keyMsg(key))
})

Expand All @@ -53,7 +56,7 @@ module.exports = function (args) {
finished = false
dat.stats.rateDown = speedometer()
updateStats()
log.status('', -1) // remove download finished message
progressLines[2] = '' // remove download finished message
})
dat.on('file-downloaded', updateStats)

Expand All @@ -62,16 +65,16 @@ module.exports = function (args) {
dat.stats.rateDown = 0
updateStats()
if (args.exit) {
log.status('', 1)
progressLines[1] = '' // clear swarm info before exiting
process.exit(0)
}
log.status('\nDownload Finished. You may exit the process with Ctrl-C.', -1)
progressLines[2] = '\nDownload Finished. You may exit the process with Ctrl-C.'
})

dat.on('swarm-update', printSwarm)

function printSwarm () {
log.status(ui.swarmMsg(dat), 1)
progressLines[1] = ui.swarmMsg(dat)
}

function updateStats () {
Expand All @@ -83,7 +86,7 @@ module.exports = function (args) {
}
msg += ' ' + downloadTxt + chalk.bold(stats.filesTotal) + ' items'
msg += chalk.dim(' (' + prettyBytes(stats.bytesProgress) + '/' + prettyBytes(stats.bytesTotal) + ')')
log.status(msg + '\n', 0)
progressLines[0] = msg + '\n'
}
}

Expand Down
21 changes: 12 additions & 9 deletions commands/share.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,25 @@ var ui = require('../lib/ui')

module.exports = function (args) {
var dat = Dat(args)
var log = logger(args)

var messages = []
var progressLines = []
var log = logger([messages, progressLines], {debug: args.debug, quiet: args.quiet})

var addText = 'Adding '
var updated = false
var initFileCount = 0

dat.stats.rateUp = speedometer()

log.status('Starting Dat...\n', 0)
if (args.snapshot) log.status('Creating Link...', 1)
else log.status('Connecting...', 1)
progressLines[0] = 'Starting Dat...\n'
if (args.snapshot) progressLines[1] = 'Creating Link...'
else progressLines[1] = 'Connecting...'

dat.on('error', onerror)

dat.open(function () {
log.message('Sharing ' + dat.dir + '\n')
messages.push('Sharing ' + dat.dir + '\n')
dat.share(function (err) {
if (err) onerror(err)
})
Expand All @@ -42,11 +45,11 @@ module.exports = function (args) {
var msg = 'Calculating Size: '
msg += stats.filesTotal + ' items '
msg += chalk.dim('(' + prettyBytes(stats.bytesTotal) + ')')
log.status(msg + '\n', 0)
progressLines[0] = msg + '\n'
})

dat.once('key', function (key) {
log.message(ui.keyMsg(key))
messages.push(ui.keyMsg(key))
if (args.quiet) console.log(ui.keyMsg(key))
})

Expand All @@ -72,7 +75,7 @@ module.exports = function (args) {
dat.on('swarm-update', printSwarm)

function printSwarm () {
log.status(ui.swarmMsg(dat), 1)
progressLines[1] = ui.swarmMsg(dat)
}

function updateStats () {
Expand All @@ -90,7 +93,7 @@ module.exports = function (args) {
var msg = ui.progress(bytesProgress / bytesTotal)
msg += ' ' + addText + chalk.bold(files) + ' items'
msg += chalk.dim(' (' + prettyBytes(bytesProgress) + '/' + prettyBytes(bytesTotal) + ')')
log.status(msg + '\n', 0)
progressLines[0] = msg + '\n'
}
}

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"pretty-bytes": "^3.0.0",
"pump": "^1.0.1",
"speedometer": "^1.0.0",
"status-logger": "^2.0.1"
"status-logger": "^3.0.0"
},
"bugs": {
"url": "https://github.com/datproject/dat/issues"
Expand Down