diff options
author | FChannel <> | 2022-05-02 12:07:00 -0700 |
---|---|---|
committer | FChannel <> | 2022-06-19 12:53:29 -0700 |
commit | 733f911fadc872933481bcbe087d519ce00372df (patch) | |
tree | 54788da4f730bd11934401c1eca48a3c87f08027 /routes/webfinger.go | |
parent | e80fe14f7985f9e85bfb9582926acd7891455786 (diff) |
cleaned up main
Diffstat (limited to 'routes/webfinger.go')
-rw-r--r-- | routes/webfinger.go | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/routes/webfinger.go b/routes/webfinger.go new file mode 100644 index 0000000..221b7dc --- /dev/null +++ b/routes/webfinger.go @@ -0,0 +1,57 @@ +package routes + +import ( + "encoding/json" + "strings" + + "github.com/FChannel0/FChannel-Server/activitypub" + "github.com/FChannel0/FChannel-Server/config" + "github.com/FChannel0/FChannel-Server/webfinger" + "github.com/gofiber/fiber/v2" +) + +func Webfinger(c *fiber.Ctx) error { + acct := c.Query("resource") + + if len(acct) < 1 { + c.Status(fiber.StatusBadRequest) + return c.Send([]byte("resource needs a value")) + } + + acct = strings.Replace(acct, "acct:", "", -1) + + actorDomain := strings.Split(acct, "@") + + if len(actorDomain) < 2 { + c.Status(fiber.StatusBadRequest) + return c.Send([]byte("accpets only subject form of acct:board@instance")) + } + + if actorDomain[0] == "main" { + actorDomain[0] = "" + } else { + actorDomain[0] = "/" + actorDomain[0] + } + + if res, err := activitypub.IsActorLocal(config.TP + "" + actorDomain[1] + "" + actorDomain[0]); err == nil && !res { + c.Status(fiber.StatusBadRequest) + return c.Send([]byte("actor not local")) + } else if err != nil { + return err + } + + var finger webfinger.Webfinger + var link webfinger.WebfingerLink + + finger.Subject = "acct:" + actorDomain[0] + "@" + actorDomain[1] + link.Rel = "self" + link.Type = "application/activity+json" + link.Href = config.TP + "" + actorDomain[1] + "" + actorDomain[0] + + finger.Links = append(finger.Links, link) + + enc, _ := json.Marshal(finger) + + c.Set("Content-Type", config.ActivityStreams) + return c.Send(enc) +} |