newest.go 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. package core
  2. import (
  3. session "codeberg.org/vnpower/pixivfe/v2/core/config"
  4. http "codeberg.org/vnpower/pixivfe/v2/core/http"
  5. "github.com/goccy/go-json"
  6. "github.com/gofiber/fiber/v2"
  7. )
  8. type ArtworkBrief struct {
  9. ID string `json:"id"`
  10. Title string `json:"title"`
  11. ArtistID string `json:"userId"`
  12. ArtistName string `json:"userName"`
  13. ArtistAvatar string `json:"profileImageUrl"`
  14. Thumbnail string `json:"url"`
  15. Pages int `json:"pageCount"`
  16. XRestrict int `json:"xRestrict"`
  17. AiType int `json:"aiType"`
  18. Bookmarked any `json:"bookmarkData"`
  19. }
  20. func GetNewestArtworks(c *fiber.Ctx, worktype string, r18 string) ([]ArtworkBrief, error) {
  21. token := session.GetToken(c)
  22. URL := http.GetNewestArtworksURL(worktype, r18, "0")
  23. var body struct {
  24. Artworks []ArtworkBrief `json:"illusts"`
  25. // LastId string
  26. }
  27. resp, err := http.UnwrapWebAPIRequest(URL, token)
  28. if err != nil {
  29. return nil, err
  30. }
  31. resp = session.ProxyImageUrl(resp)
  32. err = json.Unmarshal([]byte(resp), &body)
  33. if err != nil {
  34. return nil, err
  35. }
  36. return body.Artworks, nil
  37. }