Better headers

This commit is contained in:
Anders Rune Jensen
2017-05-11 21:15:38 +02:00
parent bd1f870b33
commit 58e51b9874
+56 -50
View File
@@ -120,25 +120,29 @@ exports.init = function (sbot, config) {
renderer: new MdRenderer(opts) renderer: new MdRenderer(opts)
} }
pull( getAbout(feedId, function (err, about) {
sbot.createUserStream({ id: feedId, reverse: true }), if (err) return cb(err)
pull.collect(function (err, logs) {
if (err) return respond(res, 500, err.stack || err) pull(
res.writeHead(200, { sbot.createUserStream({ id: feedId, reverse: true }),
'Content-Type': ctype("html") pull.collect(function (err, logs) {
}) if (err) return respond(res, 500, err.stack || err)
pull( res.writeHead(200, {
pull.values(logs), 'Content-Type': ctype("html")
paramap(addAuthorAbout, 8),
paramap(addFollowAbout, 8),
paramap(addVoteMessage, 8),
pull(renderThread(opts), wrapPage(feedId)),
toPull(res, function (err) {
if (err) console.error('[viewer]', err)
}) })
) pull(
}) pull.values(logs),
) paramap(addAuthorAbout, 8),
paramap(addFollowAbout, 8),
paramap(addVoteMessage, 8),
pull(renderThread(opts), wrapPage(about.name)),
toPull(res, function (err) {
if (err) console.error('[viewer]', err)
})
)
})
)
})
} }
function serveUserFeed(req, res, url) { function serveUserFeed(req, res, url) {
@@ -148,38 +152,40 @@ exports.init = function (sbot, config) {
var following = [] var following = []
var channelSubscriptions = [] var channelSubscriptions = []
pull( getAbout(feedId, function (err, about) {
sbot.createUserStream({ id: feedId }), pull(
pull.filter((msg) => { sbot.createUserStream({ id: feedId }),
return !msg.value || pull.filter((msg) => {
msg.value.content.type == 'contact' || return !msg.value ||
(msg.value.content.type == 'channel' && msg.value.content.type == 'contact' ||
typeof msg.value.content.subscribed != 'undefined') (msg.value.content.type == 'channel' &&
}), typeof msg.value.content.subscribed != 'undefined')
pull.collect(function (err, msgs) { }),
msgs.forEach((msg) => { pull.collect(function (err, msgs) {
if (msg.value.content.type == 'contact') msgs.forEach((msg) => {
{ if (msg.value.content.type == 'contact')
if (msg.value.content.following) {
following[msg.value.content.contact] = 1 if (msg.value.content.following)
else following[msg.value.content.contact] = 1
delete following[msg.value.content.contact] else
} delete following[msg.value.content.contact]
else // channel subscription }
{ else // channel subscription
if (msg.value.content.subscribed) {
channelSubscriptions[msg.value.content.channel] = 1 if (msg.value.content.subscribed)
else channelSubscriptions[msg.value.content.channel] = 1
delete following[msg.value.content.channel] else
} delete following[msg.value.content.channel]
}) }
})
serveFeeds(req, res, following, channelSubscriptions, feedId) serveFeeds(req, res, following, channelSubscriptions, feedId, 'user feed ' + about.name)
}) })
) )
})
} }
function serveFeeds(req, res, following, channelSubscriptions, feedId) { function serveFeeds(req, res, following, channelSubscriptions, feedId, name) {
var opts = defaultOpts var opts = defaultOpts
opts.marked = { opts.marked = {
@@ -213,7 +219,7 @@ exports.init = function (sbot, config) {
paramap(addAuthorAbout, 8), paramap(addAuthorAbout, 8),
paramap(addFollowAbout, 8), paramap(addFollowAbout, 8),
paramap(addVoteMessage, 8), paramap(addVoteMessage, 8),
pull(renderThread(opts), wrapPage(feedId)), pull(renderThread(opts), wrapPage(name)),
toPull(res, function (err) { toPull(res, function (err) {
if (err) console.error('[viewer]', err) if (err) console.error('[viewer]', err)
}) })
@@ -252,7 +258,7 @@ exports.init = function (sbot, config) {
pull.values(logs), pull.values(logs),
paramap(addAuthorAbout, 8), paramap(addAuthorAbout, 8),
paramap(addVoteMessage, 8), paramap(addVoteMessage, 8),
pull(renderThread(opts), wrapPage(channelId)), pull(renderThread(opts), wrapPage('#' + channelId)),
toPull(res, function (err) { toPull(res, function (err) {
if (err) console.error('[viewer]', err) if (err) console.error('[viewer]', err)
}) })
@@ -481,7 +487,7 @@ function renderThread(opts) {
function wrapPage(id) { function wrapPage(id) {
return wrap('<!doctype html><html><head>' return wrap('<!doctype html><html><head>'
+ '<meta charset=utf-8>' + '<meta charset=utf-8>'
+ '<title>' + id + '</title>' + '<title>' + id + ' | ssb-viewer</title>'
+ '<meta name=viewport content="width=device-width,initial-scale=1">' + '<meta name=viewport content="width=device-width,initial-scale=1">'
+ '<link rel=stylesheet href="/static/base.css">' + '<link rel=stylesheet href="/static/base.css">'
+ '<link rel=stylesheet href="/static/nicer.css">' + '<link rel=stylesheet href="/static/nicer.css">'