blob: 221b7dcec97a1f5a1e38df167ea3cfeff6ab321e (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
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)
}
|