git ssb

9+

cel / ssb-viewer



Commit 27f58a3795183b40043200e73de834d45fee2213

serve channel feeds

Anders Rune Jensen committed on 4/15/2017, 10:35:44 AM
Parent: d02df33849f9c3af8ae077841a35a453f402dc84

Files changed

index.jschanged
index.jsView
@@ -86,8 +86,9 @@
8686
8787 var m = urlIdRegex.exec(req.url)
8888
8989 if (req.url.startsWith('/user')) return serveFeed(req, res, m[4])
90 + else if (req.url.startsWith('/channel')) return serveChannel(req, res, m[4])
9091
9192 switch (m[2]) {
9293 case '%25': m[2] = '%'; m[1] = decodeURIComponent(m[1])
9394 case '%': return serveId(req, res, m[1], m[3], m[5])
@@ -115,9 +116,9 @@
115116 renderer: new MdRenderer(opts)
116117 }
117118
118119 pull(
119- sbot.createUserStream({ id: feedId, reverse: true }),
120 + sbot.createUserStream({ id: feedId, reverse: true, limit: 100 }),
120121 pull.collect(function (err, logs) {
121122 if (err) return respond(res, 500, err.stack || err)
122123 res.writeHead(200, {
123124 'Content-Type': ctype("html")
@@ -134,8 +135,52 @@
134135 })
135136 )
136137 }
137138
139 + function serveChannel(req, res, url) {
140 + var channelId = url.substring(url.lastIndexOf('channel/')+8, 100)
141 + console.log("serving channel: " + channelId)
142 +
143 + var opts = defaultOpts
144 +
145 + opts.marked = {
146 + gfm: true,
147 + mentions: true,
148 + tables: true,
149 + breaks: true,
150 + pedantic: false,
151 + sanitize: true,
152 + smartLists: true,
153 + smartypants: false,
154 + emoji: renderEmoji,
155 + renderer: new MdRenderer(opts)
156 + }
157 +
158 + pull(
159 + sbot.createLogStream({ reverse: true, limit: 10000 }),
160 + pull.filter((msg) => {
161 + return !msg.value || msg.value.content.channel == channelId
162 + }),
163 + pull.filter((msg) => {
164 + return !msg.value.content.subscribed
165 + }),
166 + pull.collect(function (err, logs) {
167 + if (err) return respond(res, 500, err.stack || err)
168 + res.writeHead(200, {
169 + 'Content-Type': ctype("html")
170 + })
171 + pull(
172 + pull.values(logs),
173 + paramap(addAuthorAbout, 8),
174 + pull(renderThread(opts), wrapPage(channelId)),
175 + toPull(res, function (err) {
176 + if (err) console.error('[viewer]', err)
177 + })
178 + )
179 + })
180 + )
181 + }
182 +
138183 function addFollowAbout(msg, cb) {
139184 if (msg.value.content.contact)
140185 getAbout(msg.value.content.contact, function (err, about) {
141186 if (err) return cb(err)

Built with git-ssb-web