diff options
author | KushBlazingJudah <59340248+KushBlazingJudah@users.noreply.github.com> | 2021-11-02 15:06:42 -0300 |
---|---|---|
committer | FChannel <> | 2022-06-19 12:53:29 -0700 |
commit | d80afd8a49f552c5dc51d8346d40809298fef11f (patch) | |
tree | 549e0dac8fe0ed21f283c92d7cd6daf40f3941ac /webfinger/webfinger.go | |
parent | 36a41e03c59624a2b4a7eb174e9a003e288a1d7d (diff) |
db package now compiles without error for now
Diffstat (limited to 'webfinger/webfinger.go')
-rw-r--r-- | webfinger/webfinger.go | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/webfinger/webfinger.go b/webfinger/webfinger.go index ffe7c6d..9e8d67d 100644 --- a/webfinger/webfinger.go +++ b/webfinger/webfinger.go @@ -4,6 +4,7 @@ import ( "encoding/json" "io/ioutil" "net/http" + "regexp" "strings" "github.com/FChannel0/FChannel-Server/activitypub" @@ -143,3 +144,37 @@ func FingerRequest(actor string, instance string) (*http.Response, error) { return resp, nil } + +func CheckValidActivity(id string) (activitypub.Collection, bool, error) { + var respCollection activitypub.Collection + + re := regexp.MustCompile(`.+\.onion(.+)?`) + if re.MatchString(id) { + id = strings.Replace(id, "https", "http", 1) + } + + req, err := http.NewRequest("GET", id, nil) + if err != nil { + return respCollection, false, err + } + + req.Header.Set("Accept", config.ActivityStreams) + + resp, err := util.RouteProxy(req) + if err != nil { + return respCollection, false, err + } + defer resp.Body.Close() + + body, _ := ioutil.ReadAll(resp.Body) + + if err := json.Unmarshal(body, &respCollection); err != nil { + return respCollection, false, err + } + + if respCollection.AtContext.Context == "https://www.w3.org/ns/activitystreams" && respCollection.OrderedItems[0].Id != "" { + return respCollection, true, nil + } + + return respCollection, false, nil +} |