personal.go 1.2 KB

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