Commit 7d90df9233302f8d58d6de7e2eacdc38036e8e63
Merge master version of serveId
Anders Rune Jensen committed on 4/23/2018, 7:02:38 PMParent: 83d27c4e28bf98bc44819ecae2d8f2016e0d636a
Files changed
index.js | changed |
index.js | ||
---|---|---|
@@ -273,9 +273,8 @@ | ||
273 | 273 … | } |
274 | 274 … | |
275 | 275 … | exports.serveId = function(req, res, id, ext, query) { |
276 | 276 … | ensureFreshAboutCache(() => { |
277 | - | |
278 | 277 … | var q = query ? qs.parse(query) : {} |
279 | 278 … | var includeRoot = !('noroot' in q) |
280 | 279 … | var base = q.base || conf.base |
281 | 280 … | var baseToken |
@@ -307,31 +306,42 @@ | ||
307 | 306 … | |
308 | 307 … | var format = formatMsgs(id, ext, opts) |
309 | 308 … | if (format === null) return respond(res, 415, 'Invalid format') |
310 | 309 … | |
311 | - pull( | |
312 | - sbot.links({dest: id, values: true }), | |
313 | - includeRoot && prepend(getMsg, id), | |
314 | - pull.unique('key'), | |
315 | - pull.collect(function (err, links) { | |
316 | - if (err) return respond(res, 500, err.stack || err) | |
317 | - var etag = hash(sort.heads(links).concat(appHash, ext, qs)) | |
318 | - if (req.headers['if-none-match'] === etag) return respond(res, 304) | |
319 | - res.writeHead(200, { | |
320 | - 'Content-Type': ctype(ext), | |
321 | - 'etag': etag | |
310 … | + function render (links) { | |
311 … | + var etag = hash(sort.heads(links).concat(appHash, ext, qs)) | |
312 … | + if (req.headers['if-none-match'] === etag) return respond(res, 304) | |
313 … | + res.writeHead(200, { | |
314 … | + 'Content-Type': ctype(ext), | |
315 … | + 'etag': etag | |
316 … | + }) | |
317 … | + pull( | |
318 … | + pull.values(sort(links)), | |
319 … | + paramap(addAuthorAbout, 8), | |
320 … | + paramap(addBlog, 8), | |
321 … | + format, | |
322 … | + toPull(res, function (err) { | |
323 … | + if (err) console.error('[viewer]', err) | |
322 | 324 … | }) |
323 | - pull( | |
324 | - pull.values(sort(links)), | |
325 | - paramap(addAuthorAbout, 8), | |
326 | - paramap(addBlog, 8), | |
327 | - format, | |
328 | - toPull(res, function (err) { | |
329 | - if (err) console.error('[viewer]', err) | |
330 | - }) | |
331 | - ) | |
332 | - }) | |
333 | - ) | |
325 … | + ) | |
326 … | + } | |
327 … | + | |
328 … | + getMsgWithValue(sbot, id, function (err, root) { | |
329 … | + if (err) return respond(res, 500, err.stack || err) | |
330 … | + if('string' === typeof root.value.content) | |
331 … | + return render([root]) | |
332 … | + | |
333 … | + pull( | |
334 … | + sbot.links({dest: id, values: true, rel: 'root' }), | |
335 … | + pull.unique('key'), | |
336 … | + pull.collect(function (err, links) { | |
337 … | + if (err) return respond(res, 500, err.stack || err) | |
338 … | + if(includeRoot) | |
339 … | + links.unshift(root) | |
340 … | + render(links) | |
341 … | + }) | |
342 … | + ) | |
343 … | + }) | |
334 | 344 … | }) |
335 | 345 … | } |
336 | 346 … | |
337 | 347 … | function addFollowAbout(msg, cb) { |
Built with git-ssb-web