diff options
Diffstat (limited to 'lib/serve.js')
-rw-r--r-- | lib/serve.js | 20 |
1 files changed, 16 insertions, 4 deletions
diff --git a/lib/serve.js b/lib/serve.js index ce37490..d63be2f 100644 --- a/lib/serve.js +++ b/lib/serve.js @@ -276,13 +276,24 @@ Serve.prototype.public = function (ext) { ) } +Serve.prototype.setCookie = function (key, value, options) { + var header = key + '=' + value + if (options) for (var k in options) { + header += '; ' + k + '=' + options[k] + } + this.res.setHeader('Set-Cookie', header) +} + Serve.prototype.new = function (ext) { var self = this var q = self.query + var latest = (/latest=([^;]*)/.exec(self.req.headers.cookie) || [])[1] var opts = { - gt: Number(q.gt) || Date.now(), + gt: Number(q.gt) || Number(latest) || Date.now(), } + if (q.catchup) self.setCookie('latest', opts.gt, {'Max-Age': 86400000}) + var read = self.app.createLogStream(opts) self.req.on('closed', function () { console.error('closing') @@ -305,7 +316,7 @@ Serve.prototype.new = function (ext) { pull.values(msgs), self.renderThread(opts, null, q), self.wrapNew({ - gt: isFinite(maxTS) ? maxTS : opts.gt + gt: isFinite(maxTS) ? maxTS : Date.now() }), self.wrapMessages(), self.wrapPage('new'), @@ -865,7 +876,7 @@ Serve.prototype.wrapPage = function (title, searchQ) { ), h('body', h('nav.nav-bar', h('form', {action: render.toUrl('/search'), method: 'get'}, - h('a', {href: render.toUrl('/new?gt=' + Date.now())}, 'new') , ' ', + h('a', {href: render.toUrl('/new')}, 'new') , ' ', h('a', {href: render.toUrl('/public')}, 'public'), ' ', h('a', {href: render.toUrl('/private')}, 'private') , ' ', h('a', {href: render.toUrl('/peers')}, 'peers') , ' ', @@ -1066,7 +1077,8 @@ Serve.prototype.wrapNew = function (opts) { thread, h('tr', h('td.paginate', {colspan: 3}, h('a', {href: '?' + qs.stringify({ - gt: opts.gt + gt: opts.gt, + catchup: 1, })}, '↓ catchup') )) ) |