🔊 Add some logging in fediverse fetching

This commit is contained in:
LittleSheep 2025-03-12 00:43:17 +08:00
parent 8a062bf07a
commit 11322370b1
2 changed files with 5 additions and 5 deletions

View File

@ -33,20 +33,19 @@ func ReadFriendConfig() {
}
func FetchFediversePost(cfg FediverseFriendConfig) ([]models.FediversePost, error) {
var posts []models.FediversePost
switch cfg.Type {
case "mastodon":
data, err := mastodon.FetchTimeline(cfg.URL, cfg.BatchSize)
if err != nil {
return nil, err
}
posts = lo.Map(data, func(item mastodon.MastodonPost, _ int) models.FediversePost {
posts := lo.Map(data, func(item mastodon.MastodonPost, _ int) models.FediversePost {
return item.ToFediversePost()
})
return posts, nil
default:
return nil, fmt.Errorf("unsupported fediverse service: %s", cfg.Type)
}
return posts, nil
}
func FetchFediverseTimedTask() {
@ -63,6 +62,7 @@ func FetchFediverseTimedTask() {
if err != nil {
log.Error().Err(err).Str("id", friend.ID).Str("url", friend.URL).Msg("Failed to fetch fediverse friend timelime...")
}
log.Info().Str("id", friend.ID).Str("url", friend.URL).Int("count", len(posts)).Msg("Fetched fediverse friend timeline...")
totalPosts = append(totalPosts, posts...)
}

View File

@ -1,7 +1,6 @@
package mastodon
import (
"encoding/json"
"fmt"
"net/http"
"strings"
@ -9,6 +8,7 @@ import (
"git.solsynth.dev/hypernet/interactive/pkg/internal/models"
"git.solsynth.dev/hypernet/nexus/pkg/nex/cruda"
jsoniter "github.com/json-iterator/go"
"github.com/samber/lo"
)
@ -64,7 +64,7 @@ func FetchTimeline(server string, limit int) ([]MastodonPost, error) {
defer resp.Body.Close()
var posts []MastodonPost
if err := json.NewDecoder(resp.Body).Decode(&posts); err != nil {
if err := jsoniter.NewDecoder(resp.Body).Decode(&posts); err != nil {
return nil, fmt.Errorf("failed to parse timeline JSON: %v", err)
}