aboutsummaryrefslogtreecommitdiff
path: root/lib/serve.js
diff options
context:
space:
mode:
Diffstat (limited to 'lib/serve.js')
-rw-r--r--lib/serve.js68
1 files changed, 22 insertions, 46 deletions
diff --git a/lib/serve.js b/lib/serve.js
index dc20141..188b275 100644
--- a/lib/serve.js
+++ b/lib/serve.js
@@ -107,7 +107,8 @@ Serve.prototype.go = function () {
function gotData(err, data) {
self.data = data
if (err) next(err)
- else if (data.action === 'publish') self.publish(next)
+ else if (data.action === 'publish') self.publishJSON(next)
+ else if (data.action === 'vote') self.publishVote(next)
else next()
}
@@ -121,14 +122,31 @@ Serve.prototype.go = function () {
}
}
-Serve.prototype.publish = function (cb) {
- var self = this
+Serve.prototype.publishJSON = function (cb) {
var content
try {
- content = JSON.parse(self.data.content)
+ content = JSON.parse(this.data.content)
} catch(e) {
return cb(e)
}
+ this.publish(content, cb)
+}
+
+Serve.prototype.publishVote = function (cb) {
+ var content = {
+ type: 'vote',
+ vote: {
+ link: this.data.link,
+ value: Number(this.data.value),
+ expression: this.data.expression,
+ }
+ }
+ if (this.data.recps) content.recps = this.data.recps.split(',')
+ this.publish(content, cb)
+}
+
+Serve.prototype.publish = function (content, cb) {
+ var self = this
var done = multicb({pluck: 1, spread: true})
u.toArray(content && content.mentions).forEach(function (mention) {
if (mention.link && mention.link[0] === '&' && !isNaN(mention.size))
@@ -327,48 +345,6 @@ Serve.prototype.links = function (path) {
)
}
-Serve.prototype.vote = function (ext) {
- var self = this
-
- var content = {
- type: 'vote',
- vote: {
- link: self.data.link,
- value: self.data.value,
- expression: self.data.expression,
- }
- }
- if (self.data.recps) content.recps = self.data.recps.split(',')
- self.app.publish(content, function (err, msg) {
- if (err) return pull(
- pull.once(u.renderError(err).outerHTML),
- self.wrapPage(content.vote.expression),
- self.respondSink(500, {
- 'Content-Type': ctype(ext)
- })
- )
-
- pull(
- pull.once(msg),
- pull.asyncMap(self.app.unboxMsg),
- self.app.render.renderFeeds(false),
- pull.map(u.toHTML),
- self.wrapMessages(),
- u.hyperwrap(function (content, cb) {
- cb(null, h('div',
- 'published:',
- content
- ))
- }),
- self.wrapPage('published'),
- self.respondSink(302, {
- 'Content-Type': ctype(ext),
- 'Location': self.app.render.toUrl(msg.key)
- })
- )
- })
-}
-
Serve.prototype.rawId = function (id) {
var self = this