From d7aa96addc75fae89ea33d1259f1c86cb83d5359 Mon Sep 17 00:00:00 2001 From: Ev Bogue Date: Sat, 16 Nov 2019 16:44:32 -0600 Subject: add profile photos that are cropped to 250 by 250 and saved to your log --- index.html | 1 + 1 file changed, 1 insertion(+) (limited to 'index.html') diff --git a/index.html b/index.html index a6f0fd9..a663afc 100644 --- a/index.html +++ b/index.html @@ -16,6 +16,7 @@ + -- cgit v1.2.3-70-g09d2 From 30cdde804f90ca533bc3388de46251f1400087a5 Mon Sep 17 00:00:00 2001 From: Ev Bogue Date: Sun, 24 Nov 2019 09:03:30 -0600 Subject: serve ads if client feeds are up to date --- ads.json | 15 +++++++++++++++ css/style.css | 23 ++++++++++++++++++++++- gossip.js | 4 ++++ index.html | 2 +- package.json | 2 +- render.js | 26 ++++++++++++++++++++++++++ server.js | 25 ++++++++++++++++++------- 7 files changed, 87 insertions(+), 10 deletions(-) create mode 100644 ads.json (limited to 'index.html') diff --git a/ads.json b/ads.json new file mode 100644 index 0000000..ada8e83 --- /dev/null +++ b/ads.json @@ -0,0 +1,15 @@ +[ +"Eat your veggies.", +"Drink more coffee.", +"Read my post.", +"Avoid Black Friday.", +"Your ad here.", +"Run your own pub to serve your ads.", +"Run your own pub to turn off ads.", +"Make money online.", +"Hello world.", +"Become a professional bogger.", +"Invite your friends.", +"Bogbook 2020.", +"Tip your bartender." +] diff --git a/css/style.css b/css/style.css index 4200941..2f28584 100644 --- a/css/style.css +++ b/css/style.css @@ -66,10 +66,31 @@ hr { #scroller:last-child { margin-bottom: 10em; } -.message, .message > *, .navbar, .navbar > * { +.message, .message > *, .navbar, .navbar > *, #ad, #ad > * { animation: fadein .5s; } +#ad { + background: white; + font-size: .8em; + border: 1px solid #ddd; + border-radius: 5px; + position: fixed; + padding: .3em .5em; + bottom: 5px; + left: 5px; + width: 250px; +} + +#ad button { + font-size: .8em; + margin: 0; + padding: 0; + padding-left: 5px; padding-right: 5px; + position: absolute; + bottom: 2px; right: 2px; +} + @keyframes fadein { from { opacity: 0; } to { opacity: 1; } diff --git a/gossip.js b/gossip.js index d0fc31c..09f4207 100644 --- a/gossip.js +++ b/gossip.js @@ -48,6 +48,10 @@ function sync (subs, keys) { var req = JSON.parse(message.data) unbox(req.box, req.requester, keys).then(unboxed => { var unboxedreq = JSON.parse(nacl.util.encodeUTF8(unboxed)) + if (unboxedreq.content) { + console.log(unboxedreq) + renderAd(unboxedreq) + } if (unboxedreq.seq === 0) { var stringedfeed = JSON.stringify(srclog) box(stringedfeed, serverpub, keys).then(boxed => { diff --git a/index.html b/index.html index a663afc..04d275f 100644 --- a/index.html +++ b/index.html @@ -17,8 +17,8 @@ - + diff --git a/package.json b/package.json index 658ffd8..c8799e4 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "bogbook", - "version": "1.6.0", + "version": "1.7.0", "description": "secure blockchain logging (blogging, without the l) -- bogging", "main": "server.js", "scripts": { diff --git a/render.js b/render.js index 3bd02df..ee91c24 100644 --- a/render.js +++ b/render.js @@ -1,3 +1,29 @@ +function renderAd (ad) { + var screen = document.getElementById('screen') + var adspot = document.getElementById('ad') + + if (adspot) { + adspot.parentNode.removeChild(adspot) + } + + newAd = h('div', {id: 'ad'}, [ + h('span', {classList: 'right'}, [h('pre', ['Ad'])]), + h('p', {innerHTML: marked(ad.content)}), + h('button', {classList: 'right', + onclick: function () { + adspot = document.getElementById('ad') + adspot.parentNode.removeChild(adspot) + } + }, ['Heard']), + h('span', [ + '—', + h('a', {href: ad.name}, [ad.name]) + ]) + ]) + + screen.appendChild(newAd) +} + function getHeader (post, keys, mini) { var getRaw = h('button', { onclick: function () { diff --git a/server.js b/server.js index 475551a..112f899 100644 --- a/server.js +++ b/server.js @@ -26,6 +26,8 @@ if (!fs.existsSync(bogdir)){fs.mkdirSync(bogdir)} var wserve = new WS.Server({ port: 8080 }) +var adContents = JSON.parse(fs.readFileSync(__dirname + '/ads.json')) + bog.keys().then(key => { wserve.on('connection', function (ws) { ws.on('message', function (message) { @@ -42,9 +44,23 @@ bog.keys().then(key => { var feed = JSON.parse(data) bog.open(feed[0]).then(msg => { if (unboxedreq.seq === msg.seq) { - console.log(unboxedreq.author + '\'s feed is identical, sending nothing to client') + //console.log(unboxedreq.author + '\'s feed is identical, sending nothing to client') + //commment this section out to disable ads + console.log(unboxedreq.author + '\'s feed is identical, sending an ad to ' + req.requester) + var ad = JSON.stringify({ + author: key.publicKey, + name: 'http://bogbook.com/', + content: adContents[Math.floor(Math.random() * adContents.length)], + timestamp: Date.now() + }) + bog.box(ad, req.requester, key).then(boxed => { + obj = { + requester: key.publicKey, + box: boxed + } + ws.send(JSON.stringify(obj)) + }) } - if (unboxedreq.seq > msg.seq) { // right now the client is still sending the entire log, which works just fine but isn't optimal console.log('client feed is longer, requesting diff from client') @@ -57,21 +73,18 @@ bog.keys().then(key => { ws.send(JSON.stringify(obj)) }) } - if (unboxedreq.seq < msg.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, @@ -82,7 +95,6 @@ bog.keys().then(key => { } }) } else { - // if we don't have the feed, request the feed from the client and save console.log('We don\'t have the log on the server, requesting log from ' + req.requester ) var reqwhole = JSON.stringify({author: unboxedreq.author, seq: 0}) @@ -96,7 +108,6 @@ bog.keys().then(key => { } }) } else if (Array.isArray(unboxedreq)) { - // first check to make sure that we have an entire log bog.open(unboxedreq[0]).then(msg => { if (msg.seq === unboxedreq.length) { fs.writeFile(bogdir + msg.author, JSON.stringify(unboxedreq), 'UTF-8', function (err, success) { -- cgit v1.2.3-70-g09d2 From f574b936cf06efac899f6dfea2681a3c59fd2fa6 Mon Sep 17 00:00:00 2001 From: Ev Bogue Date: Sat, 7 Dec 2019 07:27:54 -0600 Subject: break settings into own route and make it possible for guests to post advertisements --- index.html | 1 + render.js | 37 ++++++++------- server.js | 32 +++++++++++-- settings.js | 149 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ views.js | 105 +----------------------------------------- 5 files changed, 201 insertions(+), 123 deletions(-) create mode 100644 settings.js (limited to 'index.html') diff --git a/index.html b/index.html index 04d275f..0396bcc 100644 --- a/index.html +++ b/index.html @@ -16,6 +16,7 @@ + diff --git a/render.js b/render.js index d07e204..27b8fb4 100644 --- a/render.js +++ b/render.js @@ -14,22 +14,27 @@ function renderAd (ad) { adspace.appendChild(h('span', {classList: 'right'}, [h('pre', ['ad'])])) } - newAd = h('div', {id: 'ad'}, [ - adspace, - h('p', {innerHTML: marked(ad.content)}), - h('button', {classList: 'right', - onclick: function () { - adspot = document.getElementById('ad') - adspot.parentNode.removeChild(adspot) - } - }, ['Heard']), - h('span', [ - '—', - h('a', {href: ad.name}, [ad.name]) - ]) - ]) - - screen.appendChild(newAd) + open(ad).then(opened => { + quickName(ad.author).then(gotName => { + newAd = h('div', {id: 'ad'}, [ + adspace, + h('p', {innerHTML: marked(opened)}), + h('button', {classList: 'right', + onclick: function () { + adspot = document.getElementById('ad') + adspot.parentNode.removeChild(adspot) + } + }, ['Heard']), + h('span', [ + '—', + h('a', {href: '#' + ad.author}, [gotName]), + ' from ', + h('a', {href: ad.name}, [ad.name]) + ]) + ]) + screen.appendChild(newAd) + }) + }) } function getHeader (post, keys, mini) { diff --git a/server.js b/server.js index ad23040..8f7d1c3 100644 --- a/server.js +++ b/server.js @@ -108,6 +108,22 @@ bog.keys().then(key => { } else { bog.unbox(req.box, req.requester, key).then(unboxed => { var unboxedreq = JSON.parse(nacl.util.encodeUTF8(unboxed)) + if (unboxedreq.type == 'ad') { + + var hex = Buffer.from(nacl.hash(nacl.util.decodeUTF8(unboxedreq.signature))).toString('hex') + + var obj = { + hash: hex, + author: unboxedreq.author, + signature: unboxedreq.signature, + views: 0 + } + + fs.writeFile(addir + hex, JSON.stringify(obj), 'UTF-8', function () { + console.log('Saved as ' + hex) + }) + ws.close() + } if (unboxedreq.seq >= 0) { printAsk(req, unboxedreq) fs.readFile(bogdir + unboxedreq.author, 'UTF-8', function (err, data) { @@ -124,21 +140,28 @@ bog.keys().then(key => { fs.readFile(addir + adfiles[num], 'UTF-8', function (err, adFile) { var obj = JSON.parse(adFile) var ad = { - author: key.publicKey, + author: obj.author, name: fullURL, - content: obj.ad, + content: obj.signature, timestamp: Date.now(), views: obj.views } - obj.views++ - fs.writeFileSync(addir + obj.hash, JSON.stringify(obj), 'UTF-8') + if ((obj.views > 100) && (obj.author != '@Q++V5BbvWIg8B+TqtC9ZKFhetruuw+nOgxEqfjlOZI0=')) { + fs.unlinkSync(addir + obj.hash) + //console.log('REMOVING AD') + } else { + obj.views++ + fs.writeFileSync(addir + obj.hash, JSON.stringify(obj), 'UTF-8') + } printSendAd(ad, req) + //console.log('SENDING AD') bog.box(JSON.stringify(ad), req.requester, key).then(boxed => { sendobj = { requester: key.publicKey, box: boxed } ws.send(JSON.stringify(sendobj)) + ws.close() }) }) } else { @@ -177,6 +200,7 @@ bog.keys().then(key => { box: boxed } ws.send(JSON.stringify(obj)) + ws.close() }) } }) diff --git a/settings.js b/settings.js new file mode 100644 index 0000000..51dc1f2 --- /dev/null +++ b/settings.js @@ -0,0 +1,149 @@ +function settingsPage (keys) { + var welcome = h('div', {classList: 'message'}) + + welcome.appendChild(h('p', {innerHTML: marked('This is [Bogbook](http://bogbook.com), a distributed social network built using secure-gossiped blockchain logging (blogging), but we call them "bogs".\n\n You can view the code at [git.sr.ht/~ev/bogbook](https://git.sr.ht/~ev/bogbook) or clone it directly from our server:\n```\ngit clone http://git.bogbook.com/bogbook.git\n```\n Please communicate errors, bugs, and pull-requests to [@ev](http://bogbook.com/#@Q++V5BbvWIg8B+TqtC9ZKFhetruuw+nOgxEqfjlOZI0=) using Bogbook or via email: [ev@evbogue.com](mailto:ev@evbogue.com)')})) + + var keyDiv = h('div', {classList: 'message'}) + + keyDiv.appendChild(h('p', {innerHTML: marked('This is your ed25519 public/private keypair. It was generated using [TweetNaCl.js](https://tweetnacl.js.org/#/). Your public key is your identity when using Bogbook, save your key in a safe place so that you can continue to use the same identity.')})) + + keyDiv.appendChild(h('pre', {style: 'width: 80%'}, [h('code', [JSON.stringify(keys)])])) + + keyDiv.appendChild(h('button', { + onclick: function () { + localforage.removeItem('id', function () { + location.hash = '' + location.reload() + }) + } + }, ['Delete Key'])) + + var textarea = h('textarea', {placeholder: 'Import your existing ed25519 keypair'}) + keyDiv.appendChild(textarea) + keyDiv.appendChild(h('button', { + onclick: function () { + if (textarea.value) { + localforage.setItem('id', JSON.parse(textarea.value)).then(function () { location.reload() }) + } + } + }, ['Import Key'])) + + var everything = h('div', {classList: 'message'}) + + everything.appendChild(h('p', {innerHTML: marked('Sometimes you may want to delete all of your bogbook data in the browser. When you click this button, Bogbook will erase everything that you\'ve stored in the browser. NOTE: This will not delete Bogbook posts that you have already gossiped with others. WARNING: This will delete your Bogbook keypair as well as all data stored in the browser. If you want to continue to use the same key, make sure you\'ve backed up your keypair!')})) + + everything.appendChild(h('button', { + onclick: function () { + localforage.clear().then(function () {location.reload()}) + } + }, ['Delete Everything'])) + + /* we probably don't need this anymore + var regenerate = h('div', {classList: 'message'}) + + regenerate.appendChild(h('p', {innerHTML: marked('The regenerate button will create a new bogbook log in your browser from all of the feeds that you\'ve collected in your browser. While it is rare, you may use this button to troubleshoot if Bogbook is throwing strange database errors in your console.')})) + + regenerate.appendChild(h('button', { + onclick: function () { + regenerate() + } + }, ['Regenerate']))*/ + + + var pubs = h('div', {classList: 'message'}) + + pubs.appendChild(h('p', {innerHTML: marked('These are your bogbook pubs. Bogbook will gossip with these pubs to publish your messages and check for new messages from your subscriptions. You should have at least one Bogbook pub in order to gossip your messages. If you don\'t see a bogbook pub below, try clicking "Reset Pubs" or add \n```\nws://bogbook.com/~@h4e3bHDJeDWiCAkzp83HINPR4y7BLR7tI3fOVqwLQqw=\n```\n to your pubs list.')})) + + var add = h('input', {placeholder: 'Add a pub'}) + + var pubslist = h('select') + + localforage.getItem('securepubs').then(function (servers) { + + + pubs.appendChild(h('div', [ + add, + h('button', { + onclick: function () { + if (add.value) { + servers.push(add.value) + localforage.setItem('securepubs', servers).then(function () { location.reload() }) + } + } + }, ['Add a pub']) + ])) + + servers.forEach(function (pub) { + pubslist.appendChild( + h('option', {value: pub}, [pub]) + ) + pubs.appendChild(h('p', [ + pub, + h('button', { + onclick: function () { + var newServers = servers.filter(item => item !== pub) + localforage.setItem('securepubs', newServers).then(function () { location.reload() }) + } + }, ['Remove']) + ])) + }) + }) + + pubs.appendChild(h('button', { + onclick: function () { + localforage.removeItem('securepubs').then(function () { + location.hash = '' + location.reload() + }) + } + }, ['Reset pubs'])) + + var ads = h('div', {classList: 'message'}) + + + ads.appendChild(h('span', {innerHTML: marked('Submit an advertisement. Right now advertisements are free for anyone to post to this pub. Ads from guests will run for 100 views before they are deleted by the pub. \n\nSelect a pub:')})) + + ads.appendChild(pubslist) + + var adstext = h('input', {placeholder: 'Hello World!'}) + + ads.appendChild(h('span', [ + h('br'), + ' Write an ad: ', + h('br'), + adstext, + h('button', { + onclick: function () { + var split = pubslist.value.split('~') + console.log(split) + var serverurl = split[0] + var serverpub = split[1] + var ws = new WebSocket(serverurl) + + var msg = { + type: 'ad', + author: keys.publicKey + } + msg.signature = nacl.util.encodeBase64(nacl.sign(nacl.util.decodeUTF8(JSON.stringify(adstext.value)), nacl.util.decodeBase64(keys.privateKey))) + ws.onopen = function () { + box(JSON.stringify(msg), serverpub, keys).then(boxed => { + var obj = { + requester: keys.publicKey, + box: boxed + } + ws.send(JSON.stringify(obj)) + }) + } + adstext.value = '' + } + }, ['Publish']) + ])) + + scroller.appendChild(welcome) + scroller.appendChild(keyDiv) + scroller.appendChild(pubs) + scroller.appendChild(everything) + //scroller.appendChild(regenerate) + scroller.appendChild(ads) +} + diff --git a/views.js b/views.js index 99db90c..9ec0af6 100644 --- a/views.js +++ b/views.js @@ -98,7 +98,7 @@ function profilePage (src, keys) { if (src === window.location.hash.substring(1)) { addPosts(posts, keys) } - console.log("Bottom of page"); + //console.log("Bottom of page"); } } }) @@ -163,7 +163,7 @@ function publicPage (keys) { if ('' === window.location.hash.substring(1)) { addPosts(posts, keys) } - console.log("Bottom of page"); + //console.log("Bottom of page"); } } }) @@ -171,104 +171,3 @@ function publicPage (keys) { }) } -function settingsPage (keys) { - var welcome = h('div', {classList: 'message'}) - - welcome.appendChild(h('p', {innerHTML: marked('This is [Bogbook](http://bogbook.com), a distributed social network built using secure-gossiped blockchain logging (blogging), but we call them "bogs".\n\n You can view the code at [git.sr.ht/~ev/bogbook](https://git.sr.ht/~ev/bogbook) or clone it directly from our server:\n```\ngit clone http://git.bogbook.com/bogbook.git\n```\n Please communicate errors, bugs, and pull-requests to [@ev](http://bogbook.com/#@Q++V5BbvWIg8B+TqtC9ZKFhetruuw+nOgxEqfjlOZI0=) using Bogbook or via email: [ev@evbogue.com](mailto:ev@evbogue.com)')})) - - var keyDiv = h('div', {classList: 'message'}) - - keyDiv.appendChild(h('p', {innerHTML: marked('This is your ed25519 public/private keypair. It was generated using [TweetNaCl.js](https://tweetnacl.js.org/#/). Your public key is your identity when using Bogbook, save your key in a safe place so that you can continue to use the same identity.')})) - - keyDiv.appendChild(h('pre', {style: 'width: 80%'}, [h('code', [JSON.stringify(keys)])])) - - keyDiv.appendChild(h('button', { - onclick: function () { - localforage.removeItem('id', function () { - location.hash = '' - location.reload() - }) - } - }, ['Delete Key'])) - - var textarea = h('textarea', {placeholder: 'Import your existing ed25519 keypair'}) - keyDiv.appendChild(textarea) - keyDiv.appendChild(h('button', { - onclick: function () { - if (textarea.value) { - localforage.setItem('id', JSON.parse(textarea.value)).then(function () { location.reload() }) - } - } - }, ['Import Key'])) - - var everything = h('div', {classList: 'message'}) - - everything.appendChild(h('p', {innerHTML: marked('Sometimes you may want to delete all of your bogbook data in the browser. When you click this button, Bogbook will erase everything that you\'ve stored in the browser. NOTE: This will not delete Bogbook posts that you have already gossiped with others. WARNING: This will delete your Bogbook keypair as well as all data stored in the browser. If you want to continue to use the same key, make sure you\'ve backed up your keypair!')})) - - everything.appendChild(h('button', { - onclick: function () { - localforage.clear().then(function () {location.reload()}) - } - }, ['Delete Everything'])) - - /* we probably don't need this anymore - var regenerate = h('div', {classList: 'message'}) - - regenerate.appendChild(h('p', {innerHTML: marked('The regenerate button will create a new bogbook log in your browser from all of the feeds that you\'ve collected in your browser. While it is rare, you may use this button to troubleshoot if Bogbook is throwing strange database errors in your console.')})) - - regenerate.appendChild(h('button', { - onclick: function () { - regenerate() - } - }, ['Regenerate']))*/ - - - var pubs = h('div', {classList: 'message'}) - - pubs.appendChild(h('p', {innerHTML: marked('These are your bogbook pubs. Bogbook will gossip with these pubs to publish your messages and check for new messages from your subscriptions. You should have at least one Bogbook pub in order to gossip your messages. If you don\'t see a bogbook pub below, try clicking "Reset Pubs" or add \n```\nws://bogbook.com/~@h4e3bHDJeDWiCAkzp83HINPR4y7BLR7tI3fOVqwLQqw=\n```\n to your pubs list.')})) - - var add = h('input', {placeholder: 'Add a pub'}) - - localforage.getItem('securepubs').then(function (servers) { - - pubs.appendChild(h('div', [ - add, - h('button', { - onclick: function () { - if (add.value) { - servers.push(add.value) - localforage.setItem('securepubs', servers).then(function () { location.reload() }) - } - } - }, ['Add a pub']) - ])) - - servers.forEach(function (pub) { - pubs.appendChild(h('p', [ - pub, - h('button', { - onclick: function () { - var newServers = servers.filter(item => item !== pub) - localforage.setItem('securepubs', newServers).then(function () { location.reload() }) - } - }, ['Remove']) - ])) - }) - }) - - pubs.appendChild(h('button', { - onclick: function () { - localforage.removeItem('securepubs').then(function () { - location.hash = '' - location.reload() - }) - } - }, ['Reset pubs'])) - - scroller.appendChild(welcome) - scroller.appendChild(keyDiv) - scroller.appendChild(pubs) - scroller.appendChild(everything) - //scroller.appendChild(regenerate) -} - -- cgit v1.2.3-70-g09d2 From 3fe02c91174d7316ae2c66a7679ab807ca43c6c3 Mon Sep 17 00:00:00 2001 From: Ev Bogue Date: Sat, 21 Dec 2019 14:26:30 -0600 Subject: initial stab at private beacons --- app.js | 3 ++ beacons.js | 89 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ css/style.css | 4 +-- gossip.js | 3 ++ index.html | 1 + render.js | 73 +++++++++++++++++++++++++++++++++--------------- server.js | 59 +++++++++++++++++++++++++++------------ settings.js | 49 -------------------------------- 8 files changed, 190 insertions(+), 91 deletions(-) create mode 100644 beacons.js (limited to 'index.html') diff --git a/app.js b/app.js index 7fe1ae2..5dd49a5 100644 --- a/app.js +++ b/app.js @@ -10,6 +10,8 @@ function route (keys) { if (src === 'settings') { settingsPage(keys) + } else if (src === 'beacons') { + beaconsPage(keys) } else if (src[0] === '@') { profilePage(src, keys) } else if (src[0] === '?') { @@ -28,6 +30,7 @@ keys().then(key => { h('div', {classList: 'internal'}, [ h('li', [h('a', {href: '#'}, ['Home'])]), h('li', [h('a', {href: '#' + key.publicKey}, [getName(key.publicKey, keys)])]), + h('li', [h('a', {href: '#beacons'}, ['Beacons'])]), h('li', {classList: 'right'}, [h('a', {href: '#settings'}, ['Settings'])]), h('form', { classList: 'search', onsubmit: function (e) { diff --git a/beacons.js b/beacons.js new file mode 100644 index 0000000..1656879 --- /dev/null +++ b/beacons.js @@ -0,0 +1,89 @@ + +function beaconsPage (keys) { + + var pubslist = h('select') + + localforage.getItem('securepubs').then(function (servers) { + servers.forEach(function (pub) { + pubslist.appendChild( + h('option', {value: pub}, [pub]) + ) + }) + }) + + var ads = h('div', {classList: 'message'}) + + ads.appendChild(h('span', {innerHTML: marked('Sometimes when you\'re lost on the Internet you might want to send out a beacon so that people can see you. \n\n Beacons from guests will run for 100 views before they are deleted by the pub. \n\nSelect a pub:')})) + + ads.appendChild(pubslist) + + var recp = h('input', {placeholder: 'Ex: @Q++V5BbvWIg8B+TqtC9ZKFhetruuw+nOgxEqfjlOZI0='}) + + var adstext = h('textarea', {placeholder: 'Hello World!'}) + + ads.appendChild(h('span', [ + h('br'), + h('p', [" Send a beacon (leave the 'To:' field blank for a public beacon): "]), + h('p', ['To: ', + recp + ]), + adstext, + h('br'), + h('button', { + onclick: function () { + var split = pubslist.value.split('~') + console.log(split) + var serverurl = split[0] + var serverpub = split[1] + var ws = new WebSocket(serverurl) + + if ((recp.value) && (adstext.value)) { + var tobox = { + author: keys.publicKey, + timestamp: Date.now(), + content: adstext.value + } + box(JSON.stringify(tobox), recp.value, keys).then(boxedmsg => { + var msg = { + type: 'beacon', + author: keys.publicKey, + box: boxedmsg + } + ws.onopen = function () { + box(JSON.stringify(msg), serverpub, keys).then(boxed => { + var obj = { + requester: keys.publicKey, + box: boxed + } + ws.send(JSON.stringify(obj)) + }) + adstext.value = '' + recp.value = '' + } + }) + } + + if ((!recp.value) && (adstext.value)) { + var msg = { + type: 'beacon', + author: keys.publicKey + } + msg.signature = nacl.util.encodeBase64(nacl.sign(nacl.util.decodeUTF8(JSON.stringify(adstext.value)), nacl.util.decodeBase64(keys.privateKey))) + ws.onopen = function () { + box(JSON.stringify(msg), serverpub, keys).then(boxed => { + var obj = { + requester: keys.publicKey, + box: boxed + } + ws.send(JSON.stringify(obj)) + }) + adstext.value = '' + } + } + } + }, ['Publish']) + ])) + + scroller.appendChild(ads) +} + diff --git a/css/style.css b/css/style.css index 2a7745b..1eef78f 100644 --- a/css/style.css +++ b/css/style.css @@ -70,7 +70,7 @@ hr { animation: fadein .5s; } -#ad { +#ad, #pm { background: white; font-size: .8em; border: 1px solid #ddd; @@ -82,7 +82,7 @@ hr { width: 250px; } -#ad button { +#ad button, #pm button { font-size: .8em; margin: 0; padding: 0; diff --git a/gossip.js b/gossip.js index d0b91f1..3f88b54 100644 --- a/gossip.js +++ b/gossip.js @@ -53,6 +53,9 @@ function sync (subs, keys) { unboxedreq.signature = unboxedreq.content renderAd(unboxedreq) } + if (unboxedreq.box) { + renderAd(unboxedreq, keys) + } if (unboxedreq.seq === 0) { var stringedfeed = JSON.stringify(srclog) box(stringedfeed, serverpub, keys).then(boxed => { diff --git a/index.html b/index.html index 0396bcc..5d18890 100644 --- a/index.html +++ b/index.html @@ -17,6 +17,7 @@ + diff --git a/render.js b/render.js index d85d04b..02e4b88 100644 --- a/render.js +++ b/render.js @@ -1,4 +1,6 @@ -function renderAd (ad) { +function renderAd (ad, keys) { + console.log(ad) + var screen = document.getElementById('screen') var adspot = document.getElementById('ad') @@ -11,30 +13,57 @@ function renderAd (ad) { if (ad.views) { adspace.appendChild(h('span', {classList: 'right'}, [h('pre', [ad.views + ' views'])])) } else { - adspace.appendChild(h('span', {classList: 'right'}, [h('pre', ['ad'])])) + adspace.appendChild(h('span', {classList: 'right'}, [h('pre', ['beacon'])])) } - open(ad).then(opened => { - quickName(ad.author).then(gotName => { - newAd = h('div', {id: 'ad'}, [ - adspace, - h('p', {innerHTML: marked(opened)}), - h('button', {classList: 'right', - onclick: function () { - adspot = document.getElementById('ad') - adspot.parentNode.removeChild(adspot) - } - }, ['Heard']), - h('span', [ - '—', - h('a', {href: '#' + ad.author}, [gotName]), - ' from ', - h('a', {href: ad.name}, [ad.name]) + if (ad.box) { + unbox(ad.box, ad.author, keys).then(unboxed => { + var msg = JSON.parse(nacl.util.encodeUTF8(unboxed)) + quickName(ad.author).then(gotName => { + beacon = h('div', {id: 'pm'}, [ + h('span', {classList: 'right'}, [h('pre', [human(new Date(msg.timestamp))])]), + h('p', {innerHTML: marked(msg.content)}), + h('button', {classList: 'right', + onclick: function () { + pmspot = document.getElementById('pm') + pmspot.parentNode.removeChild(pmspot) + } + }, ['Heard']), + h('span', [ + '—', + h('a', {href: '#' + ad.author}, [gotName]), + ' from ', + h('a', {href: ad.name}, [ad.name]) + ]) ]) - ]) - screen.appendChild(newAd) - }) - }) + screen.append(beacon) + }) + }) + } + + if (ad.signature) { + open(ad).then(opened => { + quickName(ad.author).then(gotName => { + newAd = h('div', {id: 'ad'}, [ + adspace, + h('p', {innerHTML: marked(opened)}), + h('button', {classList: 'right', + onclick: function () { + adspot = document.getElementById('ad') + adspot.parentNode.removeChild(adspot) + } + }, ['Heard']), + h('span', [ + '—', + h('a', {href: '#' + ad.author}, [gotName]), + ' from ', + h('a', {href: ad.name}, [ad.name]) + ]) + ]) + screen.appendChild(newAd) + }) + }) + } } function getHeader (post, keys, mini) { diff --git a/server.js b/server.js index d324f43..5ad7064 100644 --- a/server.js +++ b/server.js @@ -119,15 +119,27 @@ bog.keys().then(key => { } else { bog.unbox(req.box, req.requester, key).then(unboxed => { var unboxedreq = JSON.parse(nacl.util.encodeUTF8(unboxed)) - if (unboxedreq.type == 'ad') { - - var hex = Buffer.from(nacl.hash(nacl.util.decodeUTF8(unboxedreq.signature))).toString('hex') - - var obj = { - hash: hex, - author: unboxedreq.author, - signature: unboxedreq.signature, - views: 0 + //console.log(unboxedreq) + if (unboxedreq.type == 'beacon') { + if (unboxedreq.box) { + var hex = Buffer.from(nacl.hash(nacl.util.decodeUTF8(unboxedreq.box))).toString('hex') + + var obj = { + hash: hex, + author: unboxedreq.author, + box: unboxedreq.box, + views: 0 + } + } + + if (unboxedreq.signature) { + var hex = Buffer.from(nacl.hash(nacl.util.decodeUTF8(unboxedreq.signature))).toString('hex') + var obj = { + hash: hex, + author: unboxedreq.author, + signature: unboxedreq.signature, + views: 0 + } } fs.writeFile(addir + hex, JSON.stringify(obj), 'UTF-8', function () { @@ -150,13 +162,25 @@ bog.keys().then(key => { var num = Math.floor(Math.random() * (adfiles.length)) fs.readFile(addir + adfiles[num], 'UTF-8', function (err, adFile) { var obj = JSON.parse(adFile) - var ad = { - author: obj.author, - name: config.fullurl, - content: obj.signature, - timestamp: Date.now(), - views: obj.views + + if (obj.signature) { + var ad = { + author: obj.author, + name: config.fullurl, + content: obj.signature, + views: obj.views + } } + + if (obj.box) { + var ad = { + author: obj.author, + name: config.fullurl, + box: obj.box, + views: obj.views + } + } + if ((obj.views > 100) && (obj.author != config.author)) { fs.unlinkSync(addir + obj.hash) //console.log('REMOVING AD') @@ -165,6 +189,7 @@ bog.keys().then(key => { fs.writeFileSync(addir + obj.hash, JSON.stringify(obj), 'UTF-8') } printSendAd(ad, req) + console.log(ad) //console.log('SENDING AD') bog.box(JSON.stringify(ad), req.requester, key).then(boxed => { sendobj = { @@ -175,9 +200,7 @@ bog.keys().then(key => { ws.close() }) }) - } else { - ads.make('Hello World.') - } + } }) } } diff --git a/settings.js b/settings.js index 51dc1f2..c88ea07 100644 --- a/settings.js +++ b/settings.js @@ -56,11 +56,7 @@ function settingsPage (keys) { var add = h('input', {placeholder: 'Add a pub'}) - var pubslist = h('select') - localforage.getItem('securepubs').then(function (servers) { - - pubs.appendChild(h('div', [ add, h('button', { @@ -74,9 +70,6 @@ function settingsPage (keys) { ])) servers.forEach(function (pub) { - pubslist.appendChild( - h('option', {value: pub}, [pub]) - ) pubs.appendChild(h('p', [ pub, h('button', { @@ -98,52 +91,10 @@ function settingsPage (keys) { } }, ['Reset pubs'])) - var ads = h('div', {classList: 'message'}) - - - ads.appendChild(h('span', {innerHTML: marked('Submit an advertisement. Right now advertisements are free for anyone to post to this pub. Ads from guests will run for 100 views before they are deleted by the pub. \n\nSelect a pub:')})) - - ads.appendChild(pubslist) - - var adstext = h('input', {placeholder: 'Hello World!'}) - - ads.appendChild(h('span', [ - h('br'), - ' Write an ad: ', - h('br'), - adstext, - h('button', { - onclick: function () { - var split = pubslist.value.split('~') - console.log(split) - var serverurl = split[0] - var serverpub = split[1] - var ws = new WebSocket(serverurl) - - var msg = { - type: 'ad', - author: keys.publicKey - } - msg.signature = nacl.util.encodeBase64(nacl.sign(nacl.util.decodeUTF8(JSON.stringify(adstext.value)), nacl.util.decodeBase64(keys.privateKey))) - ws.onopen = function () { - box(JSON.stringify(msg), serverpub, keys).then(boxed => { - var obj = { - requester: keys.publicKey, - box: boxed - } - ws.send(JSON.stringify(obj)) - }) - } - adstext.value = '' - } - }, ['Publish']) - ])) - scroller.appendChild(welcome) scroller.appendChild(keyDiv) scroller.appendChild(pubs) scroller.appendChild(everything) //scroller.appendChild(regenerate) - scroller.appendChild(ads) } -- cgit v1.2.3-70-g09d2 From 508e4c53a93cfa443dd590dd52f8fc22471d9e7c Mon Sep 17 00:00:00 2001 From: Ev Bogue Date: Fri, 3 Jan 2020 15:57:10 -0600 Subject: rip out beacons --- app.js | 3 -- beacons.js | 112 --------------------------------------- gossip.js | 10 +--- index.html | 1 - package-lock.json | 2 +- package.json | 2 +- render.js | 153 ------------------------------------------------------ server.js | 80 ---------------------------- 8 files changed, 4 insertions(+), 359 deletions(-) delete mode 100644 beacons.js (limited to 'index.html') diff --git a/app.js b/app.js index 5dd49a5..7fe1ae2 100644 --- a/app.js +++ b/app.js @@ -10,8 +10,6 @@ function route (keys) { if (src === 'settings') { settingsPage(keys) - } else if (src === 'beacons') { - beaconsPage(keys) } else if (src[0] === '@') { profilePage(src, keys) } else if (src[0] === '?') { @@ -30,7 +28,6 @@ keys().then(key => { h('div', {classList: 'internal'}, [ h('li', [h('a', {href: '#'}, ['Home'])]), h('li', [h('a', {href: '#' + key.publicKey}, [getName(key.publicKey, keys)])]), - h('li', [h('a', {href: '#beacons'}, ['Beacons'])]), h('li', {classList: 'right'}, [h('a', {href: '#settings'}, ['Settings'])]), h('form', { classList: 'search', onsubmit: function (e) { diff --git a/beacons.js b/beacons.js deleted file mode 100644 index 3c65f3e..0000000 --- a/beacons.js +++ /dev/null @@ -1,112 +0,0 @@ -function beaconsPage (keys) { - - var pubslist = h('select') - - localforage.getItem('securepubs').then(function (servers) { - servers.forEach(function (pub) { - pubslist.appendChild( - h('option', {value: pub}, [pub]) - ) - }) - }) - - var ads = h('div', {classList: 'message'}) - - ads.appendChild(h('span', {innerHTML: marked('Sometimes when you\'re lost on the Internet you might want to send out a beacon so that people can see you. \n\n Beacons from guests will run for 100 views before they are deleted by the pub. \n\nSelect a pub:')})) - - ads.appendChild(pubslist) - - var recp = h('input', {placeholder: 'Ex: @Q++V5BbvWIg8B+TqtC9ZKFhetruuw+nOgxEqfjlOZI0='}) - - var adstext = h('textarea', {placeholder: 'Hello World!'}) - - ads.appendChild(h('span', [ - h('br'), - h('p', [" Send a beacon (leave the 'To:' field blank for a public beacon): "]), - h('p', ['To: ', - recp - ]), - adstext, - h('br'), - h('button', { - onclick: function () { - var split = pubslist.value.split('~') - console.log(split) - var serverurl = split[0] - var serverpub = split[1] - var ws = new WebSocket(serverurl) - - if ((recp.value) && (adstext.value)) { - var tobox = { - author: keys.publicKey, - timestamp: Date.now(), - content: adstext.value - } - box(JSON.stringify(tobox), recp.value, keys).then(boxedmsg => { - var msg = { - type: 'beacon', - author: keys.publicKey, - box: boxedmsg - } - ws.onopen = function () { - box(JSON.stringify(msg), serverpub, keys).then(boxed => { - var obj = { - requester: keys.publicKey, - box: boxed - } - ws.send(JSON.stringify(obj)) - }) - adstext.value = '' - recp.value = '' - } - }) - } - - if ((!recp.value) && (adstext.value)) { - var msg = { - type: 'beacon', - author: keys.publicKey - } - msg.signature = nacl.util.encodeBase64(nacl.sign(nacl.util.decodeUTF8(JSON.stringify(adstext.value)), nacl.util.decodeBase64(keys.privateKey))) - ws.onopen = function () { - box(JSON.stringify(msg), serverpub, keys).then(boxed => { - var obj = { - requester: keys.publicKey, - box: boxed - } - ws.send(JSON.stringify(obj)) - }) - adstext.value = '' - } - } - } - }, ['Publish']) - ])) - - scroller.appendChild(ads) - - localforage.getItem('beacons').then(beacons => { - beacons.forEach(beacon => { - var message = h('div', {classList: 'message'}) - - if (beacon.signature) { - open(beacon).then(opened => { - quickName(beacon.author).then(gotName => { - message.appendChild(h('p', {innerHTML: marked(opened)})) - message.appendChild(h('span', [ - '—', - h('a', {href: '#' + beacon.author}, [gotName]), - ' from ', - h('a', {href: beacon.name}, [beacon.name]) - ]) - ) - }) - }) - } - - scroller.appendChild(message) - console.log(beacon) - }) - }) -} - diff --git a/gossip.js b/gossip.js index 47d40c1..809266e 100644 --- a/gossip.js +++ b/gossip.js @@ -1,11 +1,5 @@ function processreq (req, pubkey, connection, keys) { - console.log(req) - if (req.box || req.signature) { - renderAd(req, keys) - } - if (req.seq === 0 || req.seq) { - console.log('feed sync') bog(req.author).then(feed => { if (feed) { open(feed[0]).then(msg => { @@ -38,7 +32,7 @@ function processreq (req, pubkey, connection, keys) { }) } }) - } else { console.log('we dont have it')} + } }) } @@ -157,7 +151,7 @@ function sync (feeds, keys) { var pubs localforage.getItem('pubs').then(pubs => { if (!pubs) { - pubs = ['ws://' + location.hostname + ':8080'] + pubs = ['ws://' + location.hostname + ':8080', 'ws://bogbook.com'] localforage.setItem('pubs', pubs) } pubs.forEach(function (pub, index) { diff --git a/index.html b/index.html index 5d18890..0396bcc 100644 --- a/index.html +++ b/index.html @@ -17,7 +17,6 @@ - diff --git a/package-lock.json b/package-lock.json index ad97945..e17dee8 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "bogbook", - "version": "1.8.0", + "version": "1.8.1", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index a174152..437d4c7 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "bogbook", - "version": "1.8.0", + "version": "1.8.1", "description": "secure blockchain logging (blogging, without the l) -- bogging", "main": "server.js", "scripts": { diff --git a/render.js b/render.js index f1e5511..e807c1e 100644 --- a/render.js +++ b/render.js @@ -1,156 +1,3 @@ -function renderAd (ad, keys) { - localforage.getItem(ad.hash).then(heard => { - if (!heard) { - var screen = document.getElementById('screen') - var adspot = document.getElementById('ad') - var pmspot = document.getElementById('pm') - - if (adspot) { - adspot.parentNode.removeChild(adspot) - } - - - var adspace = h('span') - - if (ad.views) { - adspace.appendChild(h('span', {classList: 'right'}, [h('pre', [ad.views + ' views'])])) - } else { - adspace.appendChild(h('span', {classList: 'right'}, [h('pre', ['beacon'])])) - } - - if (ad.box) { - unbox(ad.box, ad.author, keys).then(unboxed => { - if (unboxed) { - var msg = JSON.parse(unboxed) - if (pmspot) { - pmspot.parentNode.removeChild(pmspot) - } - quickName(ad.author).then(gotName => { - beacon = h('div', {id: 'pm'}, [ - h('span', {classList: 'right'}, [h('pre', [human(new Date(msg.timestamp))])]), - h('p', {innerHTML: marked(msg.content)}), - h('button', {classList: 'right', - onclick: function () { - pmspot = document.getElementById('pm') - pmspot.parentNode.removeChild(pmspot) - if (msg.content.substring((msg.content.length - 6), msg.content.length) === 'Heard.') { - localforage.setItem(ad.hash, true).then(success => { - //console.log('heard: ' + ad.hash) - }) - - } else { - var split = ad.pub.split('~') - var serverurl = split[0] - var serverpub = split[1] - var ws = new WebSocket(serverurl) - - var tobox = { - author: keys.publicKey, - timestamp: Date.now(), - content: '>' + msg.content + '\n\nHeard.' - } - - box(JSON.stringify(tobox), ad.author, keys).then(boxedmsg => { - var msg = { - type: 'beacon', - author: keys.publicKey, - box: boxedmsg - } - ws.onopen = function () { - box(JSON.stringify(msg), serverpub, keys).then(boxed => { - var obj = { - requester: keys.publicKey, - box: boxed - } - ws.send(JSON.stringify(obj)) - localforage.setItem(ad.hash, true).then(success => { - //console.log('heard: ' + ad.hash) - localforage.getItem('beacons').then(beacons => { - if (!beacons) { beacons = [] } - beacons.unshift(ad) - localforage.setItem('beacons', beacons) - }) - - }) - }) - } - }) - } - } - }, ['Heard']), - h('span', [ - '—', - h('a', {href: '#' + ad.author}, [gotName]), - ' from ', - h('a', {href: ad.name}, [ad.name]) - ]) - ]) - screen.append(beacon) - }) - } - }) - } - - if (ad.signature) { - open(ad).then(opened => { - quickName(ad.author).then(gotName => { - newAd = h('div', {id: 'ad'}, [ - adspace, - h('p', {innerHTML: marked(opened)}), - h('button', {classList: 'right', - onclick: function () { - adspot = document.getElementById('ad') - adspot.parentNode.removeChild(adspot) - var split = ad.pub.split('~') - var serverurl = split[0] - var serverpub = split[1] - var ws = new WebSocket(serverurl) - - var tobox = { - author: keys.publicKey, - timestamp: Date.now(), - content: '>' + opened + '\n\nHeard.' - } - - box(JSON.stringify(tobox), ad.author, keys).then(boxedmsg => { - var msg = { - type: 'beacon', - author: keys.publicKey, - box: boxedmsg - } - ws.onopen = function () { - box(JSON.stringify(msg), serverpub, keys).then(boxed => { - var obj = { - requester: keys.publicKey, - box: boxed - } - ws.send(JSON.stringify(obj)) - localforage.setItem(ad.hash, true).then(success => {console.log('heard: ' + ad.hash)}) - localforage.getItem('beacons').then(beacons => { - if (!beacons) { beacons = [] } - beacons.unshift(ad) - localforage.setItem('beacons', beacons) - }) - }) - } - }) - } - }, ['Heard']), - h('span', [ - '—', - h('a', {href: '#' + ad.author}, [gotName]), - ' from ', - h('a', {href: ad.name}, [ad.name]) - ]) - ]) - screen.appendChild(newAd) - }) - }) - } - } - }) -} - function getHeader (post, keys, mini) { var getRaw = h('button', { onclick: function () { diff --git a/server.js b/server.js index ad802d1..fbe92e0 100644 --- a/server.js +++ b/server.js @@ -3,7 +3,6 @@ var homedir = require('os').homedir() var path = homedir + '/.bogbook/' var bogdir = path + 'bogs/' -var addir = path + 'ads/' var confpath = path + 'config.json' if (!fs.existsSync(homedir + '/.bogbook/')) {fs.mkdirSync(homedir + '/.bogbook/')} @@ -120,33 +119,6 @@ bog.keys().then(key => { bog.unbox(req.box, req.requester, key).then(unboxed => { var unboxedreq = JSON.parse(unboxed) //console.log(unboxedreq) - if (unboxedreq.type == 'beacon') { - if (unboxedreq.box) { - var hex = Buffer.from(nacl.hash(nacl.util.decodeUTF8(unboxedreq.box))).toString('hex') - - var obj = { - hash: hex, - author: unboxedreq.author, - box: unboxedreq.box, - views: 0 - } - } - - if (unboxedreq.signature) { - var hex = Buffer.from(nacl.hash(nacl.util.decodeUTF8(unboxedreq.signature))).toString('hex') - var obj = { - hash: hex, - author: unboxedreq.author, - signature: unboxedreq.signature, - views: 0 - } - } - - fs.writeFile(addir + hex, JSON.stringify(obj), 'UTF-8', function () { - console.log('Saved as ' + hex) - }) - ws.close() - } if (unboxedreq.seq >= 0) { printAsk(req, unboxedreq) fs.readFile(bogdir + unboxedreq.author, 'UTF-8', function (err, data) { @@ -155,58 +127,6 @@ bog.keys().then(key => { bog.open(feed[0]).then(msg => { if (unboxedreq.seq === msg.seq) { printFeedIdentical(msg, req) - if (config.ads) { - if (Math.floor(Math.random() * 6) == 2) { - fs.readdir(addir, function (err, adfiles) { - if (adfiles) { - var num = Math.floor(Math.random() * (adfiles.length)) - fs.readFile(addir + adfiles[num], 'UTF-8', function (err, adFile) { - var obj = JSON.parse(adFile) - - if (obj.signature) { - var ad = { - author: obj.author, - hash: obj.hash, - name: config.fullurl, - pub: 'ws://' + config.url + ':' + config.wsport + '/~' + key.publicKey, - signature: obj.signature, - views: obj.views - } - } - - if (obj.box) { - var ad = { - author: obj.author, - hash: obj.hash, - name: config.fullurl, - pub: 'ws://' + config.url + ':' + config.wsport + '/~' + key.publicKey, - box: obj.box, - views: obj.views - } - } - - if ((obj.views > 100) && (obj.author != config.author)) { - fs.unlinkSync(addir + obj.hash) - //console.log('REMOVING AD') - } else { - obj.views++ - fs.writeFileSync(addir + obj.hash, JSON.stringify(obj), 'UTF-8') - } - printSendAd(ad, req) - //console.log('SENDING AD') - bog.box(JSON.stringify(ad), req.requester, key).then(boxed => { - sendobj = { - requester: key.publicKey, - box: boxed - } - ws.send(JSON.stringify(sendobj)) - ws.close() - }) - }) - } - }) - } - } } if (unboxedreq.seq > msg.seq) { printClientLonger(msg, req) -- cgit v1.2.3-70-g09d2