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)
| 19 | // 3. Has a "non internal" version that is documented, but isn't this request. |
| 20 | |
| 21 | func 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 | } |
nothing calls this directly
no test coverage detected