index.go 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. package routes
  2. import (
  3. "codeberg.org/vnpower/pixivfe/v2/core"
  4. "codeberg.org/vnpower/pixivfe/v2/session"
  5. "github.com/gofiber/fiber/v2"
  6. )
  7. func IndexPage(c *fiber.Ctx) error {
  8. // If token is set, do the landing request...
  9. if token := session.GetPixivToken(c); token != "" {
  10. mode := c.Query("mode", "all")
  11. works, err := core.GetLanding(c, mode)
  12. if err != nil {
  13. return err
  14. }
  15. return Render(c, Data_index{
  16. Title: "Landing",
  17. Data: *works,
  18. LoggedIn: true,
  19. })
  20. }
  21. // ...otherwise, default to today's illustration ranking
  22. works, err := core.GetRanking(c, "daily", "illust", "", "1")
  23. if err != nil {
  24. return err
  25. }
  26. return Render(c, Data_index{
  27. Title: "Landing",
  28. NoTokenData: works,
  29. LoggedIn: false,
  30. })
  31. }
  32. func Oembed(c *fiber.Ctx) error {
  33. pageURL := c.BaseURL()
  34. artistName := c.Query("a", "")
  35. artistURL := c.Query("u", "")
  36. data := fiber.Map{
  37. "version": "1.0",
  38. "embed_type": "rich",
  39. "provider_name": "PixivFE",
  40. "provider_url": pageURL,
  41. "author_name": artistName,
  42. "author_url": artistURL,
  43. }
  44. return c.JSON(data)
  45. }