Skip to content

Commit ba0ab25

Browse files
committed
feat: media timeline
1 parent dc532b3 commit ba0ab25

3 files changed

Lines changed: 54 additions & 0 deletions

File tree

bluesky/blueskyapi.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -717,6 +717,39 @@ func GetUserTimeline(pds string, token string, context string, actor string, lim
717717
return nil, &feeds
718718
}
719719

720+
func GetMediaTimeline(pds string, token string, context string, actor string, limit int) (error, *Timeline) {
721+
apiURL := pds + "/xrpc/app.bsky.feed.getAuthorFeed?actor=" + url.QueryEscape(actor) + "&limit=" + fmt.Sprintf("%d", limit) + "&filter=posts_with_media"
722+
if context != "" {
723+
apiURL = pds + "/xrpc/app.bsky.feed.getAuthorFeed?actor=" + url.QueryEscape(actor) + "&cursor=" + context + "&limit=" + fmt.Sprintf("%d", limit) + "&filter=posts_with_media"
724+
}
725+
726+
resp, err := SendRequest(&token, http.MethodGet, apiURL, nil)
727+
if err != nil {
728+
return err, nil
729+
}
730+
defer resp.Body.Close()
731+
732+
// // Print the response body for debugging
733+
// bodyBytes, _ := io.ReadAll(resp.Body)
734+
// bodyString := string(bodyBytes)
735+
// fmt.Println("Response Body:", bodyString)
736+
737+
if resp.StatusCode != http.StatusOK {
738+
bodyBytes, _ := io.ReadAll(resp.Body)
739+
bodyString := string(bodyBytes)
740+
fmt.Println("Response Status:", resp.StatusCode)
741+
fmt.Println("Response Body:", bodyString)
742+
return errors.New("failed to fetch timeline"), nil
743+
}
744+
745+
feeds := Timeline{}
746+
if err := json.NewDecoder(resp.Body).Decode(&feeds); err != nil {
747+
return err, nil
748+
}
749+
750+
return nil, &feeds
751+
}
752+
720753
func GetPost(pds string, token string, uri string, depth int, parentHeight int) (error, *ThreadRoot) {
721754
// Example URL at://did:plc:dqibjxtqfn6hydazpetzr2w4/app.bsky.feed.post/3lchbospvbc2j
722755

twitterv1/post_viewing.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,26 @@ func user_timeline(c *fiber.Ctx) error {
4545
return convert_timeline(c, actor, blueskyapi.GetUserTimeline)
4646
}
4747

48+
func media_timeline(c *fiber.Ctx) error {
49+
actor := c.Query("screen_name")
50+
if actor == "" {
51+
actor = c.Query("user_id")
52+
if actor == "" {
53+
return c.Status(fiber.StatusBadRequest).SendString("No user provided")
54+
}
55+
actorInt, err := strconv.ParseInt(actor, 10, 64)
56+
if err != nil {
57+
return c.Status(fiber.StatusBadRequest).SendString("Invalid user_id provided")
58+
}
59+
actorPtr, err := bridge.TwitterIDToBlueSky(&actorInt)
60+
if err != nil {
61+
return c.Status(fiber.StatusBadRequest).SendString("Invalid user_id provided")
62+
}
63+
actor = *actorPtr
64+
}
65+
return convert_timeline(c, actor, blueskyapi.GetMediaTimeline)
66+
}
67+
4868
func likes_timeline(c *fiber.Ctx) error {
4969
// We shall pretend that the only thing it can be is a user id. TODO: maybe rectify this later
5070
actor := c.Params("id")

twitterv1/twitterv1.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ func InitServer(config *config.Config) {
8484
// Posts
8585
app.Get("/1/statuses/home_timeline.:filetype", home_timeline)
8686
app.Get("/1/statuses/user_timeline.:filetype", user_timeline)
87+
app.Get("/1/statuses/media_timeline.:filetype", media_timeline)
8788
app.Get("/1/statuses/show/:id.:filetype", GetStatusFromId)
8889
app.Get("/i/statuses/:id/activity/summary.:filetype", TweetInfo)
8990
app.Get("/1/related_results/show/:id.:filetype", RelatedResults)

0 commit comments

Comments
 (0)