MCPcopy Create free account
hub / github.com/Preloading/TwitterAPIBridge / SearchAhead

Function SearchAhead

twitterv1/connect.go:57–141  ·  view source on GitHub ↗

Something interesting with this endpoint is that the twitter client requested: i/search/typeahead.json?count=2500&prefetch=true&result_type=users&send_error_codes=1 Is this trying to get the first 2500 users for speed reasons? Or is this for some inital search suggestions? It was sent on right after

(c *fiber.Ctx)

Source from the content-addressed store, hash-verified

55
56// https://web.archive.org/web/20220427214446/https://twitter.com/i/search/typeahead.json?count=20&filters=true&result_type=true&src=COMPOSE&q=firat_ber
57func SearchAhead(c *fiber.Ctx) error {
58 // for completed in time
59 start := time.Now()
60
61 if strings.Contains(c.Query("result_type"), "users") {
62 // unimplemented, so we'll return it blank.
63 return EncodeAndSend(c, bridge.SearchAhead{
64 NumberOfResults: 0,
65 Query: c.Query("q"),
66 CompletedIn: time.Since(start).Seconds(),
67 })
68 }
69
70 searchQuery := c.Query("q")
71 if searchQuery == "" {
72 return ReturnError(c, "Missing search query (or that we don't support prefetch right now)", 195, fiber.StatusBadRequest)
73 }
74
75 _, pds, _, oauthToken, err := GetAuthFromReq(c)
76
77 if err != nil {
78 return MissingAuth(c, err)
79 }
80
81 limit := c.Query("count")
82 if limit == "" {
83 limit = "10"
84 }
85 limitInt, err := strconv.Atoi(limit)
86 if err != nil {
87 return ReturnError(c, "An invalid post count was specified", 195, fiber.StatusBadRequest)
88 }
89
90 // Search for users
91 bskyUsers, err := blueskyapi.UserSearchAhead(*pds, *oauthToken, searchQuery, limitInt)
92
93 if err != nil {
94 fmt.Println("Error:", err)
95 return HandleBlueskyError(c, err.Error(), "app.bsky.actor.searchActorsTypeahead", SearchAhead)
96 }
97
98 if len(bskyUsers) == 0 {
99 return EncodeAndSend(c, bridge.SearchAhead{
100 NumberOfResults: 0,
101 Query: c.Query("q"),
102 CompletedIn: time.Since(start).Seconds(),
103 })
104 }
105
106 // Converting into a summarized version of the user
107 users := make([]bridge.SummarisedUser, len(bskyUsers))
108 for i, user := range bskyUsers {
109 userId := bridge.BlueSkyToTwitterID(user.DID)
110 pfp_url := configData.CdnURL + "/cdn/img/?url=" + url.QueryEscape(user.Avatar) + ":profile_bigger"
111 users[i] = bridge.SummarisedUser{
112 ID: *userId,
113 IDStr: strconv.FormatInt(*userId, 10),
114 ScreenName: user.Handle,

Callers

nothing calls this directly

Calls 6

BlueSkyToTwitterIDFunction · 0.92
EncodeAndSendFunction · 0.85
ReturnErrorFunction · 0.85
GetAuthFromReqFunction · 0.85
MissingAuthFunction · 0.85
HandleBlueskyErrorFunction · 0.85

Tested by

no test coverage detected