user.go 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. package pages
  2. import (
  3. "errors"
  4. "math"
  5. "strconv"
  6. core "codeberg.org/vnpower/pixivfe/v2/core/webapi"
  7. "github.com/gofiber/fiber/v2"
  8. )
  9. func UserPage(c *fiber.Ctx) error {
  10. id := c.Params("id")
  11. if _, err := strconv.Atoi(id); err != nil {
  12. return err
  13. }
  14. category := c.Params("category", "artworks")
  15. if !(category == "artworks" || category == "illustrations" || category == "manga" || category == "bookmarks") {
  16. return errors.New("Invalid work category: only illustrations, manga, artworks and bookmarks are available")
  17. }
  18. page := c.Query("page", "1")
  19. pageInt, _ := strconv.Atoi(page)
  20. user, err := core.GetUserArtwork(c, id, category, pageInt)
  21. if err != nil {
  22. return err
  23. }
  24. var worksCount int
  25. var worksPerPage float64
  26. if category == "bookmarks" {
  27. worksPerPage = 48.0
  28. } else {
  29. worksPerPage = 30.0
  30. }
  31. worksCount = user.ArtworksCount
  32. pageLimit := math.Ceil(float64(worksCount) / worksPerPage)
  33. return c.Render("pages/user", fiber.Map{
  34. "Title": user.Name,
  35. "User": user,
  36. "Category": category,
  37. "PageLimit": int(pageLimit),
  38. "Page": pageInt,
  39. "MetaImage": user.BackgroundImage,
  40. })
  41. }