personal.go 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. package routes
  2. import (
  3. "net/http"
  4. "strconv"
  5. "strings"
  6. "codeberg.org/vnpower/pixivfe/v2/core"
  7. "codeberg.org/vnpower/pixivfe/v2/session"
  8. "github.com/gofiber/fiber/v2"
  9. )
  10. func PromptUserToLoginPage(c *fiber.Ctx) error {
  11. c.Status(http.StatusUnauthorized)
  12. return Render(c, Data_unauthorized{})
  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 Render(c, Data_following{Title: "Following works", Mode: mode, Artworks: works, CurPage: page, Page: pageInt})
  49. }