40 lines
979 B
Go
40 lines
979 B
Go
package e621
|
|
|
|
import (
|
|
"e621_to_neo4j/e621/models"
|
|
"fmt"
|
|
log "github.com/sirupsen/logrus"
|
|
)
|
|
|
|
// GetFavorites retrieves all favorites from the e621 API.
|
|
func (c *Client) GetFavorites(user models.E621User) ([]models.Post, error) {
|
|
page := 1
|
|
var allFavorites []models.Post
|
|
var URIPath string
|
|
|
|
for {
|
|
URIPath = fmt.Sprintf("favorites.json?user_id=%d&limit=%d&page=%d", user.ID, 320, page)
|
|
log.WithFields(log.Fields{
|
|
"id": user.ID,
|
|
"fav_page": page,
|
|
"uri": URIPath,
|
|
}).Debug("Requesting API for favorites")
|
|
favorite, err := ExecuteGetAPIRequest[models.PostResponseWrapper](c, URIPath)
|
|
if err != nil {
|
|
log.Printf(err.Error())
|
|
}
|
|
|
|
// Append the fetched posts to the result slice
|
|
allFavorites = append(allFavorites, favorite.Posts...)
|
|
|
|
// If no more posts are returned, return the accumulated favorites
|
|
if len(favorite.Posts) == 0 {
|
|
return allFavorites, nil
|
|
}
|
|
|
|
// Update the last post ID for the next page request
|
|
page += 1
|
|
|
|
}
|
|
}
|