(username string, host, requestHost string, r []webfinger.Rel)
| 30 | var wfUserNotFoundErr = impart.HTTPError{http.StatusNotFound, "User not found."} |
| 31 | |
| 32 | func (wfr wfResolver) FindUser(username string, host, requestHost string, r []webfinger.Rel) (*webfinger.Resource, error) { |
| 33 | var c *Collection |
| 34 | var err error |
| 35 | if username == host { |
| 36 | c = instanceColl |
| 37 | } else if wfr.cfg.App.SingleUser { |
| 38 | c, err = wfr.db.GetCollectionByID(1) |
| 39 | } else { |
| 40 | c, err = wfr.db.GetCollection(username) |
| 41 | } |
| 42 | if err != nil { |
| 43 | log.Error("Unable to get blog: %v", err) |
| 44 | return nil, err |
| 45 | } |
| 46 | c.hostName = wfr.cfg.App.Host |
| 47 | |
| 48 | if !c.IsInstanceColl() { |
| 49 | silenced, err := wfr.db.IsUserSilenced(c.OwnerID) |
| 50 | if err != nil { |
| 51 | log.Error("webfinger find user: check is silenced: %v", err) |
| 52 | return nil, err |
| 53 | } |
| 54 | if silenced { |
| 55 | return nil, wfUserNotFoundErr |
| 56 | } |
| 57 | } |
| 58 | if wfr.cfg.App.SingleUser { |
| 59 | // Ensure handle matches user-chosen one on single-user blogs |
| 60 | if username != c.Alias { |
| 61 | log.Info("Username '%s' is not handle '%s'", username, c.Alias) |
| 62 | return nil, wfUserNotFoundErr |
| 63 | } |
| 64 | } |
| 65 | // Only return information if site has federation enabled. |
| 66 | // TODO: enable two levels of federation? Unlisted or Public on timelines? |
| 67 | if !wfr.cfg.App.Federation { |
| 68 | return nil, wfUserNotFoundErr |
| 69 | } |
| 70 | |
| 71 | res := webfinger.Resource{ |
| 72 | Subject: "acct:" + username + "@" + host, |
| 73 | Aliases: []string{ |
| 74 | c.CanonicalURL(), |
| 75 | c.FederatedAccount(), |
| 76 | }, |
| 77 | Links: []webfinger.Link{ |
| 78 | { |
| 79 | HRef: c.CanonicalURL(), |
| 80 | Type: "text/html", |
| 81 | Rel: "https://webfinger.net/rel/profile-page", |
| 82 | }, |
| 83 | { |
| 84 | HRef: c.FederatedAccount(), |
| 85 | Type: "application/activity+json", |
| 86 | Rel: "self", |
| 87 | }, |
| 88 | }, |
| 89 | } |
nothing calls this directly
no test coverage detected