personal.go 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. package pages
  2. import (
  3. "net/http"
  4. "strconv"
  5. "strings"
  6. session "codeberg.org/vnpower/pixivfe/v2/core/session"
  7. core "codeberg.org/vnpower/pixivfe/v2/core/webapi"
  8. "github.com/gofiber/fiber/v2"
  9. )
  10. func PromptUserToLoginPage(c *fiber.Ctx) error {
  11. c.Status(http.StatusUnauthorized)
  12. return c.Render("unauthorized", fiber.Map{})
  13. }
  14. func LoginUserPage(c *fiber.Ctx) error {
  15. token := session.GetPixivToken(c)
  16. if token == "" {
  17. return PromptUserToLoginPage(c)
  18. }
  19. // The left part of the token is the member ID
  20. userId := strings.Split(token, "_")
  21. c.Redirect("/users/" + userId[0])
  22. return nil
  23. }
  24. func LoginBookmarkPage(c *fiber.Ctx) error {
  25. token := session.GetPixivToken(c)
  26. if token == "" {
  27. return PromptUserToLoginPage(c)
  28. }
  29. // The left part of the token is the member ID
  30. userId := strings.Split(token, "_")
  31. c.Redirect("/users/" + userId[0] + "/bookmarks#checkpoint")
  32. return nil
  33. }
  34. func FollowingWorksPage(c *fiber.Ctx) error {
  35. if token := session.GetPixivToken(c); token == "" {
  36. return PromptUserToLoginPage(c)
  37. }
  38. mode := c.Query("mode", "all")
  39. page := c.Query("page", "1")
  40. pageInt, err := strconv.Atoi(page)
  41. if err != nil {
  42. return err
  43. }
  44. works, err := core.GetNewestFromFollowing(c, mode, page)
  45. if err != nil {
  46. return err
  47. }
  48. return c.Render("following", fiber.Map{
  49. "Title": "Following works",
  50. "Mode": mode,
  51. "Artworks": works,
  52. "CurPage": page,
  53. "Page": pageInt,
  54. })
  55. }