pivot away from 11ty and instead store data in sqlite

The idea is going to be to build an 11ty frontend that pulls from this back-end
(or perhaps just the database, we'll see)
Also considering a mastodon-compatible api wrapper, or at the very least creating a separate wrapper and completely dropping the existing admin routes.
... ooh, I could do a micropub wrapper, too...

tl;dr: microservices. This is just the activitypub server now.
This commit is contained in:
Gordon Pedersen 2023-10-11 16:25:14 +11:00
parent 298fa4f42d
commit fd8c2073f0
47 changed files with 536 additions and 1415 deletions

View file

@ -1,95 +0,0 @@
const ACTOR = require("./actor").default
module.exports = function(eleventyConfig) {
// I'm .gitignoring my content for now, so 11ty should not ignore that
eleventyConfig.setUseGitIgnore(false)
// Filters are in a separate function to try and keep this config less cluttered
addFilters(eleventyConfig)
// same with shortcodes
addShortcodes(eleventyConfig)
// and collections
addCollections(eleventyConfig)
// add the actor data, accessible globally
eleventyConfig.addGlobalData("ACTOR", ACTOR);
// TODO: assets?
// files to passthrough copy
eleventyConfig.addPassthroughCopy({"img":"assets/img"})
eleventyConfig.addPassthroughCopy({"js":"assets/js"})
eleventyConfig.addPassthroughCopy("css")
eleventyConfig.addPassthroughCopy("CNAME")
// plugins
eleventyConfig.addPlugin(require("@11ty/eleventy-plugin-rss"))
const { EleventyHtmlBasePlugin } = require("@11ty/eleventy")
eleventyConfig.addPlugin(EleventyHtmlBasePlugin)
// Return your Object options:
return {
dir: {
input: "_content",
output: "_site"
},
htmlTemplateEngine: "njk",
templateFormats: ["md","html","njk"]
}
}
function addCollections(eleventyConfig) {
eleventyConfig.addCollection("feed", function(collectionApi) {
return collectionApi.getAllSorted().reverse().filter(item => {
if(!item.data.published) return false
return item.filePathStem.startsWith('/posts/')
}).map(item => {
item.data.author = ACTOR
return item
}).sort((a, b) => new Date(b.published).getTime() - new Date(a.published).getTime())
})
}
function addShortcodes(eleventyConfig) {
eleventyConfig.addNunjucksShortcode("getVar", function(varString){ return this.ctx[varString] })
eleventyConfig.addShortcode('renderlayoutblock', function(name){ return (this.page.layoutblock || {})[name] || '' })
eleventyConfig.addPairedShortcode('layoutblock', function(content, name) {
if (!this.page.layoutblock) this.page.layoutblock = {}
this.page.layoutblock[name] = content
return ''
})
}
function addFilters(eleventyConfig) {
eleventyConfig.addFilter("formatDate", formatDateFilter)
eleventyConfig.addFilter("dateISOString", dateISOStringFilter)
eleventyConfig.addFilter("dateObj", (value) => new Date(value))
eleventyConfig.addFilter("log", (value) => { console.log(`[11ty] 📄LOG: `, value); return value })
eleventyConfig.addFilter("concat", (value, other) => value + '' + other)
eleventyConfig.addNunjucksAsyncFilter("await", (promise) => promise.then(res => callback(null, res)).catch(err => callback(err)))
}
// default date formatting
function formatDateFilter(value) {
try{
const date = new Date(value)
if(date) return date.toISOString().replace('T', ' ').slice(0, -5)
else throw 'Unrecognized data format'
}
catch(e) {
console.error(`Could not convert "${value}"`, e)
return value;
}
}
// dates as iso string
function dateISOStringFilter(value) {
try{
const date = new Date(value)
if(date) return date.toISOString()
else throw 'Unrecognized data format'
}
catch(e) {
console.error(`Could not convert "${value}"`, e)
return value;
}
}

1
.gitignore vendored
View file

@ -173,3 +173,4 @@ _content/_data/_inbox
_content/_data/_outbox
_content/posts
_site
db.sqlite*

View file

@ -1 +0,0 @@
[]

View file

@ -1 +0,0 @@
[]

View file

@ -1 +0,0 @@
[]

View file

@ -1 +0,0 @@
module.exports = "layout-default.njk"

View file

@ -1 +0,0 @@
[]

View file

@ -1 +0,0 @@
[]

View file

@ -1,13 +0,0 @@
---js
{
layout: "layout-main.njk",
ctx: function() { return this.ctx }
}
---
{% from "macro-entry.njk" import entryMacro %}
{{ entryMacro(ctx(), author, url, content) }}
{% layoutblock 'foot' %}
<script src="/assets/js/relative-time.js"></script>
{% endlayoutblock %}

View file

@ -1,15 +0,0 @@
---
title: Feed
layout: layout-main.njk
scripts_foot: '<script src="/assets/js/relative-time.js"></script>'
---
<div class="h-feed">
<h2 class="p-name">{{ title }}</h2>
{{ content | safe }}
</div>
{% include 'partial-pagination.njk' %}
{% layoutblock 'foot' %}
<script src="/assets/js/relative-time.js"></script>
{% endlayoutblock %}

View file

@ -1,38 +0,0 @@
---
title: Mon Repos (Death's Domain)
---
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<meta name="mobile-web-app-capable" content="yes" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="icon" type="image/svg+xml" href="/assets/img/avatar-tt.svg">
<link rel="icon" type="image/png" href="/assets/img/avatar-tiny.png">
<link rel="authorization_endpoint" href="https://deathau-cellar-door.glitch.me/">
<link rel="token_endpoint" href="https://deathau-cellar-door.glitch.me/token">
{# <link rel="webmention" href="https://webmention.io/death.id.au/webmention" />
<link rel="pingback" href="https://webmention.io/death.id.au/xmlrpc" />
<link rel="microsub" href="https://aperture.p3k.io/microsub/807">
<link rel="micropub" href="https://micropub.death.id.au/.netlify/functions/micropub">
<link rel="micropub_media" href="https://micropub.death.id.au/.netlify/functions/media"> #}
<link rel="stylesheet" href="/css/styles.css">
<link rel="alternate" type="application/rss+xml" title="RSS Feed for {{ ACTOR.hostname }}" href="/rss.xml" />
<link rel="alternate" type="application/atom+xml" title="Atom Feed for {{ ACTOR.hostname}}" href="/atom.xml" />
<link rel="alternate" type="application/json" title="JSON Feed for {{ ACTOR.hostname }}" href="/feed.json" />
<script src="https://kit.fontawesome.com/ebe14e90c3.js" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/luxon/build/global/luxon.min.js" crossorigin="anonymous"></script>
<title>{{ title }}</title>
{% renderlayoutblock 'head' %}
</head>
<body>
{% renderlayoutblock 'header' %}
<main>
{{ content | safe }}
</main>
</body>
{% renderlayoutblock 'footer' %}
{% renderlayoutblock 'foot' %}
</html>

View file

@ -1,10 +0,0 @@
{% macro authorMacro(author) %}
{# {{ author | getAuthorData | log }} #}
<a class="p-author h-card u-url" href="{{ author.canonical_uri if author.canonical_uri else author.url }}">
<img class="u-photo small-avatar" alt="{{ author.icon.name if author.icon.name else "Avatar for " + author.preferredUsername }}" src="{{ author.icon.url if author.icon.url else author.avatar }}"/>
<span class="display-name">
<span class="p-name">{{ author.name }}</span>
<span class="p-nickname">{{ author.preferredUsername }}</span>
</span>
</a>
{% endmacro %}

View file

@ -1,9 +0,0 @@
{% from "macro-author.njk" import authorMacro %}
{% macro cardHeadMacro(author, date, url) %}
<div class="card-head">
<a class="u-url permalink" rel="bookmark" href="{{ url }}" >
<time class="dt-published" datetime="{{ date | dateISOString }}">{{ date | formatDate }}</time>
</a>
{{ authorMacro(author) }}
</div>
{% endmacro %}

View file

@ -1,14 +0,0 @@
{% from "macro-card-head.njk" import cardHeadMacro %}
{% from "macro-summary.njk" import summaryMacro %}
{% macro entryMacro(item, author, url, content, summaryOnly=false) %}
<div class="h-entry type-{{ item.postType }}">
{{ cardHeadMacro(author, item.published, url) }}
<div class="card-body">
{{ summaryMacro(item, url) }}
{% if item.type == 'article' and summaryOnly %}
{% elseif content %}
<div class="e-content">{{ content | safe }}</div>
{% endif %}
</div>
</div>
{% endmacro %}

View file

@ -1,83 +0,0 @@
{% macro summaryMacro(item, url) %}
{% switch item.type %}
{% case "article" %} {# article summary: #}
<h2 class="p-name"><a class="u-url" rel="bookmark" title="{{ item.name if item.name else item.title }}" href="{{ url }}">
{{ item.name if item.name else item.title }}
</a></h2>
{% if item.summary %}
<p class="p-summary">{{ item.summary | safe }}</p>
{% endif %}
{% case "reply" %} {# reply summary: #}
<p class="p-summary"><i class="fa-solid fa-reply"></i> Reply to <a class="u-in-reply-to" href="{{ item["in-reply-to"] }}">{{ item["in-reply-to"] }}</a></p>
{% case "like" %} {# like summary: #}
<p class="p-summary">Favourited <i class="fa-solid fa-star"></i> <a class="u-like-of" href="{{ item['like-of'] }}">{{ item['like-of'] }}</a></p>
{% case "boost" %} {# boost summary: #}
<p class="p-summary"></p>Boosted <i class="fa-solid fa-retweet"></i> <a class="u-repost-of" href="{{ item["repost-of"] }}">{{ item["repost-of"] }}</a></p>
{% case "bookmark" %} {# bookmark summary: #}
<p class="p-summary">Bookmarked <i class="fa-solid fa-bookmark"></i> <a class="u-bookmark-of" href="{{ item["bookmark-of"] }}">{{ item["bookmark-of"] }}</a></p>
{% case "read" %} {# read summary: #}
<p class="p-summary">
{% if item["read-status"].toLowerCase() == "to-read" %}
<data class="p-x-read-status p-read-status" value="to-read">To Read: </data>
<i class="fa-solid fa-book"></i>
{% elseif item["read-status"].toLowerCase() == "reading" %}
<data class="p-x-read-status p-read-status" value="reading">Currently Reading: </data>
<i class="fa-solid fa-book-open"></i>
{% elseif item["read-status"].toLowerCase() == "finished" %}
<data class="p-x-read-status p-read-status" value="finished">Finished Reading: </data>
<i class="fa-solid fa-book-bookmark"></i>
{% endif %}
{% if item["read-of"].startsWith("http") %}
<a class="u-read-of" href="{{ item["read-of"] }}">{{ item["read-of"] }}</a>
{% else %}
<strong class="p-read-of">{{ item["read-of"] }}</strong>
{% endif %}
</p>
{% case "watch" %} {# watch summary: #}
<p class="p-summary">
{% if item["watch-status"].toLowerCase() == "to-watch" %}
<data class="p-x-watch-status p-watch-status" value="to-watch">To Watch: </data>
{% elseif item["watch-status"].toLowerCase() == "watching" %}
<data class="p-x-watch-status p-watch-status" value="watching">Currently Watching: </data>
{% elseif item["watch-status"].toLowerCase() == "watched" or item["watch-status"].toLowerCase() == "finished" %}
<data class="p-x-watch-status p-watch-status" value="finished">Finished watching: </data>
{% else %}
<data class="p-x-watch-status p-watch-status" value="finished">Watched: </data>
{% endif %}
<i class="fa-solid fa-clapperboard"></i>
{% if item["watch-of"].startsWith("http") %}
<a class="u-watch-of" href="{{ item["watch-of"] }}">{{ item["watch-of"] }}</a>
{% else %}
<strong class="p-watch-of">{{ item["watch-of"] }}</strong>
{% endif %}
</p>
{% case "rsvp" %} {# rsvp summary: #}
<p class="p-summary">
{% if item.rsvp.toLowerCase() == "yes" %}
<i class="fa-regular fa-calendar-check"></i>
<data class="p-rsvp" value="yes">Will attend</data>
{% elseif item.rsvp.toLowerCase() == "maybe" %}
<i class="fa-regular fa-calendar-minus"></i>
<data class="p-rsvp" value="maybe">Might attend</data>
{% elseif item.rsvp.toLowerCase() == "no" %}
<i class="fa-regular fa-calendar-xmark"></i>
<data class="p-rsvp" value="no">Won't attend</data>
{% elseif item.rsvp.toLowerCase() == "interested" %}
<i class="fa-regular fa-calendar-plus"></i>
<data class="p-rsvp" value="interested">Interested in</data>
{% endif %}
<a class="u-in-reply-to" href="{{ item["in-reply-to"] }}">{{ item["in-reply-to"] }}</a>
</p>
{% endswitch %}
{% endmacro %}

View file

@ -1,15 +0,0 @@
{% if pagination %}
<nav>
<ul class="pagination" role="list">
<li><a href="{{ pagination.href.first }}" rel="first" title="First Page">«</a></li>
<li><a href="{{ pagination.href.previous if pagination.href.previous else "#" }}" class="{{ '' if pagination.href.previous else 'disabled' }}" rel="prev" title="Previous Page"></a></li>
{%- for pageEntry in pagination.pages %}
<li><a href="{{ pagination.hrefs[ loop.index0 ] }}"{% if page.url == pagination.hrefs[ loop.index0 ] %} aria-current="page" class="active" title="Current Page" {% else %} title="Jump to Page {{ loop.index }}" {% endif %}>{{ loop.index }}</a></li>
{%- endfor %}
<li><a href="{{ pagination.href.next if pagination.href.next else "#" }}" class="{{ '' if pagination.href.next else 'disabled' }}" rel="next" title="Next Page"></a></li>
<li><a href="{{ pagination.href.last }}" rel="last" title="Last Page">»</a></li>
</ul>
</nav>
{% endif %}

View file

@ -1,6 +0,0 @@
<h2 class="p-name"><a class="u-url" rel="bookmark" title="{{ item.name if item.name else item.title }}" href="{{ url }}">
{{ item.name if item.name else item.title }}
</a></h2>
{% if item.summary %}
<p class="p-summary">{{ item.summary | safe }}</p>
{% endif %}

View file

@ -1,36 +0,0 @@
---json
{
"layout": null,
"permalink": "atom.xml",
"eleventyExcludeFromCollections": true,
"metadata": {
"subtitle": "A feed of all my posts on the fediverse",
"language": "en"
}
}
---
<?xml version="1.0" encoding="utf-8"?>
{% from "macro-summary.njk" import summaryMacro %}
<feed xmlns="http://www.w3.org/2005/Atom" xml:base="{{ ACTOR.url }}">
<title>{{ ACTOR.name }}'s feed</title>
<subtitle>{{ metadata.subtitle }}</subtitle>
<link href="{{ permalink | absoluteUrl(ACTOR.url) }}" rel="self"/>
<updated>{{ collections.feed[0].date | dateToRfc3339 }}</updated>
<id>{{ ACTOR.id | absoluteUrl(ACTOR.url) }}</id>
<author>
<name>{{ ACTOR.name }}</name>
</author>
{%- for post in collections.feed %}
{%- set absolutePostUrl = post.url | absoluteUrl(ACTOR.url) %}
<entry>
<title>{{ post.data.title }}</title>
<link href="{{ absolutePostUrl }}"/>
<updated>{{ post.data.published | dateObj | dateToRfc3339 }}</updated>
<id>{{ absolutePostUrl }}</id>
<content xml:lang="{{ metadata.language }}" type="html">
{{ summaryMacro(post.data, post.url) | htmlToAbsoluteUrls(absolutePostUrl) }}
{{ post.templateContent | htmlToAbsoluteUrls(absolutePostUrl) }}
</content>
</entry>
{%- endfor %}
</feed>

View file

@ -1,76 +0,0 @@
---
layout: layout-main.njk
eleventyExcludeFromCollections: true
---
<!-- Reference for representative h-card properties: https://microformats.org/wiki/h-card -->
<div class="h-card" rel="author">
<img class="u-featured" src="{{ ACTOR.image.url }}" alt="{{ ACTOR.image.name}}" />
<img class="u-photo" alt="{{ ACTOR.icon.name}}" src="{{ ACTOR.icon.url }}" />
<h1>
I'm <span class="p-name">{{ ACTOR.name }}</span>
{% if ACTOR.name != ACTOR.preferredUsername %}
(a.k.a <span class="p-nickname">{{ ACTOR.preferredUsername }}</span>)
{% endif %}
</h1>
<p class="p-note">
{% if ACTOR.summary %}
{{ ACTOR.summary }}
{% else %}
...and I am a human on the Internet.
{% endif %}
</p>
<p>
Go check out some <a href="/posts">stuff I wrote</a><br>
Or stay up-to-date by following me
<ul>
<li><button class="icon-button button-input"
data-instruction="Please enter your fediverse / mastodon handle (e.g. '@user@domain.social')"
data-placeholder="@user@domain.social"
data-success="Thanks for the follow!"
onsubmit="handleFollow(event.value)">
<img src="/assets/img/Fediverse_logo_proposal.svg" alt="Fediverse logo">
Follow @{{ ACTOR.preferredUsername }}@{{ ACTOR.hostname }}
</button></li>
<li><i class="fa fa-rss"></i> <a class="u-url" href="/rss.xml">RSS Feed</a></li>
<li><i class="fa fa-feed"></i> <a class="u-url" href="/atom.xml">Atom Feed</a></li>
<li><i class="fa fa-feed"></i> <a class="u-url" href="/feed.json">JSON Feed</a></li>
</ul>
</p>
<p>
...or elsewhere on the Internet:
<ul>
<li><i><img class="tiny-avatar" src="/assets/img/avatar-tt-trans.svg"></i> <a class="u-uid u-url" href="https://death.id.au">Mon Repos (you are here)</a><a class="u-url" href="acct:death.au@death.id.au"></a></li>
<li><i><img class="tiny-avatar" src="/assets/img/Obsidian.svg"></i> <a class="u-url" href="https://notes.death.id.au" rel="me">My published notes</a></li>
<li><i class="fa-brands fa-mastodon"></i> <a class="u-url" href="https://pkm.social/@death_au" rel="me">@death_au@pkm.social</a></li>
<li><i class="fa-brands fa-github"></i> <a class="u-url" href="https://github.com/deathau" rel="me">@deathau</a></li>
<li><i class="fa-brands fa-twitter"></i> <a class="u-url" href="https://twitter.com/death_au" rel="me">@death_au</a></li>
<li><i class="fa-brands fa-linkedin"></i> <a class="u-url" href="https://www.linkedin.com/in/gordon-pedersen/">Gordon Pedersen</a></li>
</ul>
</p>
</div>
{% layoutblock 'foot' %}
<script src="/assets/js/follow.js"></script>
<script src="/assets/js/button-input.js"></script>
<script>
window.addEventListener('unhandledrejection', function(event) {
alert(event.reason)
})
function handleFollow(handle) {
try{
follow(`@${ACTOR.preferredUsername}@${ACTOR.hostname}`, handle)
}
catch(e){
alert(e)
}
}
function tryFollow(user) {
try{
follow(user)
}
catch(e){
alert(e)
}
}
</script>
{% endlayoutblock %}

View file

@ -1,36 +0,0 @@
---json
{
"layout": null,
"permalink": "feed.json",
"eleventyExcludeFromCollections": true,
"metadata": {
"subtitle": "A feed of all my posts on the fediverse",
"language": "en"
}
}
---
{ {% from "macro-summary.njk" import summaryMacro %}
"version": "https://jsonfeed.org/version/1.1",
"title": "{{ ACTOR.name }}'s feed",
"language": "{{ metadata.language }}",
"home_page_url": "{{ ACTOR.url }}/",
"feed_url": "{{ permalink | absoluteUrl(ACTOR.url) }}",
"description": "{{ metadata.subtitle }}",
"author": {
"name": "{{ ACTOR.name }}",
"url": "{{ ACTOR.url }}/"
},
"items": [
{%- for post in collections.feed %}
{%- set absolutePostUrl = post.url | absoluteUrl(ACTOR.url) %}
{
"id": "{{ absolutePostUrl }}",
"url": "{{ absolutePostUrl }}",
"title": "{{ post.data.title }}",
"content_html": {{ summaryMacro(post.data, post.url) | concat(post.templateContent) | htmlToAbsoluteUrls(absolutePostUrl) | dump | safe }},
"date_published": "{{ post.data.published | dateObj | dateToRfc3339 }}"
}
{% if not loop.last %},{% endif %}
{%- endfor %}
]
}

View file

@ -1,18 +0,0 @@
---
title: My Feed
layout: layout-feed.njk
pagination:
data: collections.feed
size: 20
eleventyExcludeFromCollections: true
---
{% from "macro-entry.njk" import entryMacro %}
<ul>
{% for item in pagination.items %}
<li>
{{ entryMacro(item.data, item.data.author, item.url, item.templateContent, true) }}
</li>
{% endfor %}
</ul>

View file

@ -1,36 +0,0 @@
---js
{
"layout": null,
"permalink": "rss.xml",
"eleventyExcludeFromCollections": true,
"metadata": {
"subtitle": "A feed of all my posts on the fediverse",
"language": "en"
}
}
---
<?xml version="1.0" encoding="utf-8"?>
{% from "macro-summary.njk" import summaryMacro %}
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xml:base="{{ ACTOR.url }}" xmlns:atom="http://www.w3.org/2005/Atom">
<channel>
<title>{{ ACTOR.name }}'s feed</title>
<link>{{ ACTOR.url }}</link>
<atom:link href="{{ permalink | absoluteUrl(ACTOR.url) }}" rel="self" type="application/rss+xml" />
<description>{{ metadata.subtitle }}</description>
<language>{{ metadata.language }}</language>
{%- for post in collections.feed | reverse %}
{%- set absolutePostUrl = post.url | absoluteUrl(ACTOR.url) %}
<item>
<title>{{ post.data.title }}</title>
<link>{{ absolutePostUrl }}</link>
<description>
{{ summaryMacro(post.data, post.url) | htmlToAbsoluteUrls(absolutePostUrl) }}
{{ post.templateContent | htmlToAbsoluteUrls(absolutePostUrl) }}
</description>
<pubDate>{{ post.data.published | dateObj | dateToRfc822 }}</pubDate>
<dc:creator>{{ ACTOR.name }}</dc:creator>
<guid>{{ absolutePostUrl }}</guid>
</item>
{%- endfor %}
</channel>
</rss>

View file

@ -8,8 +8,8 @@ export const summary = ""
// avatar image
const icon:{ type:"Image", mediaType:string, url:string, name:string } = {
type: "Image",
mediaType: "image/svg+xml",
url: BASE_URL + "/assets/img/avatar-tt.svg",
mediaType: "image/png",
url: "https://s.gravatar.com/avatar/bc0f8c2d2ecc533cb236ce1f858365a25dbbc80ce42df49b9a95e88f07f91720?s=800",
name: "My profile photo — a pixelated version of me"
}

BIN
bun.lockb

Binary file not shown.

View file

@ -1,211 +0,0 @@
:root {
--bg-rgb: 238, 238, 238;
--on-bg-rgb: 4, 4, 4;
--primary-rgb: 160, 116, 196;
--on-primary-rgb: 238, 238, 238;
--bg: rgb(var(--bg-rgb));
--on-bg: rgb(var(--on-bg-rgb));
--primary: rgb(var(--primary-rgb));
--on-primary: rgb(var(--on-primary-rgb));
--fade-alpha: 0.06;
--mute-alpha: 0.3;
--bg-fade: rgba(var(--bg-rgb), var(--fade-alpha));
--on-bg-fade: rgba(var(--on-bg-rgb), var(--fade-alpha));
--primary-fade: rgba(var(--primary-rgb), var(--fade-alpha));
--on-primary-fade: rgba(var(--on-primary-rgb), var(--fade-alpha));
--bg-muted: rgba(var(--bg-rgb), var(--mute-alpha));
--on-bg-muted: rgba(var(--on-bg-rgb), var(--mute-alpha));
--primary-muted: rgba(var(--primary-rgb), var(--mute-alpha));
--on-primary-muted: rgba(var(--on-primary-rgb), var(--mute-alpha));
}
@media (prefers-color-scheme: dark) {
:root{
--bg-rgb: 17, 17, 17;
--on-bg-rgb: 251, 251, 251;
--on-primary-rgb: 251, 251, 251;
--fade-alpha: 0.16;
}
}
html {
background-color: var(--bg);
color: var(--on-bg);
}
a {
color: var(--primary);
text-decoration: none;
}
a:hover {
text-decoration: underline;
}
body {
line-height: 1.6;
font-family: system-ui, -apple-system, BlinkMacSystemFont, Roboto, Helvetica, Arial, sans-serif;
text-align: center;
margin: 0;
min-height: 90vh;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
overflow-x: hidden;
}
p:last-child {
margin-block-end: 0;
}
img.u-photo { border-radius: 50%; max-height:200px; }
/* .p-author img.u-photo{
max-height: 48px;
} */
ul { padding: 0; list-style: none; }
img.u-featured {
display:block;
z-index:0;
margin-bottom:-125px
}
button.icon-button {
line-height: 24px;
background-color: #666289;
color:#fff;
border:none;
border-radius:4px;
}
button.icon-button>img {
max-height: 24px;
vertical-align: bottom;
}
.button-input-container>label{
display:block;
}
.button-input-container>input{
background-color: #666289;
color:#fff;
border:none;
border-radius: 4px;
padding: 4px 66px 4px 6px;
margin-right: -60px;
}
.button-input-container>input:focus{
border:none;
}
.button-input-container>button{
background-color: #666289;
color:#fff;
border-radius: 4px;
border-color: #fff;
}
i>img{
max-height: 1em;
vertical-align: middle;
}
img.tiny-avatar {
max-height: 17px;
}
img.small-avatar {
max-height: 40px;
}
/* Pagination */
.pagination {
margin: 50px auto;
}
.pagination li {
display: inline-block;
}
.pagination a {
padding: 8px 16px;
text-decoration: none;
border-radius: 5px;
border: 1px solid var(--on-bg-fade);
}
.pagination a.active {
background-color: var(--primary);
color: var(--on-primary);
}
.pagination a:hover:not(.active) { background-color: var(--on-bg-fade); }
.pagination a.disabled {
color: var(--primary-fade);
pointer-events: none;
}
/* End Pagination */
/* Feed Entries */
.h-entry {
max-width: 500px;
min-width: 320px;
background-color: var(--primary-fade);
padding: 20px;
margin: 0;
border: 1px solid var(--on-bg-fade);
text-align: left;
}
.h-entry:not(:last-child) {
border-bottom: none;
}
.h-entry .p-author {
max-width: calc(100% - 80px);
display: flex;
align-items: center;
gap: 10px;
overflow: hidden;
}
.h-entry .u-photo {
vertical-align: baseline;
}
.h-entry .display-name {
display: block;
max-width: 100%;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.h-entry .display-name .p-name {
white-space: nowrap;
display: block;
overflow: hidden;
text-overflow: ellipsis;
font-weight: 700;
}
.h-entry .display-name .p-nickname {
white-space: nowrap;
display: block;
overflow: hidden;
text-overflow: ellipsis;
color: var(--on-primary-muted);
}
.h-entry .permalink {
float:right;
text-align: right;
font-size: 0.8em;
color: var(--on-primary-muted);
display: block;
overflow: hidden;
text-overflow: ellipsis;
max-width:80px;
}
/* End Feed Entries */

View file

@ -1,170 +0,0 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Created with Inkscape (http://www.inkscape.org/) -->
<svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
width="196.52mm"
height="196.52mm"
viewBox="0 0 196.52 196.52"
version="1.1"
id="svg8"
inkscape:version="0.92.2 2405546, 2018-03-11"
sodipodi:docname="Logo_penta_connectat-imbrincat_retallats-color.svg"
inkscape:export-filename="/home/nestor/Pictures/Fediversal/Logo_penta_connectat-imbrincat_retallats-color-512x.png"
inkscape:export-xdpi="66.175453"
inkscape:export-ydpi="66.175453">
<defs
id="defs2" />
<sodipodi:namedview
id="base"
pagecolor="#ffffff"
bordercolor="#666666"
borderopacity="1.0"
inkscape:pageopacity="0.0"
inkscape:pageshadow="2"
inkscape:zoom="0.50411932"
inkscape:cx="-209.83484"
inkscape:cy="399.15332"
inkscape:document-units="mm"
inkscape:current-layer="layer2"
showgrid="false"
inkscape:snap-smooth-nodes="true"
inkscape:snap-midpoints="true"
inkscape:snap-global="false"
inkscape:window-width="1366"
inkscape:window-height="736"
inkscape:window-x="0"
inkscape:window-y="32"
inkscape:window-maximized="1"
fit-margin-top="5"
fit-margin-left="5"
fit-margin-right="5"
fit-margin-bottom="5" />
<metadata
id="metadata5">
<rdf:RDF>
<cc:Work
rdf:about="">
<dc:format>image/svg+xml</dc:format>
<dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
<dc:title />
</cc:Work>
</rdf:RDF>
</metadata>
<g
inkscape:groupmode="layer"
id="layer2"
inkscape:label="Linies"
style="display:inline"
transform="translate(6.6789703,-32.495842)">
<path
style="color:#000000;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:medium;line-height:normal;font-family:sans-serif;font-variant-ligatures:normal;font-variant-position:normal;font-variant-caps:normal;font-variant-numeric:normal;font-variant-alternates:normal;font-feature-settings:normal;text-indent:0;text-align:start;text-decoration:none;text-decoration-line:none;text-decoration-style:solid;text-decoration-color:#000000;letter-spacing:normal;word-spacing:normal;text-transform:none;writing-mode:lr-tb;direction:ltr;text-orientation:mixed;dominant-baseline:auto;baseline-shift:baseline;text-anchor:start;white-space:normal;shape-padding:0;clip-rule:nonzero;display:inline;overflow:visible;visibility:visible;opacity:1;isolation:auto;mix-blend-mode:normal;color-interpolation:sRGB;color-interpolation-filters:linearRGB;solid-color:#000000;solid-opacity:1;vector-effect:none;fill:#a730b8;fill-opacity:1;fill-rule:nonzero;stroke:none;stroke-width:41.5748024;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;color-rendering:auto;image-rendering:auto;shape-rendering:auto;text-rendering:auto;enable-background:accumulate"
d="m 181.13086,275.13672 a 68.892408,68.892408 0 0 1 -29.46484,29.32812 l 161.75781,162.38868 38.99805,-19.76368 z m 213.36328,214.1875 -38.99805,19.76367 81.96289,82.2832 a 68.892409,68.892409 0 0 1 29.47071,-29.33203 z"
transform="matrix(0.26458333,0,0,0.26458333,-6.6789703,32.495842)"
id="path9722"
inkscape:connector-curvature="0" />
<path
style="color:#000000;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:medium;line-height:normal;font-family:sans-serif;font-variant-ligatures:normal;font-variant-position:normal;font-variant-caps:normal;font-variant-numeric:normal;font-variant-alternates:normal;font-feature-settings:normal;text-indent:0;text-align:start;text-decoration:none;text-decoration-line:none;text-decoration-style:solid;text-decoration-color:#000000;letter-spacing:normal;word-spacing:normal;text-transform:none;writing-mode:lr-tb;direction:ltr;text-orientation:mixed;dominant-baseline:auto;baseline-shift:baseline;text-anchor:start;white-space:normal;shape-padding:0;clip-rule:nonzero;display:inline;overflow:visible;visibility:visible;opacity:1;isolation:auto;mix-blend-mode:normal;color-interpolation:sRGB;color-interpolation-filters:linearRGB;solid-color:#000000;solid-opacity:1;vector-effect:none;fill:#5496be;fill-opacity:1;fill-rule:nonzero;stroke:none;stroke-width:41.5748024;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;color-rendering:auto;image-rendering:auto;shape-rendering:auto;text-rendering:auto;enable-background:accumulate"
d="m 581.64648,339.39062 -91.57617,46.41016 6.75196,43.18945 103.61523,-52.51367 A 68.892409,68.892409 0 0 1 581.64648,339.39062 Z M 436.9082,412.74219 220.38281,522.47656 a 68.892408,68.892408 0 0 1 18.79492,37.08985 L 443.66016,455.93359 Z"
transform="matrix(0.26458333,0,0,0.26458333,-6.6789703,32.495842)"
id="path9729"
inkscape:connector-curvature="0" />
<path
style="color:#000000;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:medium;line-height:normal;font-family:sans-serif;font-variant-ligatures:normal;font-variant-position:normal;font-variant-caps:normal;font-variant-numeric:normal;font-variant-alternates:normal;font-feature-settings:normal;text-indent:0;text-align:start;text-decoration:none;text-decoration-line:none;text-decoration-style:solid;text-decoration-color:#000000;letter-spacing:normal;word-spacing:normal;text-transform:none;writing-mode:lr-tb;direction:ltr;text-orientation:mixed;dominant-baseline:auto;baseline-shift:baseline;text-anchor:start;white-space:normal;shape-padding:0;clip-rule:nonzero;display:inline;overflow:visible;visibility:visible;opacity:1;isolation:auto;mix-blend-mode:normal;color-interpolation:sRGB;color-interpolation-filters:linearRGB;solid-color:#000000;solid-opacity:1;vector-effect:none;fill:#ce3d1a;fill-opacity:1;fill-rule:nonzero;stroke:none;stroke-width:41.5748024;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;color-rendering:auto;image-rendering:auto;shape-rendering:auto;text-rendering:auto;enable-background:accumulate"
d="M 367.27539,142.4375 262.79492,346.4082 293.64258,377.375 404.26562,161.41797 A 68.892408,68.892408 0 0 1 367.27539,142.4375 Z m -131.6543,257.02148 -52.92187,103.31446 a 68.892409,68.892409 0 0 1 36.98633,18.97851 l 46.78125,-91.32812 z"
transform="matrix(0.26458333,0,0,0.26458333,-6.6789703,32.495842)"
id="path9713"
inkscape:connector-curvature="0" />
<path
style="color:#000000;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:medium;line-height:normal;font-family:sans-serif;font-variant-ligatures:normal;font-variant-position:normal;font-variant-caps:normal;font-variant-numeric:normal;font-variant-alternates:normal;font-feature-settings:normal;text-indent:0;text-align:start;text-decoration:none;text-decoration-line:none;text-decoration-style:solid;text-decoration-color:#000000;letter-spacing:normal;word-spacing:normal;text-transform:none;writing-mode:lr-tb;direction:ltr;text-orientation:mixed;dominant-baseline:auto;baseline-shift:baseline;text-anchor:start;white-space:normal;shape-padding:0;clip-rule:nonzero;display:inline;overflow:visible;visibility:visible;opacity:1;isolation:auto;mix-blend-mode:normal;color-interpolation:sRGB;color-interpolation-filters:linearRGB;solid-color:#000000;solid-opacity:1;vector-effect:none;fill:#d0188f;fill-opacity:1;fill-rule:nonzero;stroke:none;stroke-width:41.5748024;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;color-rendering:auto;image-rendering:auto;shape-rendering:auto;text-rendering:auto;enable-background:accumulate"
d="m 150.76758,304.91797 a 68.892408,68.892408 0 0 1 -34.41602,7.19531 68.892408,68.892408 0 0 1 -6.65039,-0.69531 l 30.90235,197.66211 a 68.892409,68.892409 0 0 1 34.41601,-7.19531 68.892409,68.892409 0 0 1 6.64649,0.69531 z"
transform="matrix(0.26458333,0,0,0.26458333,-6.6789703,32.495842)"
id="path1015"
inkscape:connector-curvature="0" />
<path
style="color:#000000;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:medium;line-height:normal;font-family:sans-serif;font-variant-ligatures:normal;font-variant-position:normal;font-variant-caps:normal;font-variant-numeric:normal;font-variant-alternates:normal;font-feature-settings:normal;text-indent:0;text-align:start;text-decoration:none;text-decoration-line:none;text-decoration-style:solid;text-decoration-color:#000000;letter-spacing:normal;word-spacing:normal;text-transform:none;writing-mode:lr-tb;direction:ltr;text-orientation:mixed;dominant-baseline:auto;baseline-shift:baseline;text-anchor:start;white-space:normal;shape-padding:0;clip-rule:nonzero;display:inline;overflow:visible;visibility:visible;opacity:1;isolation:auto;mix-blend-mode:normal;color-interpolation:sRGB;color-interpolation-filters:linearRGB;solid-color:#000000;solid-opacity:1;vector-effect:none;fill:#5b36e9;fill-opacity:1;fill-rule:nonzero;stroke:none;stroke-width:41.5748024;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;color-rendering:auto;image-rendering:auto;shape-rendering:auto;text-rendering:auto;enable-background:accumulate"
d="m 239.3418,560.54492 a 68.892408,68.892408 0 0 1 0.7207,13.87696 68.892408,68.892408 0 0 1 -7.26758,27.17968 l 197.62891,31.71289 a 68.892409,68.892409 0 0 1 -0.72266,-13.8789 68.892409,68.892409 0 0 1 7.26953,-27.17774 z"
transform="matrix(0.26458333,0,0,0.26458333,-6.6789703,32.495842)"
id="path1674"
inkscape:connector-curvature="0" />
<path
style="color:#000000;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:medium;line-height:normal;font-family:sans-serif;font-variant-ligatures:normal;font-variant-position:normal;font-variant-caps:normal;font-variant-numeric:normal;font-variant-alternates:normal;font-feature-settings:normal;text-indent:0;text-align:start;text-decoration:none;text-decoration-line:none;text-decoration-style:solid;text-decoration-color:#000000;letter-spacing:normal;word-spacing:normal;text-transform:none;writing-mode:lr-tb;direction:ltr;text-orientation:mixed;dominant-baseline:auto;baseline-shift:baseline;text-anchor:start;white-space:normal;shape-padding:0;clip-rule:nonzero;display:inline;overflow:visible;visibility:visible;opacity:1;isolation:auto;mix-blend-mode:normal;color-interpolation:sRGB;color-interpolation-filters:linearRGB;solid-color:#000000;solid-opacity:1;vector-effect:none;fill:#30b873;fill-opacity:1;fill-rule:nonzero;stroke:none;stroke-width:41.5748024;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;color-rendering:auto;image-rendering:auto;shape-rendering:auto;text-rendering:auto;enable-background:accumulate"
d="m 601.13281,377.19922 -91.21875,178.08203 a 68.892408,68.892408 0 0 1 36.99414,18.98242 L 638.125,396.18359 a 68.892409,68.892409 0 0 1 -36.99219,-18.98437 z"
transform="matrix(0.26458333,0,0,0.26458333,-6.6789703,32.495842)"
id="path1676"
inkscape:connector-curvature="0" />
<path
style="color:#000000;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:medium;line-height:normal;font-family:sans-serif;font-variant-ligatures:normal;font-variant-position:normal;font-variant-caps:normal;font-variant-numeric:normal;font-variant-alternates:normal;font-feature-settings:normal;text-indent:0;text-align:start;text-decoration:none;text-decoration-line:none;text-decoration-style:solid;text-decoration-color:#000000;letter-spacing:normal;word-spacing:normal;text-transform:none;writing-mode:lr-tb;direction:ltr;text-orientation:mixed;dominant-baseline:auto;baseline-shift:baseline;text-anchor:start;white-space:normal;shape-padding:0;clip-rule:nonzero;display:inline;overflow:visible;visibility:visible;opacity:1;isolation:auto;mix-blend-mode:normal;color-interpolation:sRGB;color-interpolation-filters:linearRGB;solid-color:#000000;solid-opacity:1;vector-effect:none;fill:#ebe305;fill-opacity:1;fill-rule:nonzero;stroke:none;stroke-width:41.5748024;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;color-rendering:auto;image-rendering:auto;shape-rendering:auto;text-rendering:auto;enable-background:accumulate"
d="m 476.72266,125.33008 a 68.892408,68.892408 0 0 1 -29.47071,29.33203 l 141.26563,141.81055 a 68.892409,68.892409 0 0 1 29.46875,-29.33204 z"
transform="matrix(0.26458333,0,0,0.26458333,-6.6789703,32.495842)"
id="path1678"
inkscape:connector-curvature="0" />
<path
style="color:#000000;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:medium;line-height:normal;font-family:sans-serif;font-variant-ligatures:normal;font-variant-position:normal;font-variant-caps:normal;font-variant-numeric:normal;font-variant-alternates:normal;font-feature-settings:normal;text-indent:0;text-align:start;text-decoration:none;text-decoration-line:none;text-decoration-style:solid;text-decoration-color:#000000;letter-spacing:normal;word-spacing:normal;text-transform:none;writing-mode:lr-tb;direction:ltr;text-orientation:mixed;dominant-baseline:auto;baseline-shift:baseline;text-anchor:start;white-space:normal;shape-padding:0;clip-rule:nonzero;display:inline;overflow:visible;visibility:visible;opacity:1;isolation:auto;mix-blend-mode:normal;color-interpolation:sRGB;color-interpolation-filters:linearRGB;solid-color:#000000;solid-opacity:1;vector-effect:none;fill:#f47601;fill-opacity:1;fill-rule:nonzero;stroke:none;stroke-width:41.5748024;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;color-rendering:auto;image-rendering:auto;shape-rendering:auto;text-rendering:auto;enable-background:accumulate"
d="m 347.78711,104.63086 -178.57617,90.49805 a 68.892409,68.892409 0 0 1 18.79297,37.08593 l 178.57421,-90.50195 a 68.892408,68.892408 0 0 1 -18.79101,-37.08203 z"
transform="matrix(0.26458333,0,0,0.26458333,-6.6789703,32.495842)"
id="path1680"
inkscape:connector-curvature="0" />
<path
style="color:#000000;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:medium;line-height:normal;font-family:sans-serif;font-variant-ligatures:normal;font-variant-position:normal;font-variant-caps:normal;font-variant-numeric:normal;font-variant-alternates:normal;font-feature-settings:normal;text-indent:0;text-align:start;text-decoration:none;text-decoration-line:none;text-decoration-style:solid;text-decoration-color:#000000;letter-spacing:normal;word-spacing:normal;text-transform:none;writing-mode:lr-tb;direction:ltr;text-orientation:mixed;dominant-baseline:auto;baseline-shift:baseline;text-anchor:start;white-space:normal;shape-padding:0;clip-rule:nonzero;display:inline;overflow:visible;visibility:visible;opacity:1;isolation:auto;mix-blend-mode:normal;color-interpolation:sRGB;color-interpolation-filters:linearRGB;solid-color:#000000;solid-opacity:1;vector-effect:none;fill:#57c115;fill-opacity:1;fill-rule:nonzero;stroke:none;stroke-width:41.5748024;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;color-rendering:auto;image-rendering:auto;shape-rendering:auto;text-rendering:auto;enable-background:accumulate"
d="m 446.92578,154.82617 a 68.892408,68.892408 0 0 1 -34.98242,7.48242 68.892408,68.892408 0 0 1 -6.0293,-0.63281 l 15.81836,101.29102 43.16211,6.92578 z m -16,167.02735 37.40039,239.48242 a 68.892409,68.892409 0 0 1 33.91406,-6.94336 68.892409,68.892409 0 0 1 7.20704,0.79101 L 474.08984,328.77734 Z"
transform="matrix(0.26458333,0,0,0.26458333,-6.6789703,32.495842)"
id="path9758"
inkscape:connector-curvature="0" />
<path
style="color:#000000;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:medium;line-height:normal;font-family:sans-serif;font-variant-ligatures:normal;font-variant-position:normal;font-variant-caps:normal;font-variant-numeric:normal;font-variant-alternates:normal;font-feature-settings:normal;text-indent:0;text-align:start;text-decoration:none;text-decoration-line:none;text-decoration-style:solid;text-decoration-color:#000000;letter-spacing:normal;word-spacing:normal;text-transform:none;writing-mode:lr-tb;direction:ltr;text-orientation:mixed;dominant-baseline:auto;baseline-shift:baseline;text-anchor:start;white-space:normal;shape-padding:0;clip-rule:nonzero;display:inline;overflow:visible;visibility:visible;opacity:1;isolation:auto;mix-blend-mode:normal;color-interpolation:sRGB;color-interpolation-filters:linearRGB;solid-color:#000000;solid-opacity:1;vector-effect:none;fill:#dbb210;fill-opacity:1;fill-rule:nonzero;stroke:none;stroke-width:41.5748024;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;color-rendering:auto;image-rendering:auto;shape-rendering:auto;text-rendering:auto;enable-background:accumulate"
d="m 188.13086,232.97461 a 68.892408,68.892408 0 0 1 0.75781,14.0957 68.892408,68.892408 0 0 1 -7.16015,26.98242 l 101.36914,16.28125 19.92382,-38.9082 z m 173.73633,27.90039 -19.92578,38.91211 239.51367,38.4668 a 68.892409,68.892409 0 0 1 -0.69531,-13.71875 68.892409,68.892409 0 0 1 7.34961,-27.32422 z"
transform="matrix(0.26458333,0,0,0.26458333,-6.6789703,32.495842)"
id="path9760"
inkscape:connector-curvature="0" />
</g>
<g
inkscape:groupmode="layer"
id="layer3"
inkscape:label="Nodes"
style="display:inline;opacity:1"
transform="translate(6.6789703,-32.495842)">
<circle
style="fill:#ffca00;fill-opacity:0.99596773;stroke:none;stroke-width:0.26458332;stroke-opacity:0.96078431"
id="path817"
cx="106.26596"
cy="51.535553"
r="16.570711"
transform="rotate(3.1178174)" />
<circle
id="path819"
style="fill:#64ff00;fill-opacity:0.99596773;stroke:none;stroke-width:0.26458332;stroke-opacity:0.96078431"
cx="171.42836"
cy="110.19328"
r="16.570711"
transform="rotate(3.1178174)" />
<circle
id="path823"
style="fill:#00a3ff;fill-opacity:0.99596773;stroke:none;stroke-width:0.26458332;stroke-opacity:0.96078431"
cx="135.76379"
cy="190.27704"
r="16.570711"
transform="rotate(3.1178174)" />
<circle
style="fill:#9500ff;fill-opacity:0.99596773;stroke:none;stroke-width:0.26458332;stroke-opacity:0.96078431"
id="path825"
cx="48.559471"
cy="181.1138"
r="16.570711"
transform="rotate(3.1178174)" />
<circle
id="path827"
style="fill:#ff0000;fill-opacity:0.99596773;stroke:none;stroke-width:0.26458332;stroke-opacity:0.96078431"
cx="30.328812"
cy="95.366837"
r="16.570711"
transform="rotate(3.1178174)" />
</g>
</svg>

Before

Width:  |  Height:  |  Size: 19 KiB

View file

@ -1,6 +0,0 @@
<svg width="140" height="180" viewBox="0 0 140 180" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M49.775 105.089C54.3828 103.715 61.8069 101.605 70.3434 101.082C65.2222 88.1449 63.986 76.8242 64.9803 66.7442C66.1285 55.1033 70.23 45.3874 74.228 37.1201C75.0811 35.3561 75.9012 33.7135 76.6879 32.1378C77.8017 29.9069 78.8486 27.81 79.8278 25.6916C81.4579 22.1652 82.6674 19.051 83.2791 16.1576C83.8806 13.3125 83.8838 10.7715 83.1727 8.3342C82.4607 5.89352 80.9475 3.26635 78.0704 0.386692C74.3134 -0.587559 70.1448 0.267767 67.0197 3.08162L29.9298 36.4772C27.861 38.34 26.503 40.8642 26.0879 43.6182L22.8899 64.8384C27.9185 69.2873 40.33 82.2201 47.8789 100.165C48.5525 101.766 49.1875 103.408 49.775 105.089Z" fill="white"/>
<path d="M21.3902 74.5293C21.2153 75.2761 20.9692 76.0051 20.6549 76.7063L1.05225 120.436C-0.961131 124.928 -0.0336421 130.194 3.39276 133.726L34.2418 165.523C49.9952 142.262 47.6984 120.379 40.5026 103.274C35.0465 90.3037 26.777 80.1526 21.3902 74.5293Z" fill="white"/>
<path d="M41.3687 169.269C41.9093 169.355 42.4575 169.407 43.0096 169.424C48.864 169.6 58.7098 170.109 66.6947 171.582C73.2088 172.783 86.1213 176.397 96.747 179.505C104.855 181.877 113.211 175.396 114.387 167.024C115.245 160.917 116.855 154.009 119.821 147.677L119.753 147.702C114.73 133.682 108.34 124.629 101.641 118.849C94.9619 113.086 87.7708 110.397 80.8276 109.42C69.2835 107.795 58.7071 110.832 52.0453 112.791C56.0353 129.428 54.8074 149.004 41.3687 169.269Z" fill="white"/>
<path d="M124.96 139.034C131.626 128.965 136.375 121.134 138.881 116.888C140.135 114.764 139.907 112.102 138.423 110.133C134.554 105.002 127.152 94.5755 123.12 84.9218C118.973 74.9962 118.355 59.5866 118.319 52.081C118.306 49.2279 117.402 46.4413 115.639 44.1994L91.6762 13.73C91.5918 15.1034 91.3946 16.4659 91.1093 17.8158C90.3118 21.5882 88.8073 25.3437 87.0916 29.0552C86.086 31.2306 84.9238 33.5612 83.7497 35.9157C82.9682 37.4827 82.1814 39.0607 81.432 40.6102C77.5579 48.6212 73.9528 57.3151 72.9451 67.5313C72.011 77.0006 73.2894 88.014 79.0482 101.162C80.0074 101.243 80.9727 101.351 81.9422 101.487C90.2067 102.651 98.8807 105.891 106.866 112.781C113.73 118.704 119.932 127.19 124.96 139.034Z" fill="white"/>
</svg>

Before

Width:  |  Height:  |  Size: 2.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.3 KiB

View file

@ -1,37 +0,0 @@
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 -0.5 13 17" shape-rendering="crispEdges">
<metadata>Made with Pixels to Svg https://codepen.io/shshaw/pen/XbxvNj</metadata>
<path stroke="#522301" d="M3 0h1M2 1h1M1 2h2M2 4h1M1 7h1M2 9h1M4 9h1" />
<path stroke="#512201" d="M4 0h1M3 1h1M1 3h2M1 4h1M1 5h1M1 6h1M1 8h2M0 9h1M3 9h1M0 10h2M0 11h3M1 12h1" />
<path stroke="#805130" d="M5 0h1M11 2h1" />
<path stroke="#815231" d="M6 0h2M3 2h1" />
<path stroke="#8d5e3d" d="M8 0h1M6 1h1M11 1h1" />
<path stroke="#8c5d3c" d="M9 0h1M12 2h1" />
<path stroke="#8d5e3c" d="M10 0h1M5 1h1M7 1h1M9 1h2" />
<path stroke="#7f5231" d="M4 1h1" />
<path stroke="#8c5e3c" d="M8 1h1M4 2h1" />
<path stroke="#fecbcb" d="M5 2h3M9 2h1M5 3h1M4 5h1M9 5h1M4 6h2M12 6h1M7 7h1" />
<path stroke="#ffcbcb" d="M8 2h1M10 2h1M10 7h1" />
<path stroke="#e9b6b6" d="M3 3h1M3 5h1M4 7h1M10 13h1" />
<path stroke="#ffcccc" d="M4 3h1M8 3h3M4 4h1M7 4h4M12 4h1M6 5h2M11 5h2M6 6h1M11 6h1M6 7h1M8 7h2M3 13h1" />
<path stroke="#fecccc" d="M6 3h2M11 3h2M6 4h1M8 5h1M10 5h1" />
<path stroke="#e9b5b5" d="M3 4h1M3 6h1M3 7h1" />
<path stroke="#000000" d="M5 4h1M11 4h1M4 10h1M6 10h1M3 11h1M7 11h1M4 12h1M10 12h1" />
<path stroke="#a97777" d="M2 5h1" />
<path stroke="#fbc8c8" d="M5 5h1M12 7h1" />
<path stroke="#aa7676" d="M2 6h1M2 7h1" />
<path stroke="#ce9a9a" d="M7 6h1" />
<path stroke="#ce9b9b" d="M8 6h2" />
<path stroke="#fcc8c8" d="M10 6h1" />
<path stroke="#b55916" d="M5 7h1M5 8h1M6 9h1M7 10h1" />
<path stroke="#e47726" d="M11 7h1M7 8h4M8 9h3" />
<path stroke="#aa7777" d="M3 8h2M5 9h1" />
<path stroke="#d06d25" d="M6 8h1M11 8h1M7 9h1M8 10h2M8 11h1" />
<path stroke="#4d3ca6" d="M1 9h1M2 10h1" />
<path stroke="#2a2a2a" d="M5 10h1M4 11h2M7 12h1M5 13h4M5 14h1M8 14h1" />
<path stroke="#2b2b2b" d="M6 11h1M5 12h2M8 12h1M6 14h2" />
<path stroke="#323232" d="M9 11h1M3 12h1M4 16h2M8 16h2" />
<path stroke="#333333" d="M9 12h1M9 13h1M9 14h1" />
<path stroke="#232323" d="M4 13h1M4 14h1" />
<path stroke="#003298" d="M4 15h2M9 15h1" />
<path stroke="#003399" d="M6 15h3" />
</svg>

Before

Width:  |  Height:  |  Size: 2 KiB

View file

@ -1,38 +0,0 @@
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 -0.5 20 20" shape-rendering="crispEdges">
<metadata>Made with Pixels to Svg https://codepen.io/shshaw/pen/XbxvNj</metadata>
<path stroke="#666289" d="M0 0h20M0 1h20M0 2h20M0 3h6M14 3h6M0 4h5M15 4h5M0 5h4M16 5h4M0 6h4M16 6h4M0 7h4M16 7h4M0 8h4M16 8h4M0 9h4M16 9h4M0 10h4M16 10h4M0 11h4M15 11h5M0 12h3M14 12h6M0 13h3M6 13h1M13 13h7M0 14h3M13 14h7M0 15h4M5 15h1M14 15h6M0 16h6M14 16h6M0 17h7M13 17h7M0 18h7M13 18h7M0 19h7M9 19h2M13 19h7" />
<path stroke="#522301" d="M6 3h1M5 4h1M4 5h2M5 7h1M4 10h1M5 12h1M7 12h1" />
<path stroke="#512201" d="M7 3h1M6 4h1M4 6h2M4 7h1M4 8h1M4 9h1M4 11h2M3 12h1M6 12h1M3 13h2M3 14h3M4 15h1" />
<path stroke="#805130" d="M8 3h1M14 5h1" />
<path stroke="#815231" d="M9 3h2M6 5h1" />
<path stroke="#8d5e3d" d="M11 3h1M9 4h1M14 4h1" />
<path stroke="#8c5d3c" d="M12 3h1M15 5h1" />
<path stroke="#8d5e3c" d="M13 3h1M8 4h1M10 4h1M12 4h2" />
<path stroke="#7f5231" d="M7 4h1" />
<path stroke="#8c5e3c" d="M11 4h1M7 5h1" />
<path stroke="#fecbcb" d="M8 5h3M12 5h1M8 6h1M7 8h1M12 8h1M7 9h2M15 9h1M10 10h1" />
<path stroke="#ffcbcb" d="M11 5h1M13 5h1M13 10h1" />
<path stroke="#e9b6b6" d="M6 6h1M6 8h1M7 10h1M13 16h1" />
<path stroke="#ffcccc" d="M7 6h1M11 6h3M7 7h1M10 7h4M15 7h1M9 8h2M14 8h2M9 9h1M14 9h1M9 10h1M11 10h2M6 16h1" />
<path stroke="#fecccc" d="M9 6h2M14 6h2M9 7h1M11 8h1M13 8h1" />
<path stroke="#e9b5b5" d="M6 7h1M6 9h1M6 10h1" />
<path stroke="#000000" d="M8 7h1M14 7h1M7 13h1M9 13h1M6 14h1M10 14h1M7 15h1M13 15h1" />
<path stroke="#a97777" d="M5 8h1" />
<path stroke="#fbc8c8" d="M8 8h1M15 10h1" />
<path stroke="#aa7676" d="M5 9h1M5 10h1" />
<path stroke="#ce9a9a" d="M10 9h1" />
<path stroke="#ce9b9b" d="M11 9h2" />
<path stroke="#fcc8c8" d="M13 9h1" />
<path stroke="#b55916" d="M8 10h1M8 11h1M9 12h1M10 13h1" />
<path stroke="#e47726" d="M14 10h1M10 11h4M11 12h3" />
<path stroke="#aa7777" d="M6 11h2M8 12h1" />
<path stroke="#d06d25" d="M9 11h1M14 11h1M10 12h1M11 13h2M11 14h1" />
<path stroke="#4d3ca6" d="M4 12h1M5 13h1" />
<path stroke="#2a2a2a" d="M8 13h1M7 14h2M10 15h1M8 16h4M8 17h1M11 17h1" />
<path stroke="#2b2b2b" d="M9 14h1M8 15h2M11 15h1M9 17h2" />
<path stroke="#323232" d="M12 14h1M6 15h1M7 19h2M11 19h2" />
<path stroke="#333333" d="M12 15h1M12 16h1M12 17h1" />
<path stroke="#232323" d="M7 16h1M7 17h1" />
<path stroke="#003298" d="M7 18h2M12 18h1" />
<path stroke="#003399" d="M9 18h3" />
</svg>

Before

Width:  |  Height:  |  Size: 2.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 76 KiB

View file

@ -1,61 +0,0 @@
function buttonInputClick() {
this.style.display = 'none'
const buttonInput = document.createElement('div')
buttonInput.classList.add('button-input-container')
if(this.dataset.instruction){
const label = document.createElement('label')
buttonInput.appendChild(label)
label.innerText = this.dataset.instruction
}
const input = document.createElement('input')
buttonInput.appendChild(input)
input.type = 'text'
if(this.dataset.placeholder){
input.placeholder = this.dataset.placeholder
}
const button = document.createElement('button')
buttonInput.appendChild(button)
button.innerText = "Submit"
button.addEventListener('click', () => {
if(this.onsubmit){
const event = new Event('button-input-value')
event.value = input.value
this.onsubmit(event)
}
buttonInput.parentNode.removeChild(buttonInput)
if(this.dataset.success){
const span = document.createElement('span')
span.classList.add('success')
span.innerText = this.dataset.success
setTimeout(() => {
span.parentNode.removeChild(span)
this.style.display = null
}, 5000);
this.parentNode.insertBefore(span, this.nextSibling)
}
else{
this.style.display = null
}
})
input.addEventListener("keypress", function(event) {
if (event.key === "Enter") {
event.preventDefault();
button.click();
}
});
this.parentNode.insertBefore(buttonInput, this.nextSibling)
input.focus()
}
document.addEventListener('DOMContentLoaded', () => {
document.querySelectorAll('.button-input').forEach(button => {
button.addEventListener('click', buttonInputClick)
});
}, false);

View file

@ -1,35 +0,0 @@
const SUBSCRIBE_LINK_REL = 'http://ostatus.org/schema/1.0/subscribe'
function follow(username, handle) {
if(!handle){
handle = prompt("Please enter your fediverse / mastodon handle (e.g. '@user@domain.social')", "@")
}
if(handle) {
const input = handle
handle = handle.trim().replace(/^@/,'')
const split = handle.split('@')
if(split.length == 2) {
const resource = `acct:${handle}`
const domain = split[1]
// look up remote user via webfinger
const url = `https://${domain}/.well-known/webfinger?resource=${resource}`
fetch(url, {headers: {
'Content-Type': 'application/activity+json'
}}).then(async result => {
const json = await result.json()
const subscribe = json.links.find(link => link.rel && link.rel == SUBSCRIBE_LINK_REL)
let template = subscribe.template
window.open(template.replace("{uri}", username), '_blank').focus()
})
.catch(e => {
console.error(e)
throw `Sorry, we couldn't find a subscribe uri for ${input}.\n\nTry searching for "${username}" on ${domain} (or in your fediverse client of choice)`
})
}
else {
throw 'Please enter your fediverse address in @user@domain.social format'
}
}
}

View file

@ -1,6 +0,0 @@
document.addEventListener('DOMContentLoaded', () => {
document.querySelectorAll('time').forEach(time => {
const datetime = luxon.DateTime.fromISO(time.getAttribute('datetime'))
time.innerText = datetime.toRelative()
});
}, false);

View file

@ -14,9 +14,7 @@
"typescript": "^5.0.0"
},
"dependencies": {
"@11ty/eleventy": "^2.0.1",
"@11ty/eleventy-plugin-rss": "^1.2.0",
"gray-matter": "^4.0.3",
"node-forge": "^1.3.1"
"node-forge": "^1.3.1",
"using-statement": "^0.4.2"
}
}

View file

@ -1,11 +1,14 @@
import * as db from "./db"
import { verify } from "./request"
import outbox from "./outbox"
import inbox from "./inbox"
import ACTOR from "../actor"
import { activityPubTypes } from "./env"
import ActivityPubDB from "./db"
export default (req: Request): Response | Promise<Response> | undefined => {
let db:ActivityPubDB
export default (req: Request, database:ActivityPubDB): Response | Promise<Response> | undefined => {
db = database
const url = new URL(req.url)
let match
@ -24,7 +27,7 @@ export default (req: Request): Response | Promise<Response> | undefined => {
}
export function reqIsActivityPub(req:Request) {
const contentType = req.headers.get("Accept")
const contentType = req.headers.get("Accept") + ',' + req.headers.get('Content-Type')
return activityPubTypes.some(t => contentType?.includes(t))
}
@ -47,7 +50,7 @@ const postOutbox = async (req:Request):Promise<Response> => {
// ensure that the verified actor matches the actor in the request body
if (ACTOR.id !== body.actor) return new Response("", { status: 401 })
return await outbox(body)
return await outbox(body, db)
}
const postInbox = async (req:Request):Promise<Response> => {
@ -69,21 +72,21 @@ const postInbox = async (req:Request):Promise<Response> => {
// ensure that the verified actor matches the actor in the request body
if (from !== body.actor) return new Response("", { status: 401 })
return await inbox(body)
return await inbox(body, db)
}
const getOutbox = async (req:Request):Promise<Response> => {
console.log("GetOutbox")
// TODO: Paging?
const posts = await db.listOutboxActivities()
const posts = db.listOutboxActivities()
return Response.json({
"@context": "https://www.w3.org/ns/activitystreams",
id: ACTOR.outbox,
type: "OrderedCollection",
totalItems: posts.length,
orderedItems: posts.map((post) => ({
totalItems: posts?.length,
orderedItems: posts?.map((post) => ({
...post,
actor: ACTOR.id
})).sort( (a,b) => new Date(b.published).getTime() - new Date(a.published).getTime())
@ -95,13 +98,13 @@ const getFollowers = async (req:Request):Promise<Response> => {
const url = new URL(req.url)
const page = url.searchParams.get("page")
const followers = await db.listFollowers()
const followers = db.listFollowers()
if(!page) return Response.json({
"@context": "https://www.w3.org/ns/activitystreams",
id: ACTOR.followers,
type: "OrderedCollection",
totalItems: followers.length,
totalItems: followers?.length,
first: `${ACTOR.followers}?page=1`,
})
else return Response.json({
@ -109,8 +112,8 @@ const getFollowers = async (req:Request):Promise<Response> => {
id: `${ACTOR.followers}?page=${page}`,
type: "OrderedCollectionPage",
partOf: ACTOR.followers,
totalItems: followers.length,
orderedItems: followers.map(follower => follower.actor)
totalItems: followers?.length,
orderedItems: followers?.map(follower => follower?.id)
})
}
@ -119,13 +122,13 @@ const getFollowing = async (req:Request):Promise<Response> => {
const url = new URL(req.url)
const page = url.searchParams.get("page")
const following = await db.listFollowing()
const following = db.listFollowing()
if(!page) return Response.json({
"@context": "https://www.w3.org/ns/activitystreams",
id: ACTOR.following,
type: "OrderedCollection",
totalItems: following.length,
totalItems: following?.length,
first: `${ACTOR.following}?page=1`,
})
else return Response.json({
@ -133,8 +136,8 @@ const getFollowing = async (req:Request):Promise<Response> => {
id: `${ACTOR.following}?page=${page}`,
type: "OrderedCollectionPage",
partOf: ACTOR.following,
totalItems: following.length,
orderedItems: following.map(follow => follow.actor)
totalItems: following?.length,
orderedItems: following?.map(follow => follow.id)
})
}
@ -142,18 +145,18 @@ const getActor = async (req:Request):Promise<Response> => {
console.log("GetActor")
if(reqIsActivityPub(req)) return Response.json(ACTOR, { headers: { "Content-Type": "application/activity+json"}})
else return Response.json(await db.listPosts())
else return Response.json(db.listPosts())
}
const getPost = async (req:Request, id:string):Promise<Response> => {
console.log("GetPost", id)
if(reqIsActivityPub(req)) return Response.json((await db.getOutboxActivity(id)).object, { headers: { "Content-Type": "application/activity+json"}})
else return Response.json(await db.getPost(id))
if(reqIsActivityPub(req)) return Response.json((db.getOutboxActivity(id))?.object, { headers: { "Content-Type": "application/activity+json"}})
else return Response.json(db.getPost(id))
}
const getOutboxActivity = async (req:Request, id:string):Promise<Response> => {
console.log("GetOutboxActivity", id)
return Response.json((await db.getOutboxActivity(id)), { headers: { "Content-Type": "application/activity+json"}})
return Response.json((db.getOutboxActivity(id)), { headers: { "Content-Type": "application/activity+json"}})
}

View file

@ -1,11 +1,14 @@
import { idsFromValue } from "./activitypub"
import * as db from "./db"
import { ADMIN_PASSWORD, ADMIN_USERNAME, activityPubTypes } from "./env"
import outbox from "./outbox"
import { fetchObject } from "./request"
import ACTOR from "../actor"
import ActivityPubDB from "./db"
export default (req: Request): Response | Promise<Response> | undefined => {
let db:ActivityPubDB
export default (req: Request, database: ActivityPubDB): Response | Promise<Response> | undefined => {
db = database
const url = new URL(req.url)
if(!url.pathname.startsWith('/admin')) return undefined
@ -15,7 +18,7 @@ export default (req: Request): Response | Promise<Response> | undefined => {
let match
if(req.method === "GET" && (match = url.pathname.match(/^\/test\/?$/i))) return new Response("", { status: 204 })
else if(req.method == "POST" && (match = url.pathname.match(/^\/rebuild\/?$/i))) return rebuild(req)
// else if(req.method == "POST" && (match = url.pathname.match(/^\/rebuild\/?$/i))) return rebuild(req)
else if(req.method == "POST" && (match = url.pathname.match(/^\/create\/?$/i))) return create(req)
else if(req.method == "POST" && (match = url.pathname.match(/^\/follow\/([^\/]+)\/?$/i))) return follow(req, match[1])
else if(req.method == "DELETE" && (match = url.pathname.match(/^\/follow\/([^\/]+)\/?$/i))) return unfollow(req, match[1])
@ -43,11 +46,11 @@ const checkAuth = (headers: Headers): Boolean => {
return username === ADMIN_USERNAME && password === ADMIN_PASSWORD
}
// rebuild the 11ty static pages
export const rebuild = async(req:Request):Promise<Response> => {
await db.rebuild()
return new Response("", { status: 201 })
}
// // rebuild the 11ty static pages
// export const rebuild = async(req:Request):Promise<Response> => {
// db.rebuild()
// return new Response("", { status: 201 })
// }
// create an activity
const create = async (req:Request, inReplyTo:string|null = null):Promise<Response> => {
@ -82,10 +85,10 @@ const create = async (req:Request, inReplyTo:string|null = null):Promise<Respons
object: { ...object }
}
return await outbox(activity)
return await outbox(activity, db)
}
const follow = async (req:Request, handle:string):Promise<Response> => {
const idFromHandle = async(handle:string) => {
let url
if(handle.startsWith('@')) handle = handle.substring(1)
try {
@ -106,6 +109,11 @@ const follow = async (req:Request, handle:string):Promise<Response> => {
url = actorLink.href
}
return url
}
const follow = async (req:Request, handle:string):Promise<Response> => {
const url = await idFromHandle(handle)
console.log(`Following ${url}`)
// send the follow request to the supplied actor
@ -115,22 +123,23 @@ const follow = async (req:Request, handle:string):Promise<Response> => {
actor: ACTOR.id,
object: url,
to: [url, "https://www.w3.org/ns/activitystreams#Public"]
})
}, db)
}
const unfollow = async (req:Request, handle:string):Promise<Response> => {
const url = await idFromHandle(handle)
// check to see if we are already following. If not, just return success
const existing = await db.getFollowing(handle)
const existing = db.getFollowing(url)
if (!existing) return new Response("", { status: 204 })
const activity = await db.getOutboxActivity(existing.id)
const activity = db.getOutboxActivity(existing.activity_id)
// outbox will also take care of the deletion
return await outbox({
"@context": "https://www.w3.org/ns/activitystreams",
type: "Undo",
actor: ACTOR.id,
object: activity,
to: activity.to
})
to: activity?.to
}, db)
}
const like = async (req:Request, object_url:string):Promise<Response> => {
@ -143,22 +152,22 @@ const like = async (req:Request, object_url:string):Promise<Response> => {
object: object,
to: [...idsFromValue(object.attributedTo), "https://www.w3.org/ns/activitystreams#Public"],
cc: [ACTOR.followers]
})
}, db)
}
const unlike = async (req:Request, object_id:string):Promise<Response> => {
const unlike = async (req:Request, activity_id:string):Promise<Response> => {
// check to see if we are already following. If not, just return success
const liked = await db.listLiked()
let existing = liked.find(o => o.object_id === object_id)
const liked = db.listLiked()
let existing = liked?.find(o => o?.activity_id === activity_id)
if (!existing){
const object = await (await fetchObject(object_id)).json()
const object = await (await fetchObject(activity_id)).json()
idsFromValue(object).forEach(id => {
const e = liked.find(o => o.object_id === id)
const e = liked?.find(o => o.activity_id === id)
if(e) existing = e
})
}
if (!existing) return new Response("No like found to delete", { status: 204 })
const activity = await db.getOutboxActivity(existing.id)
const activity = db.getOutboxActivity(existing.activity_id)
return undo(activity)
}
@ -172,22 +181,22 @@ const dislike = async (req:Request, object_url:string):Promise<Response> => {
object: object,
to: [...idsFromValue(object.attributedTo), "https://www.w3.org/ns/activitystreams#Public"],
cc: [ACTOR.followers]
})
}, db)
}
const undislike = async (req:Request, object_id:string):Promise<Response> => {
// check to see if we are already following. If not, just return success
const disliked = await db.listDisliked()
let existing = disliked.find(o => o.object_id === object_id)
const disliked = db.listDisliked()
let existing = disliked?.find(o => o.activity_id === object_id)
if (!existing){
const object = await (await fetchObject(object_id)).json()
idsFromValue(object).forEach(id => {
const e = disliked.find(o => o.object_id === id)
const e = disliked?.find(o => o.activity_id === id)
if(e) existing = e
})
}
if (!existing) return new Response("No dislike found to delete", { status: 204 })
const activity = await db.getOutboxActivity(existing.id)
const activity = db.getOutboxActivity(existing.activity_id)
return undo(activity)
}
@ -201,22 +210,22 @@ const share = async (req:Request, object_url:string):Promise<Response> => {
object: object,
to: [...idsFromValue(object.attributedTo), "https://www.w3.org/ns/activitystreams#Public"],
cc: [ACTOR.followers]
})
}, db)
}
const unshare = async (req:Request, object_id:string):Promise<Response> => {
// check to see if we are already following. If not, just return success
const shared = await db.listShared()
let existing = shared.find(o => o.object_id === object_id)
const shared = db.listShared()
let existing = shared?.find(o => o.activity_id === object_id)
if (!existing){
const object = await (await fetchObject(object_id)).json()
idsFromValue(object).forEach(id => {
const e = shared.find(o => o.object_id === id)
const e = shared?.find(o => o.activity_id === id)
if(e) existing = e
})
}
if (!existing) return new Response("No share found to delete", { status: 204 })
const activity = await db.getOutboxActivity(existing.id)
const activity = db.getOutboxActivity(existing.activity_id)
return undo(activity)
}
@ -229,23 +238,23 @@ const undo = async(activity:any):Promise<Response> => {
object: activity,
to: activity.to,
cc: activity.cc
})
}, db)
}
const deletePost = async (req:Request, id:string):Promise<Response> => {
const post = await db.getPostByURL(id)
const post = db.getPostByURL(id)
if(!post) return new Response("", { status: 404 })
const activity = await db.getOutboxActivity(post.local_id)
const activity = db.getOutboxActivity(post.activity_id)
return await outbox({
"@context": "https://www.w3.org/ns/activitystreams",
type: "Delete",
actor: ACTOR.id,
to: activity.to,
cc: activity.cc,
audience: activity.audience,
to: activity?.to,
cc: activity?.cc,
// audience: activity?.audience,
object: {
id,
type: "Tombstone"
}
})
}, db)
}

575
src/db.ts
View file

@ -1,229 +1,426 @@
import { ACTIVITY_INBOX_PATH, ACTIVITY_OUTBOX_PATH, CONTENT_PATH, DATA_PATH, POSTS_PATH, STATIC_PATH } from "./env"
import path from "path"
import { readdir } from "fs/promises"
import { unlinkSync } from "node:fs"
import { fetchObject } from "./request"
import { idsFromValue } from "./activitypub"
import ACTOR from "../actor"
const matter = require('gray-matter')
const Eleventy = require("@11ty/eleventy")
import { Database, Statement } from "bun:sqlite"
// rebuild the 11ty static pages
export async function rebuild() {
console.info(`Building 11ty from ${CONTENT_PATH}, to ${STATIC_PATH}`)
await new Eleventy(CONTENT_PATH, STATIC_PATH, { configPath: '.eleventy.js' }).write()
export interface ActivityObject {
activity_id: string
id: string
published: string
}
export async function createInboxActivity(activity:any, object_id:any) {
const activityFile = Bun.file(path.join(ACTIVITY_INBOX_PATH, `${object_id}.activity.json`))
await Bun.write(activityFile, JSON.stringify(activity))
export interface Activity extends ActivityObject {
type: string
actor: string
published: string
to: string[]
cc?: string[]
object?: any
}
export async function createOutboxActivity(activity:any, object_id:any) {
const activityFile = Bun.file(path.join(ACTIVITY_OUTBOX_PATH, `${object_id}.activity.json`))
await Bun.write(activityFile, JSON.stringify(activity))
export interface Following extends ActivityObject {
accepted?: boolean
}
export async function getInboxActivity(id:string) {
const file = Bun.file(path.join(ACTIVITY_INBOX_PATH, `${id}.activity.json`))
return await file.json()
export interface Post extends ActivityObject {
attributedTo: string
type: string
content?: string
}
export async function getOutboxActivity(id:string) {
const file = Bun.file(path.join(ACTIVITY_OUTBOX_PATH, `${id}.activity.json`))
return await file.json()
}
export default class ActivityPubDB {
// The Database
db: Database
export async function listInboxActivities() {
return await Promise.all(
(await readdir(ACTIVITY_INBOX_PATH)).filter(v => v.endsWith('.activity.json'))
.map(async filename => await Bun.file(path.join(ACTIVITY_INBOX_PATH, filename)).json())
)
}
// Cached Statements
export async function listOutboxActivities() {
return await Promise.all(
(await readdir(ACTIVITY_OUTBOX_PATH)).filter(v => v.endsWith('.activity.json'))
.map(async filename => await Bun.file(path.join(ACTIVITY_OUTBOX_PATH, filename)).json())
)
}
export async function createPost(post_object:any, object_id:string) {
const file = Bun.file(path.join(POSTS_PATH, `${object_id}.md`))
let {type, object, inReplyTo} = post_object
if(inReplyTo && typeof inReplyTo === 'string') inReplyTo = await fetchObject(inReplyTo)
if(object){
let { content, published, id, attributedTo } = object
if(content as string) content = '> ' + content.replace('\n', '\n> ') + '\n'
else content = ""
content += post_object.content || ""
//TODO: add appropriate content for different types (e.g. like, etc)
const data:any = { id, published, attributedTo, type }
if(inReplyTo) data.inReplyTo = idsFromValue(inReplyTo).at(0)
await Bun.write(file, matter.stringify(content, data))
constructor() {
this.db = new Database('./db.sqlite')
this.migrate()
this.cacheQueries()
}
else {
const { content, published, id, attributedTo } = post_object
let reply_content = ""
if(!object && inReplyTo) {
reply_content = inReplyTo.content
if(reply_content as string) reply_content = '> ' + reply_content.replace('\n', '\n> ') + '\n'
else reply_content = ""
close() {
this.db.close()
}
migrate() {
let version = (this.db.query("PRAGMA user_version;").get() as {user_version:number})?.user_version
console.log(`Hi from migrate! User version: ${version}`)
const statements:Statement[] = []
switch(version) {
case 0:
console.log("migrating db version 1")
this.db.exec("PRAGMA journal_mode = WAL;")
// Create the inbox table
statements.push(this.db.prepare(`CREATE TABLE [inbox] (
[activity_id] TEXT NOT NULL PRIMARY KEY,
[id] TEXT NOT NULL,
[type] TEXT NOT NULL,
[actor] TEXT NOT NULL,
[published] TEXT NOT NULL,
[to] TEXT NOT NULL,
[cc] TEXT,
[activity] TEXT NOT NULL
)`))
// Create the outbox table
statements.push(this.db.prepare(`CREATE TABLE [outbox] (
[activity_id] TEXT NOT NULL PRIMARY KEY,
[id] TEXT NOT NULL,
[type] TEXT NOT NULL,
[actor] TEXT NOT NULL,
[published] TEXT NOT NULL,
[to] TEXT NOT NULL,
[cc] TEXT,
[activity] TEXT NOT NULL
)`))
// Create the following table
statements.push(this.db.prepare(`CREATE TABLE [following] (
[activity_id] TEXT NOT NULL PRIMARY KEY,
[id] TEXT NOT NULL,
[published] TEXT NOT NULL,
[accepted] INTEGER
)`))
// Create the followers table
statements.push(this.db.prepare(`CREATE TABLE [followers] (
[activity_id] TEXT NOT NULL PRIMARY KEY,
[id] TEXT NOT NULL,
[published] TEXT NOT NULL
)`))
// Create the liked table
statements.push(this.db.prepare(`CREATE TABLE [liked] (
[activity_id] TEXT NOT NULL PRIMARY KEY,
[id] TEXT NOT NULL,
[published] TEXT NOT NULL
)`))
// Create the disliked table
statements.push(this.db.prepare(`CREATE TABLE [disliked] (
[activity_id] TEXT NOT NULL PRIMARY KEY,
[id] TEXT NOT NULL,
[published] TEXT NOT NULL
)`))
// Create the shared table
statements.push(this.db.prepare(`CREATE TABLE [shared] (
[activity_id] TEXT NOT NULL PRIMARY KEY,
[id] TEXT NOT NULL,
[published] TEXT NOT NULL
)`))
version = 1
case 1:
// Create the posts table
statements.push(this.db.prepare(`CREATE TABLE [posts] (
[activity_id] TEXT NOT NULL PRIMARY KEY,
[id] TEXT NOT NULL,
[published] TEXT NOT NULL,
[attributedTo] TEXT,
[type] TEXT NOT NULL,
[content] TEXT,
[object] TEXT
)`))
version = 2
case 2: break;
default: break;
}
const data:any = { id, published, attributedTo, type }
if(inReplyTo) data.inReplyTo = idsFromValue(inReplyTo).at(0)
await Bun.write(file, matter.stringify((reply_content || "") + (content || ""), data))
const migration = this.db.transaction((statements:Statement[]) => {
statements.forEach(s => {
console.log(s.toString());
s.run();
s.finalize()
})
return true
})
if(migration(statements)) this.db.run(`PRAGMA user_version=${version}`)
}
rebuild()
}
export async function getPost(id:string) {
const file = Bun.file(path.join(POSTS_PATH, `${id}.md`))
const { data, content } = matter(await file.text())
return {
...data,
content: content.trim(),
local_id: id
queries:{
createInboxActivity?:Statement,
getInboxActivity?:Statement,
listInboxActivities?:Statement,
createOutboxActivity?:Statement,
getOutboxActivity?:Statement,
listOutboxActivities?:Statement,
createFollowing?:Statement,
getFollowing?:Statement,
deleteFollowing?:Statement,
listFollowing?:Statement,
acceptFollowing?:Statement,
createFollower?:Statement,
getFollower?:Statement,
deleteFollower?:Statement,
listFollowers?:Statement,
createLiked?:Statement,
getLiked?:Statement,
deleteLiked?:Statement,
listLiked?:Statement,
createDisliked?:Statement,
getDisliked?:Statement,
deleteDisliked?:Statement,
listDisliked?:Statement,
createShared?:Statement,
getShared?:Statement,
deleteShared?:Statement,
listShared?:Statement,
createPost?:Statement,
getPost?:Statement,
getPostByURL?:Statement,
deletePost?:Statement,
listPosts?:Statement
} = {}
cacheQueries() {
// inbox queries
this.queries.createInboxActivity = this.db.query(`INSERT INTO [inbox]
([activity_id], [id], [type], [actor], [published], [to], [cc], [activity])
VALUES ($activity_id, $id, $type, $actor, $published, $to, $cc, $activity)`)
this.queries.getInboxActivity = this.db.query(`SELECT * FROM [inbox] WHERE [activity_id]=$activity_id`)
this.queries.listInboxActivities = this.db.query(`SELECT * FROM [inbox] ORDER BY [published] DESC`)
// outbox queries
this.queries.createOutboxActivity = this.db.query(`INSERT INTO [outbox]
([activity_id], [id], [type], [actor], [published], [to], [cc], [activity])
VALUES ($activity_id, $id, $type, $actor, $published, $to, $cc, $activity)`)
this.queries.getOutboxActivity = this.db.query(`SELECT * FROM [outbox] WHERE [activity_id]=$activity_id`)
this.queries.listOutboxActivities = this.db.query(`SELECT * FROM [outbox] ORDER BY [published] DESC`)
// following queries
this.queries.createFollowing = this.db.query(`INSERT INTO [following]
([activity_id], [id], [published], [accepted])
VALUES ($activity_id, $id, $published, NULL)`)
this.queries.getFollowing = this.db.query('SELECT * FROM [following] WHERE [id]=$id')
this.queries.deleteFollowing = this.db.query('DELETE FROM [following] WHERE [id]=$id')
this.queries.listFollowing = this.db.query('SELECT * FROM [following] ORDER BY [published] DESC')
this.queries.acceptFollowing = this.db.query('UPDATE [following] SET [accepted]=TRUE WHERE [id]=$id')
// follower queries
this.queries.createFollower = this.db.query(`INSERT INTO [followers]
([activity_id], [id], [published])
VALUES ($activity_id, $id, $published)`)
this.queries.getFollower = this.db.query('SELECT * FROM [followers] WHERE [id]=$id')
this.queries.deleteFollower = this.db.query('DELETE FROM [followers] WHERE [id]=$id')
this.queries.listFollowers = this.db.query('SELECT * FROM [followers] ORDER BY [published] DESC')
// liked queries
this.queries.createLiked = this.db.query(`INSERT INTO [liked]
([activity_id], [id], [published])
VALUES ($activity_id, $id, $published)`)
this.queries.getLiked = this.db.query('SELECT * FROM [liked] WHERE [id]=$id')
this.queries.deleteLiked = this.db.query('DELETE FROM [liked] WHERE [id]=$id')
this.queries.listLiked = this.db.query('SELECT * FROM [liked] ORDER BY [published] DESC')
// disliked queries
this.queries.createDisliked = this.db.query(`INSERT INTO [disliked]
([activity_id], [id], [published])
VALUES ($activity_id, $id, $published)`)
this.queries.getDisliked = this.db.query('SELECT * FROM [disliked] WHERE [id]=$id')
this.queries.deleteDisliked = this.db.query('DELETE FROM [disliked] WHERE [id]=$id')
this.queries.listDisliked = this.db.query('SELECT * FROM [disliked] ORDER BY [published] DESC')
// shared queries
this.queries.createShared = this.db.query(`INSERT INTO [shared]
([activity_id], [id], [published])
VALUES ($activity_id, $id, $published)`)
this.queries.getShared = this.db.query('SELECT * FROM [shared] WHERE [id]=$id')
this.queries.deleteShared = this.db.query('DELETE FROM [shared] WHERE [id]=$id')
this.queries.listShared = this.db.query('SELECT * FROM [shared] ORDER BY [published] DESC')
// post queries
this.queries.createPost = this.db.query(`INSERT INTO [posts]
([activity_id], [id], [published], [attributedTo], [type], [content], [object])
VALUES ($activity_id, $id, $published, $attributedTo, $type, $content, $object)`)
this.queries.getPost = this.db.query('SELECT * FROM [posts] WHERE [activity_id]=$activity_id')
this.queries.getPostByURL = this.db.query('SELECT * FROM [posts] WHERE [id]=$id')
this.queries.deletePost = this.db.query('DELETE FROM [posts] WHERE [id]=$id')
this.queries.listPosts = this.db.query('SELECT * FROM [posts] ORDER BY [published] DESC')
}
}
export async function getPostByURL(url_id:string) {
if(!url_id || !url_id.startsWith(ACTOR.url + '/posts/')) return null
const match = url_id.match(/\/([0-9a-f]+)\/?$/)
const local_id = match ? match[1] : url_id
return await getPost(local_id)
}
createInboxActivity(activity_id:string, activity:any) {
//new Date(activity.published).getTime().toString(36)
return this.queries.createInboxActivity?.run({
$activity_id: activity_id,
$id: activity.id,
$type: activity.type,
$actor: activity.actor,
$published: activity.published || new Date().toISOString(),
$to: JSON.stringify(activity.to),
$cc: JSON.stringify(activity.cc),
$activity: JSON.stringify(activity)
})
}
export async function deletePost(id:string) {
unlinkSync(path.join(POSTS_PATH, id + '.md'))
rebuild()
}
getInboxActivity(activity_id:string):Activity | undefined {
return JSON.parse((this.queries.getInboxActivity?.get(activity_id) as any).activity)
}
export async function listPosts() {
return await Promise.all((await readdir(POSTS_PATH)).filter(v => v.endsWith('.md')).map(async filename => await getPost(filename.slice(0, -3))))
}
listInboxActivities():Activity[] | undefined {
return this.queries.listInboxActivities?.all().map(r => JSON.parse((r as any).activity))
}
export async function createFollowing(handle:string, id:string) {
const file = Bun.file(path.join(DATA_PATH, `following.json`))
const following_list = await file.json() as Array<any>
if(!following_list.find(v => v.id === id || v.handle === handle)) following_list.push({id, handle, createdAt: new Date().toISOString()})
await Bun.write(file, JSON.stringify(following_list))
rebuild()
}
createOutboxActivity(activity_id:string, activity:any) {
//new Date(activity.published).getTime().toString(36)
return this.queries.createOutboxActivity?.run({
$activity_id: activity_id,
$id: activity.id,
$type: activity.type,
$actor: activity.actor,
$published: activity.published,
$to: JSON.stringify(activity.to),
$cc: JSON.stringify(activity.cc),
$activity: JSON.stringify(activity)
})
}
export async function deleteFollowing(handle:string) {
const file = Bun.file(path.join(DATA_PATH, `following.json`))
const following_list = await file.json() as Array<any>
await Bun.write(file, JSON.stringify(following_list.filter(v => v.handle !== handle)))
rebuild()
}
getOutboxActivity(activity_id:string): Activity | undefined {
return JSON.parse((this.queries.getOutboxActivity?.get(activity_id) as any).activity)
}
export async function getFollowing(handle:string) {
const file = Bun.file(path.join(DATA_PATH, `following.json`))
const following_list = await file.json() as Array<any>
return following_list.find(v => v.handle === handle)
}
listOutboxActivities(): Activity[] | undefined {
return this.queries.listOutboxActivities?.all().map(r => JSON.parse((r as any).activity))
}
export async function listFollowing(onlyAccepted = true) {
const file = Bun.file(path.join(DATA_PATH, `following.json`))
return ((await file.json()) as Array<any>).filter(f => !onlyAccepted || f.accepted)
}
createFollowing(activity_id:string, id:string, published:string | Date) {
if(published instanceof Date) published = published.toISOString()
return this.queries.createFollowing?.run({
$activity_id: activity_id,
$id: id,
$published: published
})
}
export async function acceptFollowing(handle:string) {
const file = Bun.file(path.join(DATA_PATH, `following.json`))
const following_list = await file.json() as Array<any>
const following = following_list.find(v => v.handle === handle)
if(following) following.accepted = new Date().toISOString()
await Bun.write(file, JSON.stringify(following_list))
rebuild()
}
getFollowing(id:string): Following | undefined {
return this.queries.getFollowing?.get(id) as any
}
export async function createFollower(actor:string, id:string) {
const file = Bun.file(path.join(DATA_PATH, `followers.json`))
const followers_list = await file.json() as Array<any>
if(!followers_list.find(v => v.id === id || v.actor === actor)) followers_list.push({id, actor, createdAt: new Date().toISOString()})
await Bun.write(file, JSON.stringify(followers_list))
rebuild()
}
deleteFollowing(id:string) {
return this.queries.deleteFollowing?.run(id)
}
export async function deleteFollower(actor:string) {
const file = Bun.file(path.join(DATA_PATH, `followers.json`))
const followers_list = await file.json() as Array<any>
await Bun.write(file, JSON.stringify(followers_list.filter(v => v.actor !== actor)))
rebuild()
}
listFollowing(): Following[] | undefined {
return this.queries.listFollowing?.all() as Following[]
}
export async function getFollower(actor:string) {
const file = Bun.file(path.join(DATA_PATH, `followers.json`))
const followers_list = await file.json() as Array<any>
return followers_list.find(v => v.actor === actor)
}
acceptFollowing(id:string) {
return this.queries.acceptFollowing?.run(id)
}
export async function listFollowers() {
const file = Bun.file(path.join(DATA_PATH, `followers.json`))
return await file.json() as Array<any>
}
createFollower(activity_id:string, id:string, published:string | Date) {
if(published instanceof Date) published = published.toISOString()
return this.queries.createFollower?.run({
$activity_id: activity_id,
$id: id,
$published: published
})
}
export async function createLiked(object_id:string, id:string) {
const file = Bun.file(path.join(DATA_PATH, `liked.json`))
const liked_list = await file.json() as Array<any>
if(!liked_list.find(v => v.object_id === object_id)) liked_list.push({id, object_id, createdAt: new Date().toISOString()})
await Bun.write(file, JSON.stringify(liked_list))
rebuild()
}
getFollower(id:string): ActivityObject | undefined {
return this.queries.getFollower?.get(id) as ActivityObject
}
export async function deleteLiked(object_id:string) {
const file = Bun.file(path.join(DATA_PATH, `liked.json`))
const liked_list = await file.json() as Array<any>
await Bun.write(file, JSON.stringify(liked_list.filter(v => v.object_id !== object_id)))
rebuild()
}
deleteFollower(id:string) {
console.log("! DELETE Follower ", id)
return this.queries.deleteFollower?.run(id)
}
export async function listLiked() {
const file = Bun.file(path.join(DATA_PATH, `liked.json`))
return await file.json() as Array<any>
}
listFollowers(): ActivityObject[] | undefined {
return this.queries.listFollowers?.all().map(x => x as ActivityObject)
}
export async function createDisliked(object_id:string, id:string) {
const file = Bun.file(path.join(DATA_PATH, `disliked.json`))
const disliked_list = await file.json() as Array<any>
if(!disliked_list.find(v => v.object_id === object_id)) disliked_list.push({id, object_id, createdAt: new Date().toISOString()})
await Bun.write(file, JSON.stringify(disliked_list))
rebuild()
}
createLiked(activity_id:string, id:string, published:string | Date) {
if(published instanceof Date) published = published.toISOString()
return this.queries.createLiked?.run({
$activity_id: activity_id,
$id: id,
$published: published
})
}
export async function deleteDisliked(object_id:string) {
const file = Bun.file(path.join(DATA_PATH, `disliked.json`))
const disliked_list = await file.json() as Array<any>
await Bun.write(file, JSON.stringify(disliked_list.filter(v => v.object_id !== object_id)))
rebuild()
}
getLiked(id:string): ActivityObject | undefined {
return this.queries.getLiked?.get(id) as ActivityObject
}
export async function listDisliked() {
const file = Bun.file(path.join(DATA_PATH, `disliked.json`))
return await file.json() as Array<any>
}
deleteLiked(id:string) {
return this.queries.deleteLiked?.run(id)
}
export async function createShared(object_id:string, id:string) {
const file = Bun.file(path.join(DATA_PATH, `shared.json`))
const shared_list = await file.json() as Array<any>
if(!shared_list.find(v => v.object_id === object_id)) shared_list.push({id, object_id, createdAt: new Date().toISOString()})
await Bun.write(file, JSON.stringify(shared_list))
rebuild()
}
listLiked(): ActivityObject[] | undefined {
return this.queries.listLiked?.all().map(x => x as ActivityObject)
}
export async function deleteShared(object_id:string) {
const file = Bun.file(path.join(DATA_PATH, `shared.json`))
const shared_list = await file.json() as Array<any>
await Bun.write(file, JSON.stringify(shared_list.filter(v => v.object_id !== object_id)))
rebuild()
}
createDisliked(activity_id:string, id:string, published:string | Date) {
if(published instanceof Date) published = published.toISOString()
return this.queries.createDisliked?.run({
$activity_id: activity_id,
$id: id,
$published: published
})
}
export async function listShared() {
const file = Bun.file(path.join(DATA_PATH, `shared.json`))
return await file.json() as Array<any>
getDisliked(id:string): ActivityObject | undefined {
return this.queries.getDisliked?.get(id) as ActivityObject
}
deleteDisliked(id:string) {
return this.queries.deleteDisliked?.run(id)
}
listDisliked(): ActivityObject[] | undefined {
return this.queries.listDisliked?.all().map(x => x as ActivityObject)
}
createShared(activity_id:string, id:string, published:string | Date) {
if(published instanceof Date) published = published.toISOString()
return this.queries.createShared?.run({
$activity_id: activity_id,
$id: id,
$published: published
})
}
getShared(id:string): ActivityObject | undefined {
return this.queries.getShared?.get(id) as ActivityObject
}
deleteShared(id:string) {
return this.queries.deleteShared?.run(id)
}
listShared(): ActivityObject[] | undefined {
return this.queries.listShared?.all().map(x => x as ActivityObject)
}
createPost(activity_id:string, object:any) {
return this.queries.createPost?.run({
$activity_id: activity_id,
$id: object.id,
$published: object.published,
$attributedTo: object.attributedTo,
$type: object.type,
$content: object.content,
$object: JSON.stringify(object)
})
}
getPost(activity_id:string): Post | undefined {
return JSON.parse((this.queries.getPost?.get(activity_id) as any).object)
}
getPostByURL(id:string): Post | undefined {
return JSON.parse((this.queries.getPostByURL?.get(id) as any).object)
}
deletePost(activity_id:string) {
return this.queries.deletePost?.run(activity_id)
}
listPosts(): Post[] | undefined {
return this.queries.listPosts?.all().map(p => JSON.parse((p as any).object))
}
}

View file

@ -31,6 +31,7 @@ export const STATIC_PATH = path.join('.', '_site')
export const CONTENT_PATH = path.join('.', '_content')
export const POSTS_PATH = path.join(CONTENT_PATH, "posts")
export const DATA_PATH = path.join(CONTENT_PATH, "_data")
export const DB_PATH = path.join(DATA_PATH, "db.sqlite")
export const ACTIVITY_INBOX_PATH = path.join(DATA_PATH, "_inbox")
export const ACTIVITY_OUTBOX_PATH = path.join(DATA_PATH, "_outbox")
@ -49,4 +50,4 @@ export const activityPubTypes = [
'application/ld+json; profile="https://www.w3.org/ns/activitystreams"',
'application/activity+json'
]
export const contentTypeHeader = { 'Content-Type': activityPubTypes[0]}
export const contentTypeHeader = { 'Content-Type': activityPubTypes[0] }

View file

@ -1,26 +1,29 @@
import { idsFromValue } from "./activitypub"
import * as db from "./db"
import outbox from "./outbox"
import { send } from "./request"
import ACTOR from "../actor"
import ActivityPubDB from "./db"
export default async function inbox(activity:any) {
let db:ActivityPubDB
export default async function inbox(activity:any, database:ActivityPubDB) {
db = database
const date = new Date()
// get the main recipients ([...new Set()] is to dedupe)
const recipientList = [...new Set([...idsFromValue(activity.to), ...idsFromValue(activity.cc), ...idsFromValue(activity.audience)])]
// if my list of followers in the list of recipients, then forward to them as well
if(recipientList.includes(ACTOR.url + "/followers")) {
(await db.listFollowers()).forEach(f => send(f, activity, activity.attributedTo))
(db.listFollowers())?.forEach(f => send(f.id, activity, activity.attributedTo))
}
// save this activity to my inbox
const id = `${date.getTime().toString(16)}`
db.createInboxActivity(activity, id)
const activity_id = `${date.getTime().toString(32)}`
console.log(`New inbox activity ${activity_id} (${activity.type})`, activity)
db.createInboxActivity(activity_id, activity)
// TODO: process the activity and update local data
switch(activity.type) {
case "Follow": follow(activity, id); break;
case "Follow": follow(activity, activity_id); break;
case "Accept": accept(activity); break;
case "Reject": reject(activity); break;
case "Undo": undo(activity); break;
@ -29,10 +32,10 @@ export default async function inbox(activity:any) {
return new Response("", { status: 204 })
}
const follow = async (activity:any, id:string) => {
const follow = async (activity:any, activity_id:string) => {
// someone is following me
// save this follower locally
db.createFollower(activity.actor, id)
db.createFollower(activity_id, activity.actor, activity.published || new Date().toISOString())
// send an accept message to the outbox
await outbox({
"@context": "https://www.w3.org/ns/activitystreams",
@ -40,26 +43,26 @@ const follow = async (activity:any, id:string) => {
actor: ACTOR.id,
to: [activity.actor],
object: activity,
});
}, db);
}
const undo = async (activity:any) => {
switch (activity.object.type) {
// someone is undoing their follow of me
case "Follow": await db.deleteFollower(activity.actor); break
case "Follow": db.deleteFollower(activity.actor); break
}
}
const accept = async (activity:any) => {
switch (activity.object.type) {
// someone accepted my follow of them
case "Follow": await db.acceptFollowing(activity.actor); break
case "Follow": db.acceptFollowing(activity.actor); break
}
}
const reject = async (activity:any) => {
switch (activity.object.type) {
// someone rejected my follow of them
case "Follow": await db.deleteFollowing(activity.actor); break
case "Follow": db.deleteFollowing(activity.actor); break
}
}

View file

@ -1,13 +1,10 @@
import { DEFAULT_DOCUMENTS, STATIC_PATH } from "./env"
import admin from './admin'
import activitypub from "./activitypub"
import activitypub, { reqIsActivityPub } from "./activitypub"
import { fetchObject } from "./request"
import path from "path"
import { BunFile } from "bun"
import { rebuild } from "./db"
import { handle, webfinger } from "../actor"
import ActivityPubDB from './db'
rebuild()
const db = new ActivityPubDB()
const server = Bun.serve({
port: 3000,
@ -15,7 +12,7 @@ const server = Bun.serve({
const url = new URL(req.url)
// log the incoming request info
console.info(`${new Date().toISOString()} 📥 ${req.method} ${req.url}`)
console.info(`${new Date().toISOString()} 📥 ${req.method} ${reqIsActivityPub(req)?'[AP] ':''}${req.url}`)
// CORS route (for now, any domain has access)
if(req.method === "OPTIONS") {
@ -36,6 +33,7 @@ const server = Bun.serve({
// return the webfinger
return Response.json(webfinger, { headers: { 'content-type': 'application/jrd+json' }})
}
// Debugging route for fetching ActivityPub documents
else if(req.method === "GET" && url.pathname.startsWith("/fetch/")) {
const object_url = url.pathname.substring(7)
if(!object_url) return new Response("No url supplied", { status: 400})
@ -43,33 +41,9 @@ const server = Bun.serve({
return fetchObject(object_url)
}
return admin(req) || activitypub(req) || staticFile(req)
// admin and activitypub routes
return admin(req, db) || activitypub(req, db) || new Response("", { status: 404 })
},
});
const getDefaultDocument = async(base_path: string) => {
for(const d of DEFAULT_DOCUMENTS){
const filePath = path.join(base_path, d)
const file = Bun.file(filePath)
if(await file.exists()) return file
}
}
})
const staticFile = async (req:Request): Promise<Response> => {
try{
const url = new URL(req.url)
const filePath = path.join(STATIC_PATH, url.pathname)
let file:BunFile|undefined = Bun.file(filePath)
// if the file doesn't exist, attempt to get the default document for the path
if(!(await file.exists())) file = await getDefaultDocument(filePath)
if(file && await file.exists()) return new Response(file)
// if the file still doesn't exist, just return a 404
else return new Response("", { status: 404 })
}
catch(err) {
console.error(err)
return new Response("", { status: 404 })
}
}
console.log(`Listening on http://localhost:${server.port} ...`);
console.log(`Listening on http://localhost:${server.port} ...`)

View file

@ -1,12 +1,15 @@
import { idsFromValue } from "./activitypub"
import * as db from "./db"
import { fetchObject, send } from "./request"
import ACTOR from "../actor"
import ActivityPubDB from "./db"
export default async function outbox(activity:any):Promise<Response> {
let db:ActivityPubDB
export default async function outbox(activity:any, database:ActivityPubDB):Promise<Response> {
db = database
const date = new Date()
const id = `${date.getTime().toString(16)}`
console.log('outbox', id, activity)
const activity_id = `${date.getTime().toString(32)}`
console.log('outbox', activity_id, activity)
// https://www.w3.org/TR/activitypub/#object-without-create
if(!activity.actor && !(activity.object || activity.target || activity.result || activity.origin || activity.instrument)) {
@ -25,7 +28,7 @@ export default async function outbox(activity:any):Promise<Response> {
if(audience) activity.audience = audience
}
activity.id = `${ACTOR.url}/outbox/${id}`
activity.id = `${ACTOR.url}/outbox/${activity_id}`
if(!activity.published) activity.published = date.toISOString()
if(activity.type === 'Create' && activity.object && Object(activity.object) === activity.object) {
@ -44,22 +47,22 @@ export default async function outbox(activity:any):Promise<Response> {
// now that has been taken care of, it's time to update our local data, depending on the contents of the activity
switch(activity.type) {
case "Accept": await accept(activity, id); break;
case "Follow": await follow(activity, id); break;
case "Like": await like(activity, id); break;
case "Dislike": await dislike(activity, id); break;
case "Annouce": await announce(activity, id); break;
case "Create": await create(activity, id); break;
case "Accept": await accept(activity, activity_id); break;
case "Follow": await follow(activity, activity_id); break;
case "Like": await like(activity, activity_id); break;
case "Dislike": await dislike(activity, activity_id); break;
case "Annouce": await announce(activity, activity_id); break;
case "Create": await create(activity, activity_id); break;
case "Undo": await undo(activity); break;
case "Delete": await deletePost(activity); break;
// TODO: case "Anncounce": return await share(activity)
}
// save the activity data for the outbox
await db.createOutboxActivity(activity, id)
db.createOutboxActivity(activity_id, activity)
// send to the appropriate recipients
finalRecipientList.forEach((to) => {
if (to.startsWith(ACTOR.url + "/followers")) db.listFollowers().then(followers => followers.forEach(f => send(f.actor, activity)))
if (to.startsWith(ACTOR.url + "/followers")) db.listFollowers()?.forEach(f => send(f.id, activity))
else if (to === "https://www.w3.org/ns/activitystreams#Public") return // there's nothing to "send" to here
else if (to) send(to, activity)
})
@ -67,57 +70,59 @@ export default async function outbox(activity:any):Promise<Response> {
return new Response("", { status: 201, headers: { location: activity.id } })
}
async function create(activity:any, id:string) {
activity.object.id = activity.object.url = `${ACTOR.url}/posts/${id}`
await db.createPost(activity.object, id)
async function create(activity:any, activity_id:string) {
activity.object.id = activity.object.url = `${ACTOR.url}/posts/${activity_id}`
db.createPost(activity_id, activity.object)
return true
}
async function accept(activity:any, id:string) {
async function accept(activity:any, activity_id:string) {
return true
}
async function follow(activity:any, id:string) {
await db.createFollowing(activity.object , id)
async function follow(activity:any, activity_id:string) {
idsFromValue(activity.object).forEach(id => {
db.createFollowing(activity_id, id, activity.published)
});
return true
}
async function like(activity:any, id:string) {
async function like(activity:any, activity_id:string) {
if(typeof activity.object === 'string'){
await db.createLiked(activity.object, id)
activity.object = await fetchObject(activity.object)
db.createLiked(activity_id, activity.object, activity.published || new Date())
activity.object = fetchObject(activity.object)
}
else {
const liked = await idsFromValue(activity.object)
liked.forEach(l => db.createLiked(l, id))
const liked = idsFromValue(activity.object)
liked.forEach(l => db.createLiked(activity_id, l, activity.published || new Date()))
}
await db.createPost(activity, id)
db.createPost(activity_id, activity)
return true
}
async function dislike(activity:any, id:string) {
async function dislike(activity:any, activity_id:string) {
if(typeof activity.object === 'string'){
await db.createDisliked(activity.object, id)
db.createDisliked(activity_id, activity.object, activity.published || new Date())
activity.object = await fetchObject(activity.object)
}
else {
const disliked = await idsFromValue(activity.object)
disliked.forEach(l => db.createDisliked(l, id))
disliked.forEach(l => db.createDisliked(activity_id, l, activity.published || new Date()))
}
await db.createPost(activity, id)
db.createPost(activity_id, activity)
return true
}
async function announce(activity:any, id:string) {
async function announce(activity:any, activity_id:string) {
if(typeof activity.object === 'string'){
await db.createShared(activity.object, id)
db.createShared(activity_id, activity.object, activity.published || new Date())
activity.object = await fetchObject(activity.object)
}
else {
const shared = await idsFromValue(activity.object)
shared.forEach(l => db.createShared(l, id))
shared.forEach(l => db.createShared(activity_id, l, activity.published || new Date()))
}
await db.createPost(activity, id)
db.createPost(activity_id, activity)
return true
}
@ -136,17 +141,17 @@ async function announce(activity:any, id:string) {
async function undo(activity:any) {
const id = await idsFromValue(activity.object).at(0)
if (!id) return true
const match = id.match(/\/([0-9a-f]+)\/?$/)
const local_id = match ? match[1] : id
console.log('undo', local_id)
const match = id.match(/\/([0-9a-z]+)\/?$/)
const activity_id = match ? match[1] : id
console.log('undo', activity_id)
try{
const existing = await db.getOutboxActivity(local_id)
const existing = db.getOutboxActivity(activity_id)
switch(activity.object.type) {
case "Follow": await db.deleteFollowing(existing.object); break;
case "Like": idsFromValue(existing.object).forEach(async id => await db.deleteLiked(id)); await db.deletePost(local_id); break;
case "Dislike": idsFromValue(existing.object).forEach(async id => await db.deleteDisliked(id)); await db.deletePost(local_id); break;
case "Announce": idsFromValue(existing.object).forEach(async id => await db.deleteShared(id)); await db.deletePost(local_id); break;
case "Follow": idsFromValue(existing?.object).forEach(async id => db.deleteFollowing(id)); break;
case "Like": idsFromValue(existing?.object).forEach(async id => db.deleteLiked(id)); db.deletePost(activity_id); break;
case "Dislike": idsFromValue(existing?.object).forEach(async id => db.deleteDisliked(id)); db.deletePost(activity_id); break;
case "Announce": idsFromValue(existing?.object).forEach(async id => db.deleteShared(id)); db.deletePost(activity_id); break;
}
}
@ -160,8 +165,8 @@ async function undo(activity:any) {
async function deletePost(activity:any) {
const id = await idsFromValue(activity.object).at(0)
if(!id) return false
const post = await db.getPostByURL(id)
const post = db.getPostByURL(id)
if(!post) return false
await db.deletePost(post.local_id)
db.deletePost(post.activity_id)
return true
}