anproto personal data server
2
fork

Configure Feed

Select the types of activity you want to include in your feed.

local bogbot works now

+78 -27
+5 -10
bogbot.js
··· 58 58 } 59 59 60 60 bogbot.open = async (msg) => { 61 - console.log(msg) 62 61 const pubkey = msg.substring(0, 44) 63 62 const sig = msg.substring(44) 64 63 ··· 82 81 } 83 82 84 83 bogbot.compose = async (content) => { 85 - const name = localStorage.getItem('name') ? 'name: ' + localStorage.getItem('name') : '' 86 - const image = localStorage.getItem('image') ? 'image:' + localStorage.getItem('image') : '' 84 + const name = localStorage.getItem('name') ? 'name: ' + localStorage.getItem('name') + '\n' : '' 85 + const image = localStorage.getItem('image') ? 'image: ' + localStorage.getItem('image') + '\n' : '' 87 86 // previous should be a bogbot.query in case multiple devices are in use but we need to get the log going again first 88 - const previous = localStorage.getItem('previous') ? 'previous:' + localStorage.getItem('previous') : '' 87 + const previous = localStorage.getItem('previous') ? 'previous: ' + localStorage.getItem('previous') + '\n' : '' 89 88 90 89 const yaml = `--- 91 - ${name} 92 - ${image} 93 - ${previous} 94 - --- 95 - ${content} 96 - ` 90 + ${name}${image}${previous}--- 91 + ${content}` 97 92 const signed = await bogbot.sign(yaml) 98 93 return signed 99 94 }
+1 -10
composer.js
··· 16 16 b.onclick = async () => { 17 17 const published = await bogbot.compose(ta.value) 18 18 ta.value = '' 19 - const rendered = await render(published) 20 19 const scroller = document.getElementById('scroller') 21 - scroller.insertBefore(rendered, scroller.firstChild) 22 - //const el = document.createElement('div') 23 - //const obj = {} 24 - //obj.protocolHash = published 25 - //obj.sig = await bogbot.find(published) 26 - //obj.opened = await bogbot.open(obj.sig) 27 - //obj.content = await bogbot.find(obj.opened.substring(13)) 28 - //el.textContent = JSON.stringify(obj) 29 - //document.body.appendChild(el) 20 + await render.hash(published, scroller) 30 21 } 31 22 32 23 div.appendChild(b)
+1 -2
example.js
··· 14 14 const log = await bogbot.getLog() 15 15 16 16 log.forEach(async (hash) => { 17 - const rendered = await render(hash) 18 - scroller.insertBefore(rendered, scroller.firstChild) 17 + await render.hash(hash, scroller) 19 18 })
+2 -1
index.html
··· 1 1 <style> 2 - input, textarea { width: 100%; } 2 + body { font-family: sans-serif;} 3 + input, textarea { width: 100%; font-family: sans-serif;} 3 4 </style> 4 5 <script type='module' src='example.js'></script> 5 6
+64 -4
render.js
··· 1 - export const render = async (hash) => { 2 - const div = document.createElement('div') 1 + import { bogbot } from './bogbot.js' 2 + import { h } from './lib/h.js' 3 + import { human } from './lib/human.js' 4 + import { vb } from './lib/vb.js' 5 + import { decode } from './lib/base64.js' 6 + 7 + export const render = {} 8 + 9 + render.blob = async (blob) => { 10 + const hash = await bogbot.hash(blob) 3 11 4 - div.textContent = hash 12 + const div = await document.getElementById(hash) 5 13 6 - return div 14 + try { 15 + const opened = await bogbot.open(blob) 16 + const ts = h('span', [await human(new Date(parseInt(opened.substring(0, 13))))]) 17 + setInterval(async () => { 18 + ts.textContent = await human(new Date(parseInt(opened.substring(0, 13)))) 19 + }, 1000) 20 + if (div) { 21 + const img = vb(decode(blob.substring(0, 44))) 22 + img.id = 'image' 23 + img.style = 'width: 30px; height: 30px; float: left; margin-right: 5px; object-fit: cover;' 24 + div.appendChild(img) 25 + div.appendChild(h('a', {href: '#' + blob.substring(0, 44), id: 'name'}, [blob.substring(0, 10)])) 26 + div.appendChild(h('a', {href: '#' + hash, style: 'float: right;'}, [ts])) 27 + div.appendChild(h('div', {id: opened.substring(13)})) 28 + const content = await bogbot.find(opened.substring(13)) 29 + if (content) { 30 + await render.blob(content) 31 + } 32 + } else { 33 + console.log('Div is not in view') 34 + } 35 + } catch (err) { 36 + console.log('Not a valid protocol message') 37 + const yaml = await bogbot.yaml(blob) 38 + if (div) { 39 + div.textContent = yaml.body 40 + div.parentNode.childNodes.forEach(async (node) => { 41 + if (yaml.name && node.id === 'name') { 42 + node.textContent = yaml.name 43 + } 44 + if (yaml.image && node.id === 'image') { 45 + const image = await bogbot.find(yaml.image) 46 + node.src = image 47 + } 48 + }) 49 + } 50 + console.log(yaml) 51 + } 52 + } 53 + 54 + render.hash = async (hash, scroller) => { 55 + const div = h('div', {id: hash}) 56 + 57 + scroller.insertBefore(div, scroller.firstChild) 58 + 59 + const sig = await bogbot.find(hash) 60 + 61 + if (sig) { 62 + await render.blob(sig) 63 + } else { 64 + await gossip(hash) 65 + } 66 + 7 67 }
+5
serve.js
··· 1 + import { serveDir } from 'https://deno.land/std/http/file_server.ts' 2 + 3 + Deno.serve((r) => { 4 + return serveDir(r, {quiet: 'True'}) 5 + })