Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Publish metadata #812

Merged
merged 5 commits into from
Jun 27, 2017
Merged
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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
"dat-link-resolve": "^1.0.0",
"dat-log": "^1.1.0",
"dat-node": "^3.3.2",
"dat-registry": "^3.0.2",
"dat-registry": "^3.0.3",
"debug": "^2.6.6",
"hyperdrive-http": "^4.1.0",
"neat-log": "^1.1.0",
Expand Down
20 changes: 15 additions & 5 deletions src/commands/publish.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,10 @@ function publish (opts) {

opts.createIfMissing = false // publish must always be a resumed archive
Dat(opts.dir, opts, function (err, dat) {
if (err) return exitErr(err)
// TODO better error msg for non-existing archive
if (err && err.name === 'MissingError') return exitErr('No existing dat in this directory. Create a dat before publishing.')
else if (err) return exitErr(err)

dat.joinNetwork() // join network to upload metadata

var datjson = DatJson(dat.archive, {file: path.join(dat.path, 'dat.json')})
datjson.read(publish)
Expand Down Expand Up @@ -94,13 +96,21 @@ function publish (opts) {
}

function makeRequest (datInfo) {
console.log(`'${chalk.bold(datInfo.name)}' will soon be ready for its great unveiling.`)
console.log(`Please wait, '${chalk.bold(datInfo.name)}' will soon be ready for its great unveiling...`)
client.dats.create(datInfo, function (err, resp, body) {
if (err) {
if (err.message) return exitErr('ERROR: ' + err.message) // node error
if (err.message) {
if (err.message === 'timed out') {
return exitErr(output`${chalk.red('\nERROR: ' + opts.server + ' could not connect to your computer.')}
Troubleshoot here: ${chalk.green('https://docs.datproject.org/troubleshooting#networking-issues')}
`)
}
var str = err.message.trim()
if (str === 'jwt expired') return exitErr(`Session expired, please ${chalk.green('dat login')} again`)
return exitErr('ERROR: ' + err.message) // node error
}

// server response errors
if (err.toString().trim() === 'jwt expired') return exitErr(`Session expired, please ${chalk.green('dat login')} again`)
return exitErr('ERROR: ' + err.toString())
}
if (body.statusCode === 400) return exitErr(new Error(body.message))
Expand Down