diff options
author | FChannel <> | 2021-06-06 03:01:19 -0700 |
---|---|---|
committer | FChannel <> | 2021-06-06 03:01:19 -0700 |
commit | 3a4aacb9c49b7d2730b7ec46205a43c5095456d6 (patch) | |
tree | 90bbd5b66402131d7082334bcc6271c6360f27fb | |
parent | 8f5289cf17c66c10285e5b30904523d51fd23de9 (diff) |
better handling of follow when instance is offline
-rw-r--r-- | main.go | 45 | ||||
-rw-r--r-- | outboxPost.go | 6 |
2 files changed, 15 insertions, 36 deletions
@@ -452,7 +452,7 @@ func main() { } enc, _ := json.Marshal(followActivity) - + req, err := http.NewRequest("POST", actor.Outbox, bytes.NewBuffer(enc)) CheckError(err, "error with follow req") @@ -466,13 +466,14 @@ func main() { req.Header.Set("Content-Type", activitystreams) - _, err = http.DefaultClient.Do(req) - - CheckError(err, "error with add board follow resp") - - FollowingBoards = GetActorFollowingDB(db, Domain) + resp, err := http.DefaultClient.Do(req) - Boards = GetBoardCollection(db) + if err != nil && resp.StatusCode != 200 { + fmt.Println("error with add board follow resp") + } else { + FollowingBoards = GetActorFollowingDB(db, Domain) + Boards = GetBoardCollection(db) + } var redirect string if(actor.Name != "main") { @@ -1550,36 +1551,14 @@ func GetActorCollection(collection string) Collection { } func IsValidActor(id string) (Actor, bool) { - var respCollection Actor - req, err := http.NewRequest("GET", id, nil) - - CheckError(err, "error with valid actor request") - - req.Header.Set("Accept", activitystreams) - - resp, err := http.DefaultClient.Do(req) - CheckError(err, "error with valid actor response") + actor := FingerActor(id) - defer resp.Body.Close() - - if resp.StatusCode == 403 { - return respCollection, false; - } - - body, _ := ioutil.ReadAll(resp.Body) - - err = json.Unmarshal(body, &respCollection) - - if err != nil { - panic(err) - } - - if respCollection.Id != "" && respCollection.Inbox != "" && respCollection.Outbox != "" { - return respCollection, true; + if actor.Id != "" { + return actor, true; } - return respCollection, false; + return actor, false; } func IsActivityLocal(db *sql.DB, activity Activity) bool { diff --git a/outboxPost.go b/outboxPost.go index edbea65..2a06211 100644 --- a/outboxPost.go +++ b/outboxPost.go @@ -92,8 +92,8 @@ func ParseOutboxRequest(w http.ResponseWriter, r *http.Request, db *sql.DB) { w.Write([]byte("")) return } - - _, validActor = IsValidActor(activity.Object.Actor.Id) + + validActor = (FingerActor(activity.Object.Actor.Id).Id != "") validLocalActor = (activity.Actor.Id == actor.Id) var verify Verify @@ -117,7 +117,7 @@ func ParseOutboxRequest(w http.ResponseWriter, r *http.Request, db *sql.DB) { } var rActivity Activity - if validActor && validLocalActor && code == auth[1] || verify.Board == Domain { + if validActor && validLocalActor && code == auth[1] { rActivity = AcceptFollow(activity) SetActorFollowingDB(db, rActivity) MakeActivityRequest(db, activity) |