git ssb

9+

cel / ssb-viewer



Commit 58e51b98743793a144acbba06d639beb926b51db

Better headers

Anders Rune Jensen committed on 5/11/2017, 7:15:38 PM
Parent: bd1f870b33c574c0a2d6808e3d3fef576d53374e

Files changed

index.jschanged
index.jsView
@@ -119,27 +119,31 @@
119119 emoji: renderEmoji,
120120 renderer: new MdRenderer(opts)
121121 }
122122
123- pull(
124- sbot.createUserStream({ id: feedId, reverse: true }),
125- pull.collect(function (err, logs) {
126- if (err) return respond(res, 500, err.stack || err)
127- res.writeHead(200, {
128- 'Content-Type': ctype("html")
123 + getAbout(feedId, function (err, about) {
124 + if (err) return cb(err)
125 +
126 + pull(
127 + sbot.createUserStream({ id: feedId, reverse: true }),
128 + pull.collect(function (err, logs) {
129 + if (err) return respond(res, 500, err.stack || err)
130 + res.writeHead(200, {
131 + 'Content-Type': ctype("html")
132 + })
133 + pull(
134 + pull.values(logs),
135 + paramap(addAuthorAbout, 8),
136 + paramap(addFollowAbout, 8),
137 + paramap(addVoteMessage, 8),
138 + pull(renderThread(opts), wrapPage(about.name)),
139 + toPull(res, function (err) {
140 + if (err) console.error('[viewer]', err)
141 + })
142 + )
129143 })
130- pull(
131- pull.values(logs),
132- paramap(addAuthorAbout, 8),
133- paramap(addFollowAbout, 8),
134- paramap(addVoteMessage, 8),
135- pull(renderThread(opts), wrapPage(feedId)),
136- toPull(res, function (err) {
137- if (err) console.error('[viewer]', err)
138- })
139- )
140- })
141- )
144 + )
145 + })
142146 }
143147
144148 function serveUserFeed(req, res, url) {
145149 var feedId = url.substring(url.lastIndexOf('user-feed/')+10, 100)
@@ -147,40 +151,42 @@
147151
148152 var following = []
149153 var channelSubscriptions = []
150154
151- pull(
152- sbot.createUserStream({ id: feedId }),
153- pull.filter((msg) => {
154- return !msg.value ||
155- msg.value.content.type == 'contact' ||
156- (msg.value.content.type == 'channel' &&
157- typeof msg.value.content.subscribed != 'undefined')
158- }),
159- pull.collect(function (err, msgs) {
160- msgs.forEach((msg) => {
161- if (msg.value.content.type == 'contact')
162- {
163- if (msg.value.content.following)
164- following[msg.value.content.contact] = 1
165- else
166- delete following[msg.value.content.contact]
167- }
168- else // channel subscription
169- {
170- if (msg.value.content.subscribed)
171- channelSubscriptions[msg.value.content.channel] = 1
172- else
173- delete following[msg.value.content.channel]
174- }
155 + getAbout(feedId, function (err, about) {
156 + pull(
157 + sbot.createUserStream({ id: feedId }),
158 + pull.filter((msg) => {
159 + return !msg.value ||
160 + msg.value.content.type == 'contact' ||
161 + (msg.value.content.type == 'channel' &&
162 + typeof msg.value.content.subscribed != 'undefined')
163 + }),
164 + pull.collect(function (err, msgs) {
165 + msgs.forEach((msg) => {
166 + if (msg.value.content.type == 'contact')
167 + {
168 + if (msg.value.content.following)
169 + following[msg.value.content.contact] = 1
170 + else
171 + delete following[msg.value.content.contact]
172 + }
173 + else // channel subscription
174 + {
175 + if (msg.value.content.subscribed)
176 + channelSubscriptions[msg.value.content.channel] = 1
177 + else
178 + delete following[msg.value.content.channel]
179 + }
180 + })
181 +
182 + serveFeeds(req, res, following, channelSubscriptions, feedId, 'user feed ' + about.name)
175183 })
176-
177- serveFeeds(req, res, following, channelSubscriptions, feedId)
178- })
179- )
184 + )
185 + })
180186 }
181187
182- function serveFeeds(req, res, following, channelSubscriptions, feedId) {
188 + function serveFeeds(req, res, following, channelSubscriptions, feedId, name) {
183189 var opts = defaultOpts
184190
185191 opts.marked = {
186192 gfm: true,
@@ -212,9 +218,9 @@
212218 pull.values(logs),
213219 paramap(addAuthorAbout, 8),
214220 paramap(addFollowAbout, 8),
215221 paramap(addVoteMessage, 8),
216- pull(renderThread(opts), wrapPage(feedId)),
222 + pull(renderThread(opts), wrapPage(name)),
217223 toPull(res, function (err) {
218224 if (err) console.error('[viewer]', err)
219225 })
220226 )
@@ -251,9 +257,9 @@
251257 pull(
252258 pull.values(logs),
253259 paramap(addAuthorAbout, 8),
254260 paramap(addVoteMessage, 8),
255- pull(renderThread(opts), wrapPage(channelId)),
261 + pull(renderThread(opts), wrapPage('#' + channelId)),
256262 toPull(res, function (err) {
257263 if (err) console.error('[viewer]', err)
258264 })
259265 )
@@ -480,9 +486,9 @@
480486
481487 function wrapPage(id) {
482488 return wrap('<!doctype html><html><head>'
483489 + '<meta charset=utf-8>'
484- + '<title>' + id + '</title>'
490 + + '<title>' + id + ' | ssb-viewer</title>'
485491 + '<meta name=viewport content="width=device-width,initial-scale=1">'
486492 + '<link rel=stylesheet href="/static/base.css">'
487493 + '<link rel=stylesheet href="/static/nicer.css">'
488494 + '</head><body>',

Built with git-ssb-web