Indention fix
This commit is contained in:
@@ -11,15 +11,15 @@ var memo = require('asyncmemo')
|
|||||||
var lru = require('lrucache')
|
var lru = require('lrucache')
|
||||||
var serveEmoji = require('emoji-server')()
|
var serveEmoji = require('emoji-server')()
|
||||||
var {
|
var {
|
||||||
MdRenderer,
|
MdRenderer,
|
||||||
renderEmoji,
|
renderEmoji,
|
||||||
formatMsgs,
|
formatMsgs,
|
||||||
wrapPage,
|
wrapPage,
|
||||||
renderThread,
|
renderThread,
|
||||||
renderAbout,
|
renderAbout,
|
||||||
renderShowAll,
|
renderShowAll,
|
||||||
renderRssItem,
|
renderRssItem,
|
||||||
wrapRss,
|
wrapRss,
|
||||||
} = require('./render');
|
} = require('./render');
|
||||||
|
|
||||||
var appHash = hash([fs.readFileSync(__filename)])
|
var appHash = hash([fs.readFileSync(__filename)])
|
||||||
@@ -52,16 +52,16 @@ exports.init = function (sbot, config) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
defaultOpts.marked = {
|
defaultOpts.marked = {
|
||||||
gfm: true,
|
gfm: true,
|
||||||
mentions: true,
|
mentions: true,
|
||||||
tables: true,
|
tables: true,
|
||||||
breaks: true,
|
breaks: true,
|
||||||
pedantic: false,
|
pedantic: false,
|
||||||
sanitize: true,
|
sanitize: true,
|
||||||
smartLists: true,
|
smartLists: true,
|
||||||
smartypants: false,
|
smartypants: false,
|
||||||
emoji: renderEmoji,
|
emoji: renderEmoji,
|
||||||
renderer: new MdRenderer(defaultOpts)
|
renderer: new MdRenderer(defaultOpts)
|
||||||
}
|
}
|
||||||
|
|
||||||
var getMsg = memo({cache: lru(100)}, getMsgWithValue, sbot)
|
var getMsg = memo({cache: lru(100)}, getMsgWithValue, sbot)
|
||||||
@@ -96,146 +96,146 @@ exports.init = function (sbot, config) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function serveFeed(req, res, feedId, ext) {
|
function serveFeed(req, res, feedId, ext) {
|
||||||
console.log("serving feed: " + feedId)
|
console.log("serving feed: " + feedId)
|
||||||
|
|
||||||
var showAll = req.url.endsWith("?showAll");
|
var showAll = req.url.endsWith("?showAll");
|
||||||
|
|
||||||
getAbout(feedId, function (err, about) {
|
getAbout(feedId, function (err, about) {
|
||||||
|
if (err) return respond(res, 500, err.stack || err)
|
||||||
|
|
||||||
|
function render() {
|
||||||
|
switch (ext) {
|
||||||
|
case 'rss':
|
||||||
|
return pull(
|
||||||
|
// formatMsgs(feedId, ext, defaultOpts)
|
||||||
|
renderRssItem(defaultOpts), wrapRss(about.name, defaultOpts)
|
||||||
|
);
|
||||||
|
default:
|
||||||
|
return pull(
|
||||||
|
renderAbout(defaultOpts, about,
|
||||||
|
renderShowAll(showAll, req.url)), wrapPage(about.name)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pull(
|
||||||
|
sbot.createUserStream({ id: feedId, reverse: true, limit: showAll ? -1 : (ext == 'rss' ? 25 : 10) }),
|
||||||
|
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, {
|
||||||
function render() {
|
'Content-Type': ctype(ext)
|
||||||
switch (ext) {
|
})
|
||||||
case 'rss':
|
|
||||||
return pull(
|
|
||||||
// formatMsgs(feedId, ext, defaultOpts)
|
|
||||||
renderRssItem(defaultOpts), wrapRss(about.name, defaultOpts)
|
|
||||||
);
|
|
||||||
default:
|
|
||||||
return pull(
|
|
||||||
renderAbout(defaultOpts, about,
|
|
||||||
renderShowAll(showAll, req.url)), wrapPage(about.name)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pull(
|
pull(
|
||||||
sbot.createUserStream({ id: feedId, reverse: true, limit: showAll ? -1 : (ext == 'rss' ? 25 :10) }),
|
pull.values(logs),
|
||||||
pull.collect(function (err, logs) {
|
paramap(addAuthorAbout, 8),
|
||||||
if (err) return respond(res, 500, err.stack || err)
|
paramap(addFollowAbout, 8),
|
||||||
res.writeHead(200, {
|
paramap(addVoteMessage, 8),
|
||||||
'Content-Type': ctype(ext)
|
paramap(addGitLinks, 8),
|
||||||
})
|
render(),
|
||||||
pull(
|
toPull(res, function (err) {
|
||||||
pull.values(logs),
|
if (err) console.error('[viewer]', err)
|
||||||
paramap(addAuthorAbout, 8),
|
})
|
||||||
paramap(addFollowAbout, 8),
|
|
||||||
paramap(addVoteMessage, 8),
|
|
||||||
paramap(addGitLinks, 8),
|
|
||||||
render(),
|
|
||||||
toPull(res, function (err) {
|
|
||||||
if (err) console.error('[viewer]', err)
|
|
||||||
})
|
|
||||||
)
|
|
||||||
})
|
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
function serveUserFeed(req, res, url) {
|
function serveUserFeed(req, res, url) {
|
||||||
var feedId = url.substring(url.lastIndexOf('user-feed/')+10, 100)
|
var feedId = url.substring(url.lastIndexOf('user-feed/')+10, 100)
|
||||||
console.log("serving user feed: " + feedId)
|
console.log("serving user feed: " + feedId)
|
||||||
|
|
||||||
var following = []
|
var following = []
|
||||||
var channelSubscriptions = []
|
var channelSubscriptions = []
|
||||||
|
|
||||||
getAbout(feedId, function (err, about) {
|
getAbout(feedId, function (err, about) {
|
||||||
pull(
|
pull(
|
||||||
sbot.createUserStream({ id: feedId }),
|
sbot.createUserStream({ id: feedId }),
|
||||||
pull.filter((msg) => {
|
pull.filter((msg) => {
|
||||||
return !msg.value ||
|
return !msg.value ||
|
||||||
msg.value.content.type == 'contact' ||
|
msg.value.content.type == 'contact' ||
|
||||||
(msg.value.content.type == 'channel' &&
|
(msg.value.content.type == 'channel' &&
|
||||||
typeof msg.value.content.subscribed != 'undefined')
|
typeof msg.value.content.subscribed != 'undefined')
|
||||||
}),
|
}),
|
||||||
pull.collect(function (err, msgs) {
|
pull.collect(function (err, msgs) {
|
||||||
msgs.forEach((msg) => {
|
msgs.forEach((msg) => {
|
||||||
if (msg.value.content.type == 'contact')
|
if (msg.value.content.type == 'contact')
|
||||||
{
|
{
|
||||||
if (msg.value.content.following)
|
if (msg.value.content.following)
|
||||||
following[msg.value.content.contact] = 1
|
following[msg.value.content.contact] = 1
|
||||||
else
|
else
|
||||||
delete following[msg.value.content.contact]
|
delete following[msg.value.content.contact]
|
||||||
}
|
}
|
||||||
else // channel subscription
|
else // channel subscription
|
||||||
{
|
{
|
||||||
if (msg.value.content.subscribed)
|
if (msg.value.content.subscribed)
|
||||||
channelSubscriptions[msg.value.content.channel] = 1
|
channelSubscriptions[msg.value.content.channel] = 1
|
||||||
else
|
else
|
||||||
delete channelSubscriptions[msg.value.content.channel]
|
delete channelSubscriptions[msg.value.content.channel]
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
serveFeeds(req, res, following, channelSubscriptions, feedId, 'user feed ' + (about ? about.name : ""))
|
serveFeeds(req, res, following, channelSubscriptions, feedId, 'user feed ' + (about ? about.name : ""))
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
function serveFeeds(req, res, following, channelSubscriptions, feedId, name) {
|
function serveFeeds(req, res, following, channelSubscriptions, feedId, name) {
|
||||||
pull(
|
pull(
|
||||||
sbot.createLogStream({ reverse: true, limit: 5000 }),
|
sbot.createLogStream({ reverse: true, limit: 5000 }),
|
||||||
pull.filter((msg) => {
|
pull.filter((msg) => {
|
||||||
return !msg.value ||
|
return !msg.value ||
|
||||||
(msg.value.author in following ||
|
(msg.value.author in following ||
|
||||||
msg.value.content.channel in channelSubscriptions)
|
msg.value.content.channel in channelSubscriptions)
|
||||||
}),
|
}),
|
||||||
pull.take(150),
|
pull.take(150),
|
||||||
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, {
|
||||||
'Content-Type': ctype("html")
|
'Content-Type': ctype("html")
|
||||||
})
|
})
|
||||||
pull(
|
pull(
|
||||||
pull.values(logs),
|
pull.values(logs),
|
||||||
paramap(addAuthorAbout, 8),
|
paramap(addAuthorAbout, 8),
|
||||||
paramap(addFollowAbout, 8),
|
paramap(addFollowAbout, 8),
|
||||||
paramap(addVoteMessage, 8),
|
paramap(addVoteMessage, 8),
|
||||||
paramap(addGitLinks, 8),
|
paramap(addGitLinks, 8),
|
||||||
pull(renderThread(defaultOpts), wrapPage(name)),
|
pull(renderThread(defaultOpts), wrapPage(name)),
|
||||||
toPull(res, function (err) {
|
toPull(res, function (err) {
|
||||||
if (err) console.error('[viewer]', err)
|
if (err) console.error('[viewer]', err)
|
||||||
})
|
|
||||||
)
|
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
|
})
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
function serveChannel(req, res, url) {
|
function serveChannel(req, res, url) {
|
||||||
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 showAll = req.url.endsWith("?showAll")
|
||||||
|
|
||||||
pull(
|
pull(
|
||||||
sbot.query.read({ limit: showAll ? 300 : 10, 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, {
|
||||||
'Content-Type': ctype("html")
|
'Content-Type': ctype("html")
|
||||||
})
|
})
|
||||||
pull(
|
pull(
|
||||||
pull.values(logs),
|
pull.values(logs),
|
||||||
paramap(addAuthorAbout, 8),
|
paramap(addAuthorAbout, 8),
|
||||||
paramap(addVoteMessage, 8),
|
paramap(addVoteMessage, 8),
|
||||||
pull(renderThread(defaultOpts, '',
|
pull(renderThread(defaultOpts, '',
|
||||||
renderShowAll(showAll, req.url)),
|
renderShowAll(showAll, req.url)),
|
||||||
wrapPage('#' + channelId)),
|
wrapPage('#' + channelId)),
|
||||||
toPull(res, function (err) {
|
toPull(res, function (err) {
|
||||||
if (err) console.error('[viewer]', err)
|
if (err) console.error('[viewer]', err)
|
||||||
})
|
|
||||||
)
|
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
|
})
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
function serveId(req, res, id, ext, query) {
|
function serveId(req, res, id, ext, query) {
|
||||||
@@ -297,25 +297,25 @@ exports.init = function (sbot, config) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function addFollowAbout(msg, cb) {
|
function addFollowAbout(msg, cb) {
|
||||||
if (msg.value.content.contact)
|
if (msg.value.content.contact)
|
||||||
getAbout(msg.value.content.contact, function (err, about) {
|
getAbout(msg.value.content.contact, function (err, about) {
|
||||||
if (err) return cb(err)
|
if (err) return cb(err)
|
||||||
msg.value.content.contactAbout = about
|
msg.value.content.contactAbout = about
|
||||||
cb(null, msg)
|
cb(null, msg)
|
||||||
})
|
})
|
||||||
else
|
else
|
||||||
cb(null, msg)
|
cb(null, msg)
|
||||||
}
|
}
|
||||||
|
|
||||||
function addVoteMessage(msg, cb) {
|
function addVoteMessage(msg, cb) {
|
||||||
if (msg.value.content.type == 'vote' && msg.value.content.vote.link[0] == '%')
|
if (msg.value.content.type == 'vote' && msg.value.content.vote.link[0] == '%')
|
||||||
getMsg(msg.value.content.vote.link, function (err, linkedMsg) {
|
getMsg(msg.value.content.vote.link, function (err, linkedMsg) {
|
||||||
if (linkedMsg)
|
if (linkedMsg)
|
||||||
msg.value.content.vote.linkedText = linkedMsg.value.content.text
|
msg.value.content.vote.linkedText = linkedMsg.value.content.text
|
||||||
cb(null, msg)
|
cb(null, msg)
|
||||||
})
|
})
|
||||||
else
|
else
|
||||||
cb(null, msg)
|
cb(null, msg)
|
||||||
}
|
}
|
||||||
|
|
||||||
function addAuthorAbout(msg, cb) {
|
function addAuthorAbout(msg, cb) {
|
||||||
@@ -327,20 +327,20 @@ exports.init = function (sbot, config) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function addGitLinks(msg, cb) {
|
function addGitLinks(msg, cb) {
|
||||||
if (msg.value.content.type == 'git-update')
|
if (msg.value.content.type == 'git-update')
|
||||||
getMsg(msg.value.content.repo, function (err, gitRepo) {
|
getMsg(msg.value.content.repo, function (err, gitRepo) {
|
||||||
if (gitRepo)
|
if (gitRepo)
|
||||||
msg.value.content.repoName = gitRepo.value.content.name
|
msg.value.content.repoName = gitRepo.value.content.name
|
||||||
cb(null, msg)
|
cb(null, msg)
|
||||||
})
|
})
|
||||||
else if (msg.value.content.type == 'issue')
|
else if (msg.value.content.type == 'issue')
|
||||||
getMsg(msg.value.content.project, function (err, gitRepo) {
|
getMsg(msg.value.content.project, function (err, gitRepo) {
|
||||||
if (gitRepo)
|
if (gitRepo)
|
||||||
msg.value.content.repoName = gitRepo.value.content.name
|
msg.value.content.repoName = gitRepo.value.content.name
|
||||||
cb(null, msg)
|
cb(null, msg)
|
||||||
})
|
})
|
||||||
else
|
else
|
||||||
cb(null, msg)
|
cb(null, msg)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -515,8 +515,8 @@ function renderDefault(c) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function renderShowAll(showAll, url) {
|
function renderShowAll(showAll, url) {
|
||||||
if (showAll)
|
if (showAll)
|
||||||
return '';
|
return '';
|
||||||
else
|
else
|
||||||
return '<br>' + h('a', { href : url + '?showAll' }, 'Show whole feed').outerHTML;
|
return '<br>' + h('a', { href : url + '?showAll' }, 'Show whole feed').outerHTML;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user