git ssb

0+

Daan Patchwork / ssb-viewer



forked from cel / ssb-viewer

Commit 8c420a8d3bd2ae01b8ecb8409e951c5fde1e0f8d

Limit channel & feed serving by default

Anders Rune Jensen committed on 5/20/2017, 7:37:25 PM
Parent: 54c06b511566bde688d64e44d057778d19a45258

Files changed

index.jschanged
render.jschanged
index.jsView
@@ -92,13 +92,16 @@
9292
9393 function serveFeed(req, res, feedId) {
9494 console.log("serving feed: " + feedId)
9595
96+ var showAll = req.url.endsWith("?showAll")
97+ var showAllHTML = showAll ? '' : '<br/><a href="' + req.url + '?showAll">Show whole feed</a>'
98+
9699 getAbout(feedId, function (err, about) {
97- if (err) return respond(res, 500, err.stack || err)
100+ if (err) return respond(res, 500, err.stack || err)
98101
99102 pull(
100- sbot.createUserStream({ id: feedId, reverse: true }),
103+ sbot.createUserStream({ id: feedId, reverse: true, limit: showAll ? -1 : 10 }),
101104 pull.collect(function (err, logs) {
102105 if (err) return respond(res, 500, err.stack || err)
103106 res.writeHead(200, {
104107 'Content-Type': ctype("html")
@@ -108,9 +111,9 @@
108111 paramap(addAuthorAbout, 8),
109112 paramap(addFollowAbout, 8),
110113 paramap(addVoteMessage, 8),
111114 paramap(addGitLinks, 8),
112- pull(renderAbout(defaultOpts, about), wrapPage(about.name)),
115+ pull(renderAbout(defaultOpts, about, showAllHTML), wrapPage(about.name)),
113116 toPull(res, function (err) {
114117 if (err) console.error('[viewer]', err)
115118 })
116119 )
@@ -190,11 +193,14 @@
190193
191194 function serveChannel(req, res, url) {
192195 var channelId = url.substring(url.lastIndexOf('channel/')+8, 100)
193196 console.log("serving channel: " + channelId)
197+
198+ var showAll = req.url.endsWith("?showAll")
199+ var showAllHTML = showAll ? '' : '<br/><a href="' + req.url + '?showAll">Show whole feed</a>'
194200
195201 pull(
196- sbot.query.read({ limit: 500, reverse: true, query: [{$filter: { value: { content: { channel: channelId }}}}]}),
202+ sbot.query.read({ limit: showAll ? 300 : 10, reverse: true, query: [{$filter: { value: { content: { channel: channelId }}}}]}),
197203 pull.collect(function (err, logs) {
198204 if (err) return respond(res, 500, err.stack || err)
199205 res.writeHead(200, {
200206 'Content-Type': ctype("html")
@@ -202,9 +208,9 @@
202208 pull(
203209 pull.values(logs),
204210 paramap(addAuthorAbout, 8),
205211 paramap(addVoteMessage, 8),
206- pull(renderThread(defaultOpts), wrapPage('#' + channelId)),
212+ pull(renderThread(defaultOpts, showAllHTML), wrapPage('#' + channelId)),
207213 toPull(res, function (err) {
208214 if (err) console.error('[viewer]', err)
209215 })
210216 )
render.jsView
@@ -94,9 +94,9 @@
9494 return cat([pull.once(before), read, pull.once(after)]);
9595 };
9696 }
9797
98-function renderAbout(opts, about) {
98+function renderAbout(opts, about, showAllHTML = "") {
9999 return pull(
100100 pull.map(renderMsg.bind(this, opts)),
101101 wrap(
102102 '<span class="top-tip">You are reading content from ' +
@@ -110,26 +110,26 @@
110110 (about.description != undefined ?
111111 marked(about.description, opts.marked) : '') +
112112 '</figcaption></figure></header></article>',
113113
114- '</main>' +
114+ showAllHTML + '</main>' +
115115 '<a class="call-to-action" href="https://www.scuttlebutt.nz">' +
116116 'Join Scuttlebutt now' +
117117 '</a>'
118118 )
119119 );
120120 }
121121
122-function renderThread(opts) {
122+function renderThread(opts, showAllHTML = "") {
123123 return pull(
124124 pull.map(renderMsg.bind(this, opts)),
125125 wrap(
126126 '<span class="top-tip">You are reading content from ' +
127127 '<a href="https://www.scuttlebutt.nz">Scuttlebutt</a>' +
128128 '</span>' +
129129 '<main>',
130130
131- '</main>' +
131+ showAllHTML + '</main>' +
132132 '<a class="call-to-action" href="https://www.scuttlebutt.nz">' +
133133 'Join Scuttlebutt now' +
134134 '</a>'
135135 )

Built with git-ssb-web