Browse Source

clean up and move all config and keys to a settings page

master
Ev Bogue 3 years ago
parent
commit
cdcbf89b31
  1. 10
      app.js
  2. 7
      css/style.css
  3. 4
      gossip.js
  4. 21
      package-lock.json
  5. 1
      package.json
  6. 8
      server.js
  7. 76
      views.js

10
app.js

@ -8,10 +8,8 @@ function route (keys) {
var screen = document.getElementById('screen')
screen.appendChild(scroller)
if (src === 'key') {
keyPage(keys)
} else if (src === 'pubs') {
pubs()
if (src === 'settings') {
settingsPage(keys)
} else if (src[0] === '@') {
profilePage(src, keys)
} else if (src[0] === '?') {
@ -30,9 +28,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: '#key'}, ['Key'])]),
h('li', [h('a', {href: '#pubs'}, ['Pubs'])]),
h('li', {classList: 'right'}, [h('a', {href: 'http://git.sr.ht/~ev/bogbook'}, ['Git'])]),
h('li', {classList: 'right'}, [h('a', {href: '#settings'}, ['Settings'])]),
h('form', { classList: 'search',
onsubmit: function (e) {
window.location.hash = '?' + search.value

7
css/style.css

@ -61,6 +61,8 @@ hr {
border-radius: 5px;
}
#scroller:last-child { margin-bottom: 10em; }
.message, .message > *, .navbar, .navbar > * {
animation: fadein .5s;
}
@ -167,17 +169,18 @@ textarea {
}
form.search, input.search {
width: 100px;
width: 175px;
float: right;
margin: 0;
padding: 0;
padding-left: .1em;
color: #f5f5f5;
background: #444;
border-radius: 3px;
}
form.search {
margin-top: .3em;
margin-top: .20em;
}
.navbar li.right {

4
gossip.js

@ -102,7 +102,7 @@ function sync (subs, keys) {
open(unboxedreq[i]).then(opened => {
log.unshift(opened)
var scroller = document.getElementById('scroller')
scroller.insertBefore(render(opened, keys), scroller.childNodes[2])
scroller.insertBefore(render(opened, keys), scroller.childNodes[1])
if (unboxedreq.length + lastmsg.seq === opened.seq) {
log.sort((a, b) => a.timestamp - b.timestamp)
var reversed = log.reverse()
@ -155,7 +155,7 @@ function sync (subs, keys) {
open(unboxedreq[i]).then(opened => {
log.unshift(opened)
var scroller = document.getElementById('scroller')
scroller.insertBefore(render(opened, keys), scroller.childNodes[2])
scroller.insertBefore(render(opened, keys), scroller.childNodes[1])
if (opened.seq === unboxedreq.length) {
log.sort((a, b) => a.timestamp - b.timestamp)
var reversed = log.reverse()

21
package-lock.json generated

@ -83,22 +83,6 @@
"is-wsl": "^1.1.0"
}
},
"sanitize-filename": {
"version": "1.6.3",
"resolved": "https://registry.npmjs.org/sanitize-filename/-/sanitize-filename-1.6.3.tgz",
"integrity": "sha512-y/52Mcy7aw3gRm7IrcGDFx/bCk4AhRh2eI9luHOQM86nZsqwiRkkq2GekHXBBD+SmPidc8i2PqtYZl+pWJ8Oeg==",
"requires": {
"truncate-utf8-bytes": "^1.0.0"
}
},
"truncate-utf8-bytes": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/truncate-utf8-bytes/-/truncate-utf8-bytes-1.0.2.tgz",
"integrity": "sha1-QFkjkJWS1W94pYGENLC3hInKXys=",
"requires": {
"utf8-byte-length": "^1.0.1"
}
},
"tweetnacl": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/tweetnacl/-/tweetnacl-1.0.1.tgz",
@ -114,11 +98,6 @@
"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",
"resolved": "https://registry.npmjs.org/utf8-byte-length/-/utf8-byte-length-1.0.4.tgz",
"integrity": "sha1-9F8VDExm7uloGGUFq5P8u4rWv2E="
},
"ws": {
"version": "6.2.1",
"resolved": "https://registry.npmjs.org/ws/-/ws-6.2.1.tgz",

1
package.json

@ -13,7 +13,6 @@
"ecstatic": "^4.1.2",
"ed2curve": "^0.2.1",
"open": "^6.2.0",
"sanitize-filename": "^1.6.3",
"tweetnacl": "^1.0.1",
"tweetnacl-util": "^0.15.0",
"ws": "^6.2.1"

8
server.js

@ -1,5 +1,6 @@
// static server (8089)
var fs = require('fs')
var http = require('http')
var serve = require('ecstatic')
var open = require('open')
@ -14,19 +15,14 @@ open('http://localhost:8089')
var bog = require('./bog')
var WS = require('ws')
var fs = require('fs')
var nacl = require('tweetnacl')
nacl.util = require('tweetnacl-util')
var homedir = require('os').homedir()
var sanitize = require('sanitize-filename')
var homedir = require('os').homedir()
var bogdir = homedir + '/.bogbook/bogs/'
var blobdir = homedir + '/.bogbook/blobs/'
if (!fs.existsSync(homedir + '/.bogbook/')) {fs.mkdirSync(homedir + '/.bogbook/')}
if (!fs.existsSync(bogdir)){fs.mkdirSync(bogdir)}
if (!fs.existsSync(blobdir)){fs.mkdirSync(blobdir)}
var wserve = new WS.Server({ port: 8080 })

76
views.js

@ -11,7 +11,7 @@ function profilePage (src, keys) {
var profile = h('div', {classList: 'profile'})
scroller.appendChild(profile)
scroller.appendChild(h('div'))
//scroller.appendChild(h('div'))
var subs = [src]
@ -144,22 +144,6 @@ function publicPage (keys) {
}
})
var div = h('div')
div.appendChild(h('button', {
onclick: function () {
localforage.clear().then(function () {location.reload()})
}
}, ['Delete Everything']))
div.appendChild(h('button', {
onclick: function () {
regenerate()
}
}, ['Regenerate']))
scroller.appendChild(div)
scroller.appendChild(composer(keys))
async function addPosts (posts, keys) {
@ -189,14 +173,18 @@ function publicPage (keys) {
})
}
function keyPage (keys) {
var message = h('div', {classList: 'message'})
function settingsPage (keys) {
var welcome = h('div', {classList: 'message'})
message.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](http://bogbook.com/), save your key in a safe place so that you can continue to use the same identity.')}))
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)')}))
message.appendChild(h('pre', {style: 'width: 80%'}, [h('code', [JSON.stringify(keys)])]))
var keyDiv = h('div', {classList: 'message'})
message.appendChild(h('button', {
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 = ''
@ -206,8 +194,8 @@ function keyPage (keys) {
}, ['Delete Key']))
var textarea = h('textarea', {placeholder: 'Import your existing ed25519 keypair'})
message.appendChild(textarea)
message.appendChild(h('button', {
keyDiv.appendChild(textarea)
keyDiv.appendChild(h('button', {
onclick: function () {
if (textarea.value) {
localforage.setItem('id', JSON.parse(textarea.value)).then(function () { location.reload() })
@ -215,19 +203,37 @@ function keyPage (keys) {
}
}, ['Import Key']))
scroller.appendChild(message)
}
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']))*/
function pubs () {
var message = h('div', {classList: 'message'})
var pubs = h('div', {classList: 'message'})
message.appendChild(h('p', {innerHTML: marked('These are the Bogbook pubs that your browser will connect to as it looks for new messages from your subscriptions, when you post new bog posts, and when you click on feeds.\n\nAdd or remove these pubs to control where your Bogbook gossips. Localhost is a default, but will only work if you install Bogbook on your local computer by [cloning down the repo](https://git.sr.ht/~ev/bogbook).')}))
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) {
message.appendChild(h('div', [
pubs.appendChild(h('div', [
add,
h('button', {
onclick: function () {
@ -240,7 +246,7 @@ function pubs () {
]))
servers.forEach(function (pub) {
message.appendChild(h('p', [
pubs.appendChild(h('p', [
pub,
h('button', {
onclick: function () {
@ -252,7 +258,7 @@ function pubs () {
})
})
message.appendChild(h('button', {
pubs.appendChild(h('button', {
onclick: function () {
localforage.removeItem('securepubs').then(function () {
location.hash = ''
@ -261,6 +267,10 @@ function pubs () {
}
}, ['Reset pubs']))
scroller.appendChild(message)
scroller.appendChild(welcome)
scroller.appendChild(keyDiv)
scroller.appendChild(pubs)
scroller.appendChild(everything)
//scroller.appendChild(regenerate)
}

Loading…
Cancel
Save