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/comm.go | |
parent | 36a41e03c59624a2b4a7eb174e9a003e288a1d7d (diff) |
db package now compiles without error for now
Diffstat (limited to 'webfinger/comm.go')
-rw-r--r-- | webfinger/comm.go | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/webfinger/comm.go b/webfinger/comm.go new file mode 100644 index 0000000..dd25cb4 --- /dev/null +++ b/webfinger/comm.go @@ -0,0 +1,70 @@ +package webfinger + +import ( + "encoding/json" + "errors" + "io/ioutil" + "net/http" + + "github.com/FChannel0/FChannel-Server/activitypub" + "github.com/FChannel0/FChannel-Server/config" + "github.com/FChannel0/FChannel-Server/util" +) + +// TODO: All of these functions in this file I don't know where to place so they'll remain here until I find a better place for them. + +func GetActorCollection(collection string) (activitypub.Collection, error) { + var nCollection activitypub.Collection + + if collection == "" { + return nCollection, errors.New("invalid collection") + } + + req, err := http.NewRequest("GET", collection, nil) + if err != nil { + return nCollection, err + } + + req.Header.Set("Accept", config.ActivityStreams) + + resp, err := util.RouteProxy(req) + if err != nil { + return nCollection, err + } + + defer resp.Body.Close() + + if resp.StatusCode == 200 { + body, _ := ioutil.ReadAll(resp.Body) + + if len(body) > 0 { + if err := json.Unmarshal(body, &nCollection); err != nil { + return nCollection, err + } + } + } + + return nCollection, nil +} + +func GetCollectionFromReq(path string) (activitypub.Collection, error) { + var respCollection activitypub.Collection + + req, err := http.NewRequest("GET", path, nil) + if err != nil { + return respCollection, err + } + + req.Header.Set("Accept", config.ActivityStreams) + + resp, err := util.RouteProxy(req) + if err != nil { + return respCollection, err + } + defer resp.Body.Close() + + body, _ := ioutil.ReadAll(resp.Body) + + err = json.Unmarshal(body, &respCollection) + return respCollection, err +} |