aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFChannel <>2021-05-30 14:59:11 -0700
committerFChannel <>2021-05-30 14:59:11 -0700
commit614f50a7bacc878abcaccc9186673ab2958a717d (patch)
tree46b7fc5cb17370bf43a7ac96a2c2761a6984076a
parent6413dd0fa2b3a381d306069ad8d2dd766fe754ec (diff)
added webfinger discovery for boards
-rw-r--r--main.go42
-rw-r--r--webfinger.go12
2 files changed, 54 insertions, 0 deletions
diff --git a/main.go b/main.go
index 8405bc6..8d28e33 100644
--- a/main.go
+++ b/main.go
@@ -905,6 +905,48 @@ func main() {
w.Write([]byte(""))
})
+ http.HandleFunc("/.well-known/webfinger", func(w http.ResponseWriter, r *http.Request) {
+ acct := r.URL.Query()["resource"]
+
+ if(len(acct) < 1) {
+ w.WriteHeader(http.StatusBadRequest)
+ w.Write([]byte("resource needs a value"))
+ return
+ }
+
+ acct[0] = strings.Replace(acct[0], "acct:", "", -1)
+
+ actorDomain := strings.Split(acct[0], "@")
+
+ if(len(actorDomain) < 2) {
+ w.WriteHeader(http.StatusBadRequest)
+ w.Write([]byte("accpets only subject form of acct:board@instance"))
+ return
+ }
+
+ if !IsActorLocal(db, TP + "" + actorDomain[1] + "/" + actorDomain[0]) {
+ w.WriteHeader(http.StatusBadRequest)
+ w.Write([]byte("actor not local"))
+ return
+ }
+
+ var finger Webfinger
+ var link WebfingerLink
+
+ finger.Subject = "acct:" + actorDomain[0] + "@" + actorDomain[1]
+ link.Rel = "self"
+ link.Type = "application/activity+json"
+ link.Href = TP + "" + actorDomain[1] + "/" + actorDomain[0]
+
+ finger.Links = append(finger.Links, link)
+
+ enc, _ := json.Marshal(finger)
+
+ w.Header().Set("Content-Type", activitystreams)
+ w.Write(enc)
+
+ })
+
fmt.Println("Server for " + Domain + " running on port " + Port)
fmt.Println("Mod key: " + *Key)
diff --git a/webfinger.go b/webfinger.go
new file mode 100644
index 0000000..004bdca
--- /dev/null
+++ b/webfinger.go
@@ -0,0 +1,12 @@
+package main
+
+type Webfinger struct {
+ Subject string `json:"subject,omitempty"`
+ Links []WebfingerLink `json:"links,omitempty"`
+}
+
+type WebfingerLink struct {
+ Rel string `json:"rel,omitempty"`
+ Type string `json:"type,omitempty"`
+ Href string `json:"href,omitempty"`
+}