From 3cf3db8db268115a55a3ebd8dc7ce0a5602b3a31 Mon Sep 17 00:00:00 2001 From: haskal Date: Sat, 2 May 2020 04:17:22 -0400 Subject: [PATCH] Create basic settings and build webfinger --- NOTES.md | 1 + private/rules.rkt | 58 +++++++++++++++++++++++++++++++++++------------ scripts/init | 20 ++++++++++------ 3 files changed, 57 insertions(+), 22 deletions(-) diff --git a/NOTES.md b/NOTES.md index fc38c53..eb7cdcc 100644 --- a/NOTES.md +++ b/NOTES.md @@ -3,6 +3,7 @@ - crypto-lib - markdown - sass (submodule, needed modifications) +- http ## Disk structure diff --git a/private/rules.rkt b/private/rules.rkt index 303505c..3d713b3 100644 --- a/private/rules.rkt +++ b/private/rules.rkt @@ -3,8 +3,14 @@ ;; static generation rules (require json + net/url-string "compile.rkt") +(define (get-pref prefs what) + (match prefs + [(list _ ... (list (? (curry symbol=? what)) value) _ ...) value] + [_ (error "no such pref" prefs what)])) + (define ACTOR-CONTEXT (list "https://www.w3.org/ns/activitystreams" "https://w3id.org/security/v1" @@ -19,15 +25,20 @@ 'featured "toot:featured"))) (define compile-index-json - (rule '("db/actorkey.pub") "public/index.json" + (rule '("db/actorkey.pub" "src/instance.rktd" "src/bio.md") "public/index.json" (lambda (in out) (define key (port->string (hash-ref in "db/actorkey.pub"))) + (define prefs (read (hash-ref in "src/instance.rktd"))) + (define instance-url (get-pref prefs 'shonks:instance-url)) + (define display-name (get-pref prefs 'shonks:display-name)) + (define name (get-pref prefs 'shonks:name)) + (define bio (port->string (hash-ref in "src/bio.md"))) (define actor (hash '@context ACTOR-CONTEXT 'Type "Person" - 'id "https://example.tld/" - 'name "haskal" - 'preferredUsername "haskal" + 'id instance-url + 'name display-name + 'preferredUsername name 'icon (hash 'type "Image" 'url "something" 'sensitive #f) @@ -35,29 +46,46 @@ 'url "something" 'sensitive #f) 'tag (list (hash 'type "Hashtag" - 'href "https://example.tld/tags/blahaj" + 'href (string-append instance-url "tags/blahaj") 'name "#blahaj")) 'manuallyApprovesFollowers #f - 'summary "summary lol" + 'summary bio 'attachment (list (hash 'type "PropertyValue" 'name "pronouns" 'value "they/them")) - 'url "https://example.tld/" - 'inbox "https://example.tld/inbox" - 'sharedInbox "https://example.tld/inbox" - 'endpoints (hash 'sharedInbox "https://example.tld/inbox") - 'outbox "https://example.tld/outbox" + 'url instance-url + 'inbox (string-append instance-url "inbox") + 'sharedInbox (string-append instance-url "inbox") + 'endpoints (hash 'sharedInbox (string-append instance-url "inbox")) + 'outbox (string-append instance-url "outbox") 'following 'null - 'followers "https://example.tld/followers" + 'followers (string-append instance-url "followers") 'liked 'null - 'publicKey (hash 'id "https://example.tld/#main-key" + 'publicKey (hash 'id (string-append instance-url "#main-key") 'type "Key" - 'owner "https://example.tld/" + 'owner instance-url 'publicKeyPem key))) (write-json actor out)))) +(define compile-webfinger + (rule '("src/instance.rktd") "public/webfinger.json" + (lambda (in out) + (define prefs (read (hash-ref in "src/instance.rktd"))) + (define instance-url (get-pref prefs 'shonks:instance-url)) + (define host (url-host (string->url instance-url))) + (define name (get-pref prefs 'shonks:name)) + (define webfinger + (hash + 'subject (format "acct:~a@~a" name host) + 'links (list (hash + 'rel "self" + 'type "application/activity+json" + 'href instance-url)))) + (write-json webfinger out)))) + (define compiler-rules - (set compile-index-json)) + (set compile-index-json + compile-webfinger)) (define ops (generate-operations compiler-rules)) (for ([op (in-list ops)]) diff --git a/scripts/init b/scripts/init index 4f49ece..b2146da 100755 --- a/scripts/init +++ b/scripts/init @@ -43,10 +43,14 @@ ; src and public (make-directory "src") -(put-preferences '(shonks:instance-url shonks:display-name shonks:name) - '("https://myinstance.tld/" "Display Name(tm)" "username") - #f - "src/instance.rktd") +;; TODO +;; don't rly like preferences, so this is custom because i said so :P +(define DEFAULT-PREFS + '((shonks:instance-url "https://myinstance.tld/") + (shonks:display-name "Display Name(tm)") + (shonks:name "username"))) +(with-output-to-file "src/instance.rktd" + (lambda () (pretty-write DEFAULT-PREFS) (void))) (with-output-to-file "src/bio.md" (lambda () (write-string "this section left intentionally blank") @@ -55,11 +59,13 @@ (make-directory "public") (make-directory "public/posts") +(make-directory "public/tags") + +(make-directory "nginx") ; task queue -(define c (sqlite3-connect #:database "taskq.sqlite3" #:mode 'create)) -(query-exec c "create table taskq (id blob(16) primary key, task blob, state integer)") -(disconnect c) +(require "../private/taskq.rkt") +(taskq-close (make-taskq "taskq.sqlite3" #t)) (with-output-to-file "version" (lambda () (write-string "1.0") (void)))