🐛 Allow masotdon fetch to decide to use trending or not

This commit is contained in:
LittleSheep 2025-03-14 23:07:56 +08:00
parent 5126855b1d
commit 78d9bb5fc2
2 changed files with 15 additions and 7 deletions
pkg/internal/services

@ -17,10 +17,10 @@ type FromFediversePost interface {
}
type FediverseFriendConfig struct {
ID string `json:"id"`
URL string `json:"url"`
Type string `json:"type"`
BatchSize int `json:"batch_size" toml:"batch_size"`
ID string `json:"id"`
URL string `json:"url"`
Type string `json:"type"`
Trending bool `json:"trending"`
}
var fediverseFriends []FediverseFriendConfig
@ -35,7 +35,7 @@ func ReadFriendConfig() {
func FetchFediversePost(cfg FediverseFriendConfig) ([]models.FediversePost, error) {
switch cfg.Type {
case "mastodon":
data, err := mastodon.FetchTimeline(cfg.URL, 50)
data, err := mastodon.FetchTimeline(cfg.URL, 50, cfg.Trending)
if err != nil {
return nil, err
}

@ -59,8 +59,16 @@ func (v MastodonPost) ToFediversePost() models.FediversePost {
}
}
func FetchTimeline(server string, limit int) ([]MastodonPost, error) {
url := fmt.Sprintf("%s/api/v1/trends/statuses?limit=%d", server, limit)
func FetchTimeline(server string, limit int, useTrend bool) ([]MastodonPost, error) {
url := fmt.Sprintf(
lo.Ternary(
useTrend,
"%s/api/v1/trends/statuses?limit=%d",
"%s/api/v1/timelines/public?limit=%s",
),
server,
limit,
)
log.Debug().Str("url", url).Msg("Fetching mastodon timeline...")
resp, err := http.Get(url)