reduce ambitions

This commit is contained in:
nebula 2025-04-20 23:38:06 +00:00
parent c34e5b5124
commit 014f1cd222
2 changed files with 18 additions and 58 deletions

View File

@ -1,30 +1,15 @@
**note**: this readme has been extensively edited since i initially posted it on tilde.town. there are no longer any ambitions to replace bbj with this project
# bink
serverless forum and microblogging for tilde.town
serverless microblogging for tilde.town
# object logic
each system user that chooses to use bink will have a folder in their home directory called `.bink/`, which will be populated by items named after the epoch-nanoseconds time of creation. the contents of each item are json formatted. the following structure defines what a post is:
each system user that chooses to use bink will have a folder in their home directory called `.bink/`, which will be populated by items named after the epoch-nanoseconds time of creation. the contents of each item are plaintext, and that is the post.
```
{
"body": "this is the body of the post, as a string",
"forum": false boolean OR "the title of the forum thread"
}
```
from the path where the object is stored, ex. `/home/nebula/.bink/1745182221128478782`, the user who posted the item and the time it was produced can be inferred. each post object therefore has 4 pieces of data: the `body`, the `forum` indicator (more on that in next paragraph), the exact time the post was produced, and the user who posted it. the client will iterate over system files by using the `/home/**/.bink/*` glob, collecting all of the user objects without using a central server like `bbj`
when `object.forum` is false, the `body` of the the object is used to make a microblogging post by the user. if `object.forum` is a string, this is the title of the thread this post belongs to. there is no additional data specififying if this is the first forum post or what order it came in the thread, as this information can be inferred from the object filename
from the path where the object is stored, ex. `/home/nebula/.bink/1745182221128478782`, the user who posted the item and the time it was produced can be inferred. each post object therefore has 3 pieces of data: the post body, the exact time the post was produced, and the user who posted it. the client will iterate over system files by using the `/home/**/.bink/*` glob, collecting all of the user objects without using a central server like `bbj`
## potential flaws
* users who choose to delete or tamper with the contents of their `~/.bink/` directory will cause some confusion in threads, where their posts are missing, which would be especially odd if the first post were to vanish. the program would therefore show the `n` posts which came after the original post, losing important context
* scales poorly: client will need to implement some sort of pagination logic if many thousands of posts exist, or the program will be very slow. every file on the system must be iterated with each subsequent update. in 10 years of use, this serverless approach may become cumbersome.
## upsides over bbj
* there is no server to maintain or have potential issues with
* no potential for centralized data corruption
* zero passwords or necessary authentication, all user interaction is based on the logged in user and the permissions they do/dont have to write in the chosen directory
* ability to edit your own posts and own your data
* scales poorly: client will need to implement some sort of pagination logic if many thousands of posts exist, or the program will be very slow. every file on the system must be iterated with each subsequent update. in 10 years of use, this serverless approach may become cumbersome.

49
bink.py
View File

@ -2,11 +2,9 @@ import json
from glob import glob
from time import time_ns
import os
from collections import OrderedDict
from sys import argv
home = os.path.expanduser("~/.bink")
max_title_length = 120
max_body_length = 64_000
try:
@ -14,9 +12,9 @@ try:
except FileExistsError:
pass
def write_object(obj):
with open(f"{home}/{time_ns()}", "w") as f:
json.dump(obj, f, indent=2)
def create_post(body):
with open(f"{home}/{time_ns()}", "w", encoding="UTF-8") as f:
f.write(body)
def file_object(path):
split = path.split("/")
@ -24,49 +22,26 @@ def file_object(path):
# output: (999, "nebula", "/home/nebula/.bink/999")
return (int(split[-1]), split[2], path)
def create_forum_post(title, body):
thread = {
"body": body[:max_body_length],
"forum": title[:max_title_length]
}
write_object(thread)
def create_blog_post(body):
blog = {
"body": body,
"forum": False
}
write_object(blog)
def generate_feed():
def generate_feed(before=None, count=50):
posts = [file_object(path) for path in glob("/home/**/.bink/*")]
if before:
posts = [post for post in posts if post[0] < before]
posts.sort(key=lambda x: x[0], reverse=True)
forums = OrderedDict()
blogs = []
for time, user, path in posts:
for time, user, path in posts[:count]:
# try:
with open(path, "r") as f:
data = json.load(f)
with open(path, "r", encoding="UTF-8") as f:
body = f.read()
# except
obj = {
"user": user,
"time": time,
"body": data["body"][:max_body_length],
"forum": data["forum"]
"body": body[:max_body_length],
}
if obj["forum"]:
obj["forum"] = obj["forum"][:max_title_length]
try:
forums[data["forum"]].insert(0, obj)
except KeyError:
forums[data["forum"]] = [obj]
else:
blogs.insert(0, obj)
return (blogs, forums)
blogs.append(obj)
return blogs
if "dump" in argv:
with open("/dev/stdout", "w") as f:
json.dump(generate_feed(), f)
exit()
import urwid