Limit channel & feed serving by default
This commit is contained in:
@@ -93,11 +93,14 @@ exports.init = function (sbot, config) {
|
|||||||
function serveFeed(req, res, feedId) {
|
function serveFeed(req, res, feedId) {
|
||||||
console.log("serving feed: " + feedId)
|
console.log("serving feed: " + feedId)
|
||||||
|
|
||||||
|
var showAll = req.url.endsWith("?showAll")
|
||||||
|
var showAllHTML = showAll ? '' : '<br/><a href="' + req.url + '?showAll">Show whole feed</a>'
|
||||||
|
|
||||||
getAbout(feedId, function (err, about) {
|
getAbout(feedId, function (err, about) {
|
||||||
if (err) return respond(res, 500, err.stack || err)
|
if (err) return respond(res, 500, err.stack || err)
|
||||||
|
|
||||||
pull(
|
pull(
|
||||||
sbot.createUserStream({ id: feedId, reverse: true }),
|
sbot.createUserStream({ id: feedId, reverse: true, limit: showAll ? -1 : 10 }),
|
||||||
pull.collect(function (err, logs) {
|
pull.collect(function (err, logs) {
|
||||||
if (err) return respond(res, 500, err.stack || err)
|
if (err) return respond(res, 500, err.stack || err)
|
||||||
res.writeHead(200, {
|
res.writeHead(200, {
|
||||||
@@ -109,7 +112,7 @@ exports.init = function (sbot, config) {
|
|||||||
paramap(addFollowAbout, 8),
|
paramap(addFollowAbout, 8),
|
||||||
paramap(addVoteMessage, 8),
|
paramap(addVoteMessage, 8),
|
||||||
paramap(addGitLinks, 8),
|
paramap(addGitLinks, 8),
|
||||||
pull(renderAbout(defaultOpts, about), wrapPage(about.name)),
|
pull(renderAbout(defaultOpts, about, showAllHTML), wrapPage(about.name)),
|
||||||
toPull(res, function (err) {
|
toPull(res, function (err) {
|
||||||
if (err) console.error('[viewer]', err)
|
if (err) console.error('[viewer]', err)
|
||||||
})
|
})
|
||||||
@@ -192,8 +195,11 @@ exports.init = function (sbot, config) {
|
|||||||
var channelId = url.substring(url.lastIndexOf('channel/')+8, 100)
|
var channelId = url.substring(url.lastIndexOf('channel/')+8, 100)
|
||||||
console.log("serving channel: " + channelId)
|
console.log("serving channel: " + channelId)
|
||||||
|
|
||||||
|
var showAll = req.url.endsWith("?showAll")
|
||||||
|
var showAllHTML = showAll ? '' : '<br/><a href="' + req.url + '?showAll">Show whole feed</a>'
|
||||||
|
|
||||||
pull(
|
pull(
|
||||||
sbot.query.read({ limit: 500, reverse: true, query: [{$filter: { value: { content: { channel: channelId }}}}]}),
|
sbot.query.read({ limit: showAll ? 300 : 10, reverse: true, query: [{$filter: { value: { content: { channel: channelId }}}}]}),
|
||||||
pull.collect(function (err, logs) {
|
pull.collect(function (err, logs) {
|
||||||
if (err) return respond(res, 500, err.stack || err)
|
if (err) return respond(res, 500, err.stack || err)
|
||||||
res.writeHead(200, {
|
res.writeHead(200, {
|
||||||
@@ -203,7 +209,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(defaultOpts), wrapPage('#' + channelId)),
|
pull(renderThread(defaultOpts, showAllHTML), wrapPage('#' + channelId)),
|
||||||
toPull(res, function (err) {
|
toPull(res, function (err) {
|
||||||
if (err) console.error('[viewer]', err)
|
if (err) console.error('[viewer]', err)
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -95,7 +95,7 @@ function wrap(before, after) {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
function renderAbout(opts, about) {
|
function renderAbout(opts, about, showAllHTML = "") {
|
||||||
return pull(
|
return pull(
|
||||||
pull.map(renderMsg.bind(this, opts)),
|
pull.map(renderMsg.bind(this, opts)),
|
||||||
wrap(
|
wrap(
|
||||||
@@ -111,7 +111,7 @@ function renderAbout(opts, about) {
|
|||||||
marked(about.description, opts.marked) : '') +
|
marked(about.description, opts.marked) : '') +
|
||||||
'</figcaption></figure></header></article>',
|
'</figcaption></figure></header></article>',
|
||||||
|
|
||||||
'</main>' +
|
showAllHTML + '</main>' +
|
||||||
'<a class="call-to-action" href="https://www.scuttlebutt.nz">' +
|
'<a class="call-to-action" href="https://www.scuttlebutt.nz">' +
|
||||||
'Join Scuttlebutt now' +
|
'Join Scuttlebutt now' +
|
||||||
'</a>'
|
'</a>'
|
||||||
@@ -119,7 +119,7 @@ function renderAbout(opts, about) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function renderThread(opts) {
|
function renderThread(opts, showAllHTML = "") {
|
||||||
return pull(
|
return pull(
|
||||||
pull.map(renderMsg.bind(this, opts)),
|
pull.map(renderMsg.bind(this, opts)),
|
||||||
wrap(
|
wrap(
|
||||||
@@ -128,7 +128,7 @@ function renderThread(opts) {
|
|||||||
'</span>' +
|
'</span>' +
|
||||||
'<main>',
|
'<main>',
|
||||||
|
|
||||||
'</main>' +
|
showAllHTML + '</main>' +
|
||||||
'<a class="call-to-action" href="https://www.scuttlebutt.nz">' +
|
'<a class="call-to-action" href="https://www.scuttlebutt.nz">' +
|
||||||
'Join Scuttlebutt now' +
|
'Join Scuttlebutt now' +
|
||||||
'</a>'
|
'</a>'
|
||||||
|
|||||||
Reference in New Issue
Block a user