From 35fd4cfba80c0e434d082778e6105629165b33d7 Mon Sep 17 00:00:00 2001 From: cel Date: Thu, 29 Nov 2018 15:21:15 -1000 Subject: Integrate with ssb-publishguard redirects --- lib/app.js | 29 ++++++++++++++++++++++++++++- lib/serve.js | 3 ++- 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/lib/app.js b/lib/app.js index fb27e78..b4da954 100644 --- a/lib/app.js +++ b/lib/app.js @@ -224,11 +224,38 @@ App.prototype.getMsgDecryptedOoo = function (key, cb) { }) } +App.prototype.publishMayRedirect = function (content, cb) { + var publishguard = this.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) + } + this.sbot.private.publish(content, recps, cb) + } else { + if (publishguard && publishguard.publishGetUrl) { + return publishguard.publishGetUrl({ + content: content, + redirectBase: this.baseUrl + '/' + }, onPublishGetUrl) + } + this.sbot.publish(content, cb) + } + function onPublishGetUrl(err, url) { + if (err) return cb(err) + cb({redirectUrl: url}) + } +} + App.prototype.publish = function (content, cb) { var self = this function tryPublish(triesLeft) { if (Array.isArray(content.recps)) { - recps = content.recps.map(u.linkDest) + var recps = content.recps.map(u.linkDest) self.sbot.private.publish(content, recps, next) } else { self.sbot.publish(content, next) diff --git a/lib/serve.js b/lib/serve.js index 9d59fa4..db9be20 100644 --- a/lib/serve.js +++ b/lib/serve.js @@ -161,6 +161,7 @@ Serve.prototype.go = function () { function next(err, publishedMsg) { if (err) { + if (err.redirectUrl) return self.redirect(err.redirectUrl) self.res.writeHead(400, {'Content-Type': 'text/plain'}) self.res.end(err.stack) } else if (publishedMsg) { @@ -292,7 +293,7 @@ Serve.prototype.publish = function (content, cb) { }) done(function (err) { if (err) return cb(err) - self.app.publish(content, function (err, msg) { + self.app.publishMayRedirect(content, function (err, msg) { if (err) return cb(err) delete self.data.text delete self.data.recps -- cgit v1.2.3