git ssb

0+

Daan Patchwork / ssb-viewer



forked from cel / ssb-viewer

Commit 9ba7dc35e388b5a7425bd0899e99160b4ed8e6a7

Indention fix

Anders Rune Jensen committed on 12/16/2017, 2:03:05 PM
Parent: 941de4f1ac468a300bc8885ef2e2338bb8e1a429

Files changed

index.jschanged
render.jschanged
index.jsView
@@ -10,17 +10,17 @@
1010 var memo = require('asyncmemo')
1111 var lru = require('lrucache')
1212 var serveEmoji = require('emoji-server')()
1313 var {
14- MdRenderer,
15- renderEmoji,
16- formatMsgs,
17- wrapPage,
18- renderThread,
19- renderAbout,
20- renderShowAll,
21- renderRssItem,
22- wrapRss,
14+ MdRenderer,
15+ renderEmoji,
16+ formatMsgs,
17+ wrapPage,
18+ renderThread,
19+ renderAbout,
20+ renderShowAll,
21+ renderRssItem,
22+ wrapRss,
2323 } = require('./render');
2424
2525 var appHash = hash([fs.readFileSync(__filename)])
2626
@@ -51,18 +51,18 @@
5151 emoji_base: conf.emoji_base || (base + 'emoji/'),
5252 }
5353
5454 defaultOpts.marked = {
55- gfm: true,
56- mentions: true,
57- tables: true,
58- breaks: true,
59- pedantic: false,
60- sanitize: true,
61- smartLists: true,
62- smartypants: false,
63- emoji: renderEmoji,
64- renderer: new MdRenderer(defaultOpts)
55+ gfm: true,
56+ mentions: true,
57+ tables: true,
58+ breaks: true,
59+ pedantic: false,
60+ sanitize: true,
61+ smartLists: true,
62+ smartypants: false,
63+ emoji: renderEmoji,
64+ renderer: new MdRenderer(defaultOpts)
6565 }
6666
6767 var getMsg = memo({cache: lru(100)}, getMsgWithValue, sbot)
6868 var getAbout = memo({cache: lru(100)}, require('./lib/about'), sbot)
@@ -95,148 +95,148 @@
9595 }
9696 }
9797
9898 function serveFeed(req, res, feedId, ext) {
99- console.log("serving feed: " + feedId)
99+ console.log("serving feed: " + feedId)
100100
101- var showAll = req.url.endsWith("?showAll");
101+ var showAll = req.url.endsWith("?showAll");
102102
103- getAbout(feedId, function (err, about) {
104- if (err) return respond(res, 500, err.stack || err)
103+ getAbout(feedId, function (err, about) {
104+ if (err) return respond(res, 500, err.stack || err)
105105
106- function render() {
107- switch (ext) {
108- case 'rss':
109- return pull(
110- // formatMsgs(feedId, ext, defaultOpts)
111- renderRssItem(defaultOpts), wrapRss(about.name, defaultOpts)
112- );
113- default:
114- return pull(
115- renderAbout(defaultOpts, about,
116- renderShowAll(showAll, req.url)), wrapPage(about.name)
117- );
118- }
119- }
106+ function render() {
107+ switch (ext) {
108+ case 'rss':
109+ return pull(
110+ // formatMsgs(feedId, ext, defaultOpts)
111+ renderRssItem(defaultOpts), wrapRss(about.name, defaultOpts)
112+ );
113+ default:
114+ return pull(
115+ renderAbout(defaultOpts, about,
116+ renderShowAll(showAll, req.url)), wrapPage(about.name)
117+ );
118+ }
119+ }
120120
121+ pull(
122+ sbot.createUserStream({ id: feedId, reverse: true, limit: showAll ? -1 : (ext == 'rss' ? 25 : 10) }),
123+ pull.collect(function (err, logs) {
124+ if (err) return respond(res, 500, err.stack || err)
125+ res.writeHead(200, {
126+ 'Content-Type': ctype(ext)
127+ })
121128 pull(
122- sbot.createUserStream({ id: feedId, reverse: true, limit: showAll ? -1 : (ext == 'rss' ? 25 :10) }),
123- pull.collect(function (err, logs) {
124- if (err) return respond(res, 500, err.stack || err)
125- res.writeHead(200, {
126- 'Content-Type': ctype(ext)
127- })
128- pull(
129- pull.values(logs),
130- paramap(addAuthorAbout, 8),
131- paramap(addFollowAbout, 8),
132- paramap(addVoteMessage, 8),
133- paramap(addGitLinks, 8),
134- render(),
135- toPull(res, function (err) {
136- if (err) console.error('[viewer]', err)
137- })
138- )
139- })
129+ pull.values(logs),
130+ paramap(addAuthorAbout, 8),
131+ paramap(addFollowAbout, 8),
132+ paramap(addVoteMessage, 8),
133+ paramap(addGitLinks, 8),
134+ render(),
135+ toPull(res, function (err) {
136+ if (err) console.error('[viewer]', err)
137+ })
140138 )
141- })
139+ })
140+ )
141+ })
142142 }
143143
144144 function serveUserFeed(req, res, url) {
145- var feedId = url.substring(url.lastIndexOf('user-feed/')+10, 100)
146- console.log("serving user feed: " + feedId)
145+ var feedId = url.substring(url.lastIndexOf('user-feed/')+10, 100)
146+ console.log("serving user feed: " + feedId)
147147
148- var following = []
149- var channelSubscriptions = []
150-
151- getAbout(feedId, function (err, about) {
152- pull(
153- sbot.createUserStream({ id: feedId }),
154- pull.filter((msg) => {
155- return !msg.value ||
156- msg.value.content.type == 'contact' ||
157- (msg.value.content.type == 'channel' &&
158- typeof msg.value.content.subscribed != 'undefined')
159- }),
160- pull.collect(function (err, msgs) {
161- msgs.forEach((msg) => {
162- if (msg.value.content.type == 'contact')
163- {
164- if (msg.value.content.following)
165- following[msg.value.content.contact] = 1
166- else
167- delete following[msg.value.content.contact]
168- }
169- else // channel subscription
170- {
171- if (msg.value.content.subscribed)
172- channelSubscriptions[msg.value.content.channel] = 1
173- else
174- delete channelSubscriptions[msg.value.content.channel]
175- }
176- })
177-
178- serveFeeds(req, res, following, channelSubscriptions, feedId, 'user feed ' + (about ? about.name : ""))
179- })
180- )
181- })
148+ var following = []
149+ var channelSubscriptions = []
150+
151+ getAbout(feedId, function (err, about) {
152+ pull(
153+ sbot.createUserStream({ id: feedId }),
154+ pull.filter((msg) => {
155+ return !msg.value ||
156+ msg.value.content.type == 'contact' ||
157+ (msg.value.content.type == 'channel' &&
158+ typeof msg.value.content.subscribed != 'undefined')
159+ }),
160+ pull.collect(function (err, msgs) {
161+ msgs.forEach((msg) => {
162+ if (msg.value.content.type == 'contact')
163+ {
164+ if (msg.value.content.following)
165+ following[msg.value.content.contact] = 1
166+ else
167+ delete following[msg.value.content.contact]
168+ }
169+ else // channel subscription
170+ {
171+ if (msg.value.content.subscribed)
172+ channelSubscriptions[msg.value.content.channel] = 1
173+ else
174+ delete channelSubscriptions[msg.value.content.channel]
175+ }
176+ })
177+
178+ serveFeeds(req, res, following, channelSubscriptions, feedId, 'user feed ' + (about ? about.name : ""))
179+ })
180+ )
181+ })
182182 }
183183
184184 function serveFeeds(req, res, following, channelSubscriptions, feedId, name) {
185- pull(
186- sbot.createLogStream({ reverse: true, limit: 5000 }),
187- pull.filter((msg) => {
188- return !msg.value ||
189- (msg.value.author in following ||
190- msg.value.content.channel in channelSubscriptions)
191- }),
192- pull.take(150),
193- pull.collect(function (err, logs) {
194- if (err) return respond(res, 500, err.stack || err)
195- res.writeHead(200, {
196- 'Content-Type': ctype("html")
197- })
198- pull(
199- pull.values(logs),
200- paramap(addAuthorAbout, 8),
201- paramap(addFollowAbout, 8),
202- paramap(addVoteMessage, 8),
203- paramap(addGitLinks, 8),
204- pull(renderThread(defaultOpts), wrapPage(name)),
205- toPull(res, function (err) {
206- if (err) console.error('[viewer]', err)
207- })
208- )
185+ pull(
186+ sbot.createLogStream({ reverse: true, limit: 5000 }),
187+ pull.filter((msg) => {
188+ return !msg.value ||
189+ (msg.value.author in following ||
190+ msg.value.content.channel in channelSubscriptions)
191+ }),
192+ pull.take(150),
193+ pull.collect(function (err, logs) {
194+ if (err) return respond(res, 500, err.stack || err)
195+ res.writeHead(200, {
196+ 'Content-Type': ctype("html")
197+ })
198+ pull(
199+ pull.values(logs),
200+ paramap(addAuthorAbout, 8),
201+ paramap(addFollowAbout, 8),
202+ paramap(addVoteMessage, 8),
203+ paramap(addGitLinks, 8),
204+ pull(renderThread(defaultOpts), wrapPage(name)),
205+ toPull(res, function (err) {
206+ if (err) console.error('[viewer]', err)
209207 })
210- )
208+ )
209+ })
210+ )
211211 }
212212
213213 function serveChannel(req, res, url) {
214- var channelId = url.substring(url.lastIndexOf('channel/')+8, 100)
215- console.log("serving channel: " + channelId)
214+ var channelId = url.substring(url.lastIndexOf('channel/')+8, 100)
215+ console.log("serving channel: " + channelId)
216216
217- var showAll = req.url.endsWith("?showAll")
218-
219- pull(
220- sbot.query.read({ limit: showAll ? 300 : 10, reverse: true, query: [{$filter: { value: { content: { channel: channelId }}}}]}),
221- pull.collect(function (err, logs) {
222- if (err) return respond(res, 500, err.stack || err)
223- res.writeHead(200, {
224- 'Content-Type': ctype("html")
225- })
226- pull(
227- pull.values(logs),
228- paramap(addAuthorAbout, 8),
229- paramap(addVoteMessage, 8),
230- pull(renderThread(defaultOpts, '',
231- renderShowAll(showAll, req.url)),
232- wrapPage('#' + channelId)),
233- toPull(res, function (err) {
234- if (err) console.error('[viewer]', err)
235- })
236- )
217+ var showAll = req.url.endsWith("?showAll")
218+
219+ pull(
220+ sbot.query.read({ limit: showAll ? 300 : 10, reverse: true, query: [{$filter: { value: { content: { channel: channelId }}}}]}),
221+ pull.collect(function (err, logs) {
222+ if (err) return respond(res, 500, err.stack || err)
223+ res.writeHead(200, {
224+ 'Content-Type': ctype("html")
225+ })
226+ pull(
227+ pull.values(logs),
228+ paramap(addAuthorAbout, 8),
229+ paramap(addVoteMessage, 8),
230+ pull(renderThread(defaultOpts, '',
231+ renderShowAll(showAll, req.url)),
232+ wrapPage('#' + channelId)),
233+ toPull(res, function (err) {
234+ if (err) console.error('[viewer]', err)
237235 })
238- )
236+ )
237+ })
238+ )
239239 }
240240
241241 function serveId(req, res, id, ext, query) {
242242 var q = query ? qs.parse(query) : {}
@@ -296,27 +296,27 @@
296296 )
297297 }
298298
299299 function addFollowAbout(msg, cb) {
300- if (msg.value.content.contact)
301- getAbout(msg.value.content.contact, function (err, about) {
302- if (err) return cb(err)
303- msg.value.content.contactAbout = about
304- cb(null, msg)
305- })
306- else
307- cb(null, msg)
300+ if (msg.value.content.contact)
301+ getAbout(msg.value.content.contact, function (err, about) {
302+ if (err) return cb(err)
303+ msg.value.content.contactAbout = about
304+ cb(null, msg)
305+ })
306+ else
307+ cb(null, msg)
308308 }
309309
310310 function addVoteMessage(msg, cb) {
311- if (msg.value.content.type == 'vote' && msg.value.content.vote.link[0] == '%')
312- getMsg(msg.value.content.vote.link, function (err, linkedMsg) {
313- if (linkedMsg)
314- msg.value.content.vote.linkedText = linkedMsg.value.content.text
315- cb(null, msg)
316- })
317- else
318- cb(null, msg)
311+ if (msg.value.content.type == 'vote' && msg.value.content.vote.link[0] == '%')
312+ getMsg(msg.value.content.vote.link, function (err, linkedMsg) {
313+ if (linkedMsg)
314+ msg.value.content.vote.linkedText = linkedMsg.value.content.text
315+ cb(null, msg)
316+ })
317+ else
318+ cb(null, msg)
319319 }
320320
321321 function addAuthorAbout(msg, cb) {
322322 getAbout(msg.value.author, function (err, about) {
@@ -326,22 +326,22 @@
326326 })
327327 }
328328
329329 function addGitLinks(msg, cb) {
330- if (msg.value.content.type == 'git-update')
331- getMsg(msg.value.content.repo, function (err, gitRepo) {
332- if (gitRepo)
333- msg.value.content.repoName = gitRepo.value.content.name
334- cb(null, msg)
335- })
336- else if (msg.value.content.type == 'issue')
337- getMsg(msg.value.content.project, function (err, gitRepo) {
338- if (gitRepo)
339- msg.value.content.repoName = gitRepo.value.content.name
340- cb(null, msg)
341- })
342- else
343- cb(null, msg)
330+ if (msg.value.content.type == 'git-update')
331+ getMsg(msg.value.content.repo, function (err, gitRepo) {
332+ if (gitRepo)
333+ msg.value.content.repoName = gitRepo.value.content.name
334+ cb(null, msg)
335+ })
336+ else if (msg.value.content.type == 'issue')
337+ getMsg(msg.value.content.project, function (err, gitRepo) {
338+ if (gitRepo)
339+ msg.value.content.repoName = gitRepo.value.content.name
340+ cb(null, msg)
341+ })
342+ else
343+ cb(null, msg)
344344 }
345345 }
346346
347347 function serveBlob(req, res, sbot, id) {
render.jsView
@@ -514,9 +514,9 @@
514514 return h('pre', JSON.stringify(c, 0, 2));
515515 }
516516
517517 function renderShowAll(showAll, url) {
518- if (showAll)
519- return '';
520- else
521- return '<br>' + h('a', { href : url + '?showAll' }, 'Show whole feed').outerHTML;
518+ if (showAll)
519+ return '';
520+ else
521+ return '<br>' + h('a', { href : url + '?showAll' }, 'Show whole feed').outerHTML;
522522 }

Built with git-ssb-web