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

Function InternalSearch

twitterv1/discover.go:21–126  ·  view source on GitHub ↗

Searching, oh boy. This function contacts an internal API, which is: 1. Not documented 2. Too common of a function to find 3. Has a "non internal" version that is documented, but isn't this request.

(c *fiber.Ctx)

Source from the content-addressed store, hash-verified

19// 3. Has a "non internal" version that is documented, but isn't this request.
20
21func InternalSearch(c *fiber.Ctx) error {
22 // Thank you so much @Savefade for what this should repsond.
23 q := c.Query("q")
24 fmt.Println("Search query:", q)
25
26 _, pds, _, oauthToken, err := GetAuthFromReq(c)
27 if err != nil {
28 return MissingAuth(c, err)
29 }
30
31 // Pagination
32 max_id := c.Query("max_id")
33 var until *time.Time
34 if max_id != "" {
35 maxIDInt, err := strconv.ParseInt(max_id, 10, 64)
36 if err != nil {
37 return ReturnError(c, "An invalid max_id has been specified", 195, fiber.StatusBadRequest)
38 }
39 _, until, _, err = bridge.TwitterMsgIdToBluesky(&maxIDInt)
40 if err != nil {
41 return ReturnError(c, "An invalid max_id has been specified", 195, fiber.StatusBadRequest)
42 }
43 }
44
45 var since *time.Time
46 since_id := c.Query("since_id")
47 if since_id != "" {
48 sinceIDInt, err := strconv.ParseInt(since_id, 10, 64)
49 if err != nil {
50 return ReturnError(c, "An invalid since_id has been specified", 195, fiber.StatusBadRequest)
51 }
52 _, until, _, err = bridge.TwitterMsgIdToBluesky(&sinceIDInt)
53 if err != nil {
54 return ReturnError(c, "An invalid since_id has been specified", 195, fiber.StatusBadRequest)
55 }
56 }
57
58 bskySearch, err := blueskyapi.PostSearch(*pds, *oauthToken, q, since, until)
59
60 if err != nil {
61 fmt.Println("Error:", err)
62 return HandleBlueskyError(c, err.Error(), "app.bsky.feed.searchPosts", InternalSearch)
63 }
64
65 // Optimization: Get all users at once so we don't have to do it in chunks
66 var dids []string
67 for _, search := range bskySearch {
68 dids = append(dids, search.Author.DID)
69 }
70 blueskyapi.GetUsersInfo(*pds, *oauthToken, dids, false) // add to cache
71
72 replyUrls := []string{}
73
74 for _, search := range bskySearch {
75 if search.Record.Reply != nil {
76 replyUrls = append(replyUrls, search.Record.Reply.Parent.URI)
77 }
78 }

Callers

nothing calls this directly

Calls 7

TwitterMsgIdToBlueskyFunction · 0.92
GetAuthFromReqFunction · 0.85
MissingAuthFunction · 0.85
ReturnErrorFunction · 0.85
HandleBlueskyErrorFunction · 0.85
TranslatePostToTweetFunction · 0.85
EncodeAndSendFunction · 0.85

Tested by

no test coverage detected