Browse Source

bogbook @ 1.6.0 -- real-time bogbook and only send 25 posts at a time

master
Ev Bogue 3 years ago
parent
commit
2a8e4ab57a
  1. 26
      package-lock.json
  2. 2
      package.json
  3. 21
      server.js
  4. 33
      views.js

26
package-lock.json generated

@ -1,13 +1,13 @@
{
"name": "bogbook",
"version": "1.5.0",
"version": "1.6.0",
"lockfileVersion": 1,
"requires": true,
"dependencies": {
"async-limiter": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/async-limiter/-/async-limiter-1.0.0.tgz",
"integrity": "sha512-jp/uFnooOiO+L211eZOoSyzpOITMXx1rBITauYykG3BRYPu8h0UcxsPNB04RR5vo4Tyz3+ay17tR6JVf9qzYWg=="
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/async-limiter/-/async-limiter-1.0.1.tgz",
"integrity": "sha512-csOlWGAcRFJaI6m+F2WKdnMKr4HhdhFVBk0H/QbJFMCr+uO2kwohwXQPxw/9OCxp05r5ghVBFSyioixx3gfkNQ=="
},
"charset": {
"version": "1.0.1",
@ -58,9 +58,9 @@
"integrity": "sha1-HxbkqiKwTRM2tmGIpmrzxgDDpm0="
},
"mime": {
"version": "2.4.3",
"resolved": "https://registry.npmjs.org/mime/-/mime-2.4.3.tgz",
"integrity": "sha512-QgrPRJfE+riq5TPZMcHZOtm8c6K/yYrMbKIoRfapfiGLxS8OTeIfRhUGW5LU7MlRa52KOAGCfUNruqLrIBvWZw=="
"version": "2.4.4",
"resolved": "https://registry.npmjs.org/mime/-/mime-2.4.4.tgz",
"integrity": "sha512-LRxmNwziLPT828z+4YkNzloCFC2YM4wrB99k+AV5ZbEyfGNWfG8SO1FUXLmLDBSo89NrJZ4DIWeLjy1CHGhMGA=="
},
"minimist": {
"version": "1.2.0",
@ -76,9 +76,9 @@
}
},
"open": {
"version": "6.2.0",
"resolved": "https://registry.npmjs.org/open/-/open-6.2.0.tgz",
"integrity": "sha512-Vxf6HJkwrqmvh9UAID3MnMYXntbTxKLOSfOnO7LJdzPf3NE3KQYFNV0/Lcz2VAndbRFil58XVCyh8tiX11fiYw==",
"version": "6.4.0",
"resolved": "https://registry.npmjs.org/open/-/open-6.4.0.tgz",
"integrity": "sha512-IFenVPgF70fSm1keSd2iDBIDIBZkroLeuffXq+wKTzTJlBpesFWojV9lb8mzOfaAzM1sr7HQHuO0vtV0zYekGg==",
"requires": {
"is-wsl": "^1.1.0"
}
@ -110,9 +110,9 @@
"integrity": "sha1-RXbBzuXi1j0gf+5S8boCgZSAvHU="
},
"url-join": {
"version": "4.0.0",
"resolved": "https://registry.npmjs.org/url-join/-/url-join-4.0.0.tgz",
"integrity": "sha1-TTNA6AfTdzvamZH4MFrNzCpmXSo="
"version": "4.0.1",
"resolved": "https://registry.npmjs.org/url-join/-/url-join-4.0.1.tgz",
"integrity": "sha512-jk1+QP6ZJqyOiuEI9AEWQfju/nB2Pw466kbA0LEZljHwKeMgd9WrAEgEGxjPDD2+TNbbb37rTyhEfrCXfuKXnA=="
},
"utf8-byte-length": {
"version": "1.0.4",

2
package.json

@ -1,6 +1,6 @@
{
"name": "bogbook",
"version": "1.5.0",
"version": "1.6.0",
"description": "secure blockchain logging (blogging, without the l) -- bogging",
"main": "server.js",
"scripts": {

21
server.js

@ -39,12 +39,10 @@ bog.keys().then(key => {
} else {
bog.unbox(req.box, req.requester, key).then(unboxed => {
var unboxedreq = JSON.parse(nacl.util.encodeUTF8(unboxed))
if (unboxedreq.seq) {
if (unboxedreq.seq >= 0) {
console.log(req.requester + ' asked for feed ' + unboxedreq.author + ' after sequence ' + unboxedreq.seq)
// check to see if we have the feed on disk
fs.readFile(bogdir + unboxedreq.author, 'UTF-8', function (err, data) {
if (data) {
// TODO open the latest message, and check the sequence number
var feed = JSON.parse(data)
bog.open(feed[0]).then(msg => {
if (unboxedreq.seq === msg.seq) {
@ -63,10 +61,21 @@ bog.keys().then(key => {
ws.send(JSON.stringify(obj))
})
}
if (unboxedreq.seq < msg.seq) {
console.log('client feed is shorter, sending diff to client')
var diff = JSON.stringify(feed.slice(0, msg.seq - unboxedreq.seq))
var endrange = feed.length - unboxedreq.seq - 25
if (endrange < 0) {
endrange = feed.length - unboxedreq.seq - 1
}
var baserange = feed.length - unboxedreq.seq
console.log('client feed is shorter, sending from ' + baserange + ' to ' + endrange + ' to client')
var diff = JSON.stringify(
feed.slice(
endrange,
baserange)
)
//var diff = JSON.stringify(feed.slice(0, msg.seq - unboxedreq.seq))
bog.box(diff, req.requester, key).then(boxed => {
var obj = {
requester: key.publicKey,

33
views.js

@ -12,11 +12,20 @@ function profilePage (src, keys) {
var profile = h('div', {classList: 'profile'})
scroller.appendChild(profile)
scroller.appendChild(h('div'))
var subs = [src]
sync(subs, keys)
var interval = 1000
timer = function() {
if (src === window.location.hash.substring(1)) {
if (interval < 10000) { interval = interval + 200 }
sync(subs, keys)
setTimeout(timer, interval)
}
}
timer()
profile.appendChild(h('a', {href: '#' + src}, [
getImage(src, keys, 'profileAvatar'),
@ -100,11 +109,27 @@ function publicPage (keys) {
localforage.getItem('subscriptions').then(function (subs) {
if (subs) {
sync(subs, keys)
var interval = 1000
timer = function() {
if ('' === window.location.hash.substring(1)) {
if (interval < 10000) { interval = interval + 1000 }
sync(subs, keys)
setTimeout(timer, interval)
}
}
timer()
} else {
var subs = [keys.publicKey]
localforage.setItem('subscriptions', subs)
sync(subs, keys)
var interval = 1000
timer = function() {
if ('' === window.location.hash.substring(1)) {
if (interval < 10000) { interval = interval + 1000 }
sync(subs, keys)
setTimeout(timer, interval)
}
}
timer()
}
})

Loading…
Cancel
Save