newest.go 711 B

1234567891011121314151617181920212223242526272829303132
  1. package core
  2. import (
  3. session "codeberg.org/vnpower/pixivfe/v2/core/session"
  4. http "codeberg.org/vnpower/pixivfe/v2/core/http"
  5. "github.com/goccy/go-json"
  6. "github.com/gofiber/fiber/v2"
  7. )
  8. func GetNewestArtworks(c *fiber.Ctx, worktype string, r18 string) ([]ArtworkBrief, error) {
  9. token := session.GetPixivToken(c)
  10. URL := http.GetNewestArtworksURL(worktype, r18, "0")
  11. var body struct {
  12. Artworks []ArtworkBrief `json:"illusts"`
  13. // LastId string
  14. }
  15. resp, err := http.UnwrapWebAPIRequest(c.Context(), URL, token)
  16. if err != nil {
  17. return nil, err
  18. }
  19. resp = session.ProxyImageUrl(c, resp)
  20. err = json.Unmarshal([]byte(resp), &body)
  21. if err != nil {
  22. return nil, err
  23. }
  24. return body.Artworks, nil
  25. }