diff --git a/README.md b/README.md index 12745944..7a9d10e8 100644 --- a/README.md +++ b/README.md @@ -55,7 +55,7 @@ standard. ## Running By default, running the built `out/debug/tildefriends` executable will start a -web server at . `tildefriends -h` lists further +web server at . `tildefriends -h` lists further options. The first user to create an account and log in will be granted administrative diff --git a/apps/ssb.json b/apps/ssb.json index 15464f38..ec6045b4 100644 --- a/apps/ssb.json +++ b/apps/ssb.json @@ -1,5 +1,5 @@ { "type": "tildefriends-app", "emoji": "🦀", - "previous": "&lGTfidaEuVfuFbpQD9WGizMpC6OwYr1AqM+AH0yaVsc=.sha256" + "previous": "&ErfmEIt3WboZp6PR3cC/i7XU/ZTI/2X5I9XvUN0GGMU=.sha256" } diff --git a/apps/ssb/tf-message.js b/apps/ssb/tf-message.js index 057b6c8a..fa653086 100644 --- a/apps/ssb/tf-message.js +++ b/apps/ssb/tf-message.js @@ -377,9 +377,7 @@ class TfMessageElement extends LitElement { render_menu() { let content = this.get_content(); - let formats = [ - ['message', 'Message'], - ]; + let formats = [['message', 'Message']]; if (content?.type == 'post' || content?.type == 'blog') { formats.push(['md', 'Markdown']); } @@ -390,12 +388,33 @@ class TfMessageElement extends LitElement { return html`
-
- ${this.message?.id} - - ${formats.map(([format, name]) => (html` - - `))} +
+ ${this.message?.id} + + ${formats.map( + ([format, name]) => html` + + ` + )}
`; @@ -412,11 +431,10 @@ class TfMessageElement extends LitElement { - ${is_encrypted} - ${this.render_menu()} - + ${is_encrypted} ${this.render_menu()} +
+ ${new Date(this.message.timestamp).toLocaleString()} +
`; } diff --git a/apps/ssb/tf-tab-news-feed.js b/apps/ssb/tf-tab-news-feed.js index 5471593f..81834bbc 100644 --- a/apps/ssb/tf-tab-news-feed.js +++ b/apps/ssb/tf-tab-news-feed.js @@ -189,7 +189,7 @@ class TfTabNewsFeedElement extends LitElement { UNION SELECT refs_in.message AS ref FROM messages_refs refs_in JOIN news ON refs_in.ref = news.id `, - [JSON.stringify(result.map(x => x.id))] + [JSON.stringify(result.map((x) => x.id))] ); let t2 = new Date(); let related_messages = await tfrpc.rpc.query( @@ -199,7 +199,8 @@ class TfTabNewsFeedElement extends LitElement { JOIN json_each(?2) refs ON messages.id = refs.value JOIN json_each(?1) AS following ON messages.author = following.value `, - [JSON.stringify(this.following), JSON.stringify(refs.map(x => x.ref))]); + [JSON.stringify(this.following), JSON.stringify(refs.map((x) => x.ref))] + ); result = [].concat(result, related_messages); let t3 = new Date(); console.log( diff --git a/apps/web/app.js b/apps/web/app.js index 31f5e0c9..d2afa6ac 100644 --- a/apps/web/app.js +++ b/apps/web/app.js @@ -2,7 +2,7 @@ let g_hash; async function query(sql, params) { let results = []; - await ssb.sqlAsync(sql, params, function(row) { + await ssb.sqlAsync(sql, params, function (row) { results.push(row); }); return results; @@ -35,7 +35,10 @@ async function resolve(id) { } async function get_names(identities) { - return Object.fromEntries((await query(` + return Object.fromEntries( + ( + await query( + ` SELECT author, name FROM ( SELECT messages.author, @@ -47,23 +50,35 @@ async function get_names(identities) { json_extract(messages.content, '$.type') = 'about' AND content ->> 'about' = messages.author AND name IS NOT NULL) WHERE author_rank = 1 - `, [JSON.stringify(identities)])).map(x => [x.author, x.name])); + `, + [JSON.stringify(identities)] + ) + ).map((x) => [x.author, x.name]) + ); } async function render(hash) { g_hash = hash; if (!hash) { - let sites = (await query(` + let sites = await query( + ` SELECT site.author, site.id FROM messages site WHERE site.content ->> 'type' = 'web-init' - `, [])); - let names = await get_names(sites.map(x => x.author)); + `, + [] + ); + let names = await get_names(sites.map((x) => x.author)); if (hash === g_hash) { - await app.setDocument(``); + await app.setDocument( + `` + ); } } else { - let site_id = hash.charAt(0) == '#' ? decodeURIComponent(hash.substring(1)) : decodeURIComponent(hash); + let site_id = + hash.charAt(0) == '#' + ? decodeURIComponent(hash.substring(1)) + : decodeURIComponent(hash); await app.setDocument(` @@ -82,4 +97,4 @@ async function main() { render(null); } -main(); \ No newline at end of file +main(); diff --git a/apps/web/handler.js b/apps/web/handler.js index ab1d92ca..c21f6037 100644 --- a/apps/web/handler.js +++ b/apps/web/handler.js @@ -1,6 +1,6 @@ async function query(sql, params) { let results = []; - await ssb.sqlAsync(sql, params, function(row) { + await ssb.sqlAsync(sql, params, function (row) { results.push(row); }); return results; @@ -19,17 +19,22 @@ function guess_content_type(name) { } async function main() { - let path = request.path.replaceAll(/(%[0-9a-fA-F]{2})/g, x => String.fromCharCode(parseInt(x.substring(1), 16))); + let path = request.path.replaceAll(/(%[0-9a-fA-F]{2})/g, (x) => + String.fromCharCode(parseInt(x.substring(1), 16)) + ); let match = path.match(/^(%.{44}\.sha256)(?:\/)?(.*)$/); let content_type = guess_content_type(request.path); - let root = await query(` + let root = await query( + ` SELECT root.content ->> 'root' AS root FROM messages site JOIN messages root ON site.id = ? AND root.author = site.author AND root.content ->> 'site' = site.id ORDER BY root.sequence DESC LIMIT 1 - `, [match[1]]); + `, + [match[1]] + ); let root_id = root[0]['root']; let last_id = root_id; let blob = await ssb.blobGet(root_id); @@ -40,8 +45,7 @@ async function main() { blob = await ssb.blobGet(dir?.links[part]); content_type = guess_content_type(part); } - } catch { - } + } catch {} respond({ status_code: 200, @@ -50,10 +54,10 @@ async function main() { }); } -main().catch(function(e) { +main().catch(function (e) { respond({ status_code: 200, data: `${e.message}\n${e.stack}`, content_type: 'text/plain', }); -}); \ No newline at end of file +});