diff options
Diffstat (limited to 'lib/serve.js')
-rw-r--r-- | lib/serve.js | 33 |
1 files changed, 32 insertions, 1 deletions
diff --git a/lib/serve.js b/lib/serve.js index 353b60a..a965573 100644 --- a/lib/serve.js +++ b/lib/serve.js @@ -64,6 +64,8 @@ function Serve(app, req, res) { this.req = req this.res = res this.startDate = new Date() + var hostname = req.headers.host || app.hostname + this.baseUrl = 'http://' + hostname + (app.opts.base || '/') } Serve.prototype.go = function () { @@ -333,7 +335,7 @@ Serve.prototype.publish = function (content, cb) { }) done(function (err) { if (err) return cb(err) - self.app.publishMayRedirect(content, function (err, msg) { + self.publishMayRedirect(content, function (err, msg) { if (err) return cb(err) delete self.data.text delete self.data.recps @@ -342,6 +344,35 @@ Serve.prototype.publish = function (content, cb) { }) } +Serve.prototype.publishMayRedirect = function (content, cb) { + var publishguard = this.app.sbot.publishguard + if (Array.isArray(content.recps)) { + var recps = content.recps.map(u.linkDest) + if (publishguard && publishguard.privatePublishGetUrl) { + return publishguard.privatePublishGetUrl({ + content: content, + recps: recps, + redirectBase: this.baseUrl + }, onPublishGetUrl) + } else { + this.app.privatePublish(content, recps, cb) + } + } else { + if (publishguard && publishguard.publishGetUrl) { + publishguard.publishGetUrl({ + content: content, + redirectBase: this.baseUrl + }, onPublishGetUrl) + } else { + this.app.sbot.publish(content, cb) + } + } + function onPublishGetUrl(err, url) { + if (err) return cb(err) + cb({redirectUrl: url}) + } +} + Serve.prototype.handle = function () { var m = urlIdRegex.exec(this.req.url) this.query = m[5] ? qs.parse(m[5]) : {} |