MCPcopy Index your code
hub / github.com/Preloading/TwitterAPIBridge / UserSearch

Function UserSearch

twitterv1/connect.go:16–48  ·  view source on GitHub ↗
(c *fiber.Ctx)

Source from the content-addressed store, hash-verified

14)
15
16func UserSearch(c *fiber.Ctx) error {
17 searchQuery := c.Query("q")
18 _, pds, _, oauthToken, err := GetAuthFromReq(c)
19
20 if err != nil {
21 return MissingAuth(c, err)
22 }
23 // Search for users
24 bskyUsers, err := blueskyapi.UserSearch(*pds, *oauthToken, searchQuery)
25
26 if err != nil {
27 fmt.Println("Error:", err)
28 return HandleBlueskyError(c, err.Error(), "app.bsky.actor.searchActors", UserSearch)
29 }
30 // Get complete user info.
31 // We must do this as the search API only returns a subset of the user info, and twitter wants all of it.
32
33 // Extract the dids into a string array
34 var dids []string
35 for _, user := range bskyUsers {
36 dids = append(dids, user.DID)
37 }
38 if len(dids) == 0 {
39 return EncodeAndSend(c, []bridge.TwitterUser{})
40 }
41 users, err := blueskyapi.GetUsersInfo(*pds, *oauthToken, dids, false)
42 if err != nil {
43 fmt.Println("Error:", err)
44 return HandleBlueskyError(c, err.Error(), "app.bsky.actor.getProfiles", UserSearch)
45 }
46
47 return EncodeAndSend(c, users)
48}
49
50// Something interesting with this endpoint is that the twitter client requested:
51// /i/search/typeahead.json?count=2500&prefetch=true&result_type=users&send_error_codes=1

Callers

nothing calls this directly

Calls 4

GetAuthFromReqFunction · 0.85
MissingAuthFunction · 0.85
HandleBlueskyErrorFunction · 0.85
EncodeAndSendFunction · 0.85

Tested by

no test coverage detected