Skip to content

Commit

Permalink
url in dat.json should always be right when publishing (#101)
Browse files Browse the repository at this point in the history
* make sure that if the url is stale that it gets updated for the dat.json

* overwrite old url in dat.json on publish

* standard
  • Loading branch information
Karissa authored and joehand committed Jan 25, 2017
1 parent 67eb296 commit 420a540
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/commands/publish.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
var Dat = require('dat-node')
var encoding = require('dat-encoding')
var prompt = require('prompt')
var TownshipClient = require('../township')
var ui = require('../ui')
Expand Down Expand Up @@ -28,7 +29,7 @@ function publish (opts) {
function publish (dat) {
var datInfo = {
name: dat.meta.name || opts.name,
url: dat.meta.url || 'dat://' + dat.key.toString('hex'),
url: 'dat://' + encoding.toStr(dat.key),
title: dat.meta.title,
description: dat.meta.description,
keywords: dat.meta.keywords
Expand Down
23 changes: 23 additions & 0 deletions tests/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,29 @@ authServer(port, function (err, server, closeServer) {
st.end()
})

test('auth - publish our awesome dat with bad dat.json url', function (t) {
fs.readFile(path.join(fixtures, 'dat.json'), function (err, contents) {
t.ifError(err)
var info = JSON.parse(contents)
var oldUrl = info.url
info.url = info.url.replace('e', 'a')
fs.writeFile(path.join(fixtures, 'dat.json'), JSON.stringify(info), function (err) {
t.ifError(err, 'error after write')
var cmd = dat + ' publish --name awesome'
var st = spawn(t, cmd, {cwd: fixtures})
st.stdout.match(function (output) {
var published = output.indexOf('Successfully published') > -1
if (!published) return false
t.ok(published, 'published')
t.same(help.datJson(fixtures).url, oldUrl, 'has dat.json with url')
return true
})
st.stderr.empty()
st.end()
})
})
})

test('auth - clone from registry', function (t) {
// MAKE SURE THESE MATCH WHAT is published above
// TODO: be less lazy and make a publish helper
Expand Down

0 comments on commit 420a540

Please sign in to comment.