From 946379b16a68ffd636d8fed3925367cfa8e2e6f6 Mon Sep 17 00:00:00 2001 From: cel Date: Sat, 18 Aug 2018 11:13:21 -0700 Subject: Render some dark-crystal stuff --- lib/app.js | 13 +++++++++++++ lib/render-msg.js | 30 ++++++++++++++++++++++++++++++ lib/serve.js | 31 ++++++++++++++++++++++++++++++- 3 files changed, 73 insertions(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/app.js b/lib/app.js index b63a13e..5b3035a 100644 --- a/lib/app.js +++ b/lib/app.js @@ -1019,3 +1019,16 @@ App.prototype.getThread = function (msg) { }) ]) } + +App.prototype.getShard = function (id, cb) { + var self = this + this.getMsgDecrypted(id, function (err, msg) { + if (err) return cb(new Error('Unable to get shard message: ' + err.stack)) + var c = msg.value.content || {} + if (!c.shard) return cb(new Error('Message missing shard: ' + id)) + self.unboxContent(c.shard, function (err, shard) { + if (err) return cb(new Error('Unable to decrypt shard: ' + err.stack)) + cb(null, shard) + }) + }) +} diff --git a/lib/render-msg.js b/lib/render-msg.js index 89a5f90..5fcf9ff 100644 --- a/lib/render-msg.js +++ b/lib/render-msg.js @@ -306,6 +306,8 @@ RenderMsg.prototype.message = function (cb) { case 'share': return this.share(cb) case 'tag': return this.tag(cb) case 'edit': return this.edit(cb) + case 'dark-crystal/shard': return this.shard(cb) + case 'invite': return this.invite(cb) default: return this.object(cb) } } @@ -1916,3 +1918,31 @@ RenderMsg.prototype.tagTitle = function (cb) { + msgName + ' as ' + rootName) }) } + +RenderMsg.prototype.shard = function (cb) { + // this.c.errors + // this.c.version + var self = this + self.link(self.c.root, function (err, rootLink) { + self.wrap(h('div', [ + h('div', h('small', h('span.symbol', '  ↳'), ' dark-crystal ', rootLink || '?')), + h('p', [ + h('a', { + href: self.toUrl('/shard/' + encodeURIComponent(self.msg.key)), + title: 'view shard' + }, 'shard') + ]) + ]), cb) + }) +} + +RenderMsg.prototype.invite = function (cb) { + // this.c.version + var self = this + self.link(self.c.root, function (err, rootLink) { + self.wrap(h('div', [ + h('div', h('small', h('span.symbol', '  ↳'), ' ', rootLink || '?')), + self.c.body ? h('div', {innerHTML: self.render.markdown(self.c.body)}) : '', + ]), cb) + }) +} diff --git a/lib/serve.js b/lib/serve.js index 2eba468..92d6065 100644 --- a/lib/serve.js +++ b/lib/serve.js @@ -378,6 +378,7 @@ Serve.prototype.path = function (url) { case '/npm-registry': return this.npmRegistry(m[2]) case '/markdown': return this.markdown(m[2]) case '/edit-diff': return this.editDiff(m[2]) + case '/shard': return this.shard(m[2]) case '/zip': return this.zip(m[2]) case '/web': return this.web(m[2]) } @@ -3478,7 +3479,11 @@ Serve.prototype.editDiff = function (url) { try { id = decodeURIComponent(url.substr(1)) } catch(err) { - return ph('div', u.renderError(err).outerHTML) + return pull( + pull.once(u.renderError(err).outerHTML), + self.wrapPage('diff: ' + id), + self.respondSink(400) + ) } return pull( ph('section', {}, [ @@ -3547,3 +3552,27 @@ Serve.prototype.postEditDiffTable = function (oldMsg, newMsg) { ]) ) } + +Serve.prototype.shard = function (url) { + var self = this + var id + try { + id = decodeURIComponent(url.substr(1)) + } catch(err) { + return onError(err) + } + function onError(err) { + pull( + pull.once(u.renderError(err).outerHTML), + self.wrapPage('shard: ' + id), + self.respondSink(400) + ) + } + self.app.getShard(id, function (err, shard) { + if (err) return onError(err) + pull( + pull.once(shard), + self.respondSink(200, {'Content-Type': 'text/plain'}) + ) + }) +} -- cgit v1.2.3