(app *App, actorIRI string)
| 1000 | } |
| 1001 | |
| 1002 | func getActor(app *App, actorIRI string) (*activitystreams.Person, *RemoteUser, error) { |
| 1003 | log.Info("Fetching actor %s locally", actorIRI) |
| 1004 | actor := &activitystreams.Person{} |
| 1005 | remoteUser, err := getRemoteUser(app, actorIRI) |
| 1006 | if err != nil { |
| 1007 | if iErr, ok := err.(impart.HTTPError); ok { |
| 1008 | if iErr.Status == http.StatusNotFound { |
| 1009 | // Fetch remote actor |
| 1010 | log.Info("Not found; fetching actor %s remotely", actorIRI) |
| 1011 | actorResp, err := resolveIRI(app.cfg.App.Host, actorIRI) |
| 1012 | if err != nil { |
| 1013 | log.Error("Unable to get base actor! %v", err) |
| 1014 | return nil, nil, impart.HTTPError{http.StatusInternalServerError, "Couldn't fetch actor."} |
| 1015 | } |
| 1016 | if err := unmarshalActor(actorResp, actor); err != nil { |
| 1017 | log.Error("Unable to unmarshal base actor! %v", err) |
| 1018 | return nil, nil, impart.HTTPError{http.StatusInternalServerError, "Couldn't parse actor."} |
| 1019 | } |
| 1020 | baseActor := &activitystreams.Person{} |
| 1021 | if err := unmarshalActor(actorResp, baseActor); err != nil { |
| 1022 | log.Error("Unable to unmarshal actual actor! %v", err) |
| 1023 | return nil, nil, impart.HTTPError{http.StatusInternalServerError, "Couldn't parse actual actor."} |
| 1024 | } |
| 1025 | // Fetch the actual actor using the owner field from the publicKey object |
| 1026 | actualActorResp, err := resolveIRI(app.cfg.App.Host, baseActor.PublicKey.Owner) |
| 1027 | if err != nil { |
| 1028 | log.Error("Unable to get actual actor! %v", err) |
| 1029 | return nil, nil, impart.HTTPError{http.StatusInternalServerError, "Couldn't fetch actual actor."} |
| 1030 | } |
| 1031 | if err := unmarshalActor(actualActorResp, actor); err != nil { |
| 1032 | log.Error("Unable to unmarshal actual actor! %v", err) |
| 1033 | return nil, nil, impart.HTTPError{http.StatusInternalServerError, "Couldn't parse actual actor."} |
| 1034 | } |
| 1035 | } else { |
| 1036 | return nil, nil, err |
| 1037 | } |
| 1038 | } else { |
| 1039 | return nil, nil, err |
| 1040 | } |
| 1041 | } else { |
| 1042 | actor = remoteUser.AsPerson() |
| 1043 | } |
| 1044 | return actor, remoteUser, nil |
| 1045 | } |
| 1046 | |
| 1047 | func GetProfileURLFromHandle(app *App, handle string) (string, error) { |
| 1048 | handle = strings.TrimLeft(handle, "@") |
no test coverage detected