aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcel <cel@f/6sQ6d2CMxRUhLpspgGIulDxDCwYD7DzFzPNr7u5AU=.ed25519>2017-04-20 17:54:19 -0700
committercel <cel@f/6sQ6d2CMxRUhLpspgGIulDxDCwYD7DzFzPNr7u5AU=.ed25519>2017-04-20 20:01:43 -0700
commit5fafec89b671c52ef3bd59ccbef317c9bb4ccaea (patch)
treeb195493fd46f10cf64c6b360c682a6eb88e5c4a7
parent75fa67ce9869076f2d1994902b2a6a2c14807856 (diff)
downloadpatchfoo-5fafec89b671c52ef3bd59ccbef317c9bb4ccaea.tar.gz
patchfoo-5fafec89b671c52ef3bd59ccbef317c9bb4ccaea.zip
Set timestamp cookie for /new on "catchup"
-rw-r--r--lib/serve.js20
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')
))
)