index.go 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. package pages
  2. import (
  3. session "codeberg.org/vnpower/pixivfe/v2/core/session"
  4. core "codeberg.org/vnpower/pixivfe/v2/core/webapi"
  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 c.Render("index", fiber.Map{
  16. "Title": "Landing", "Data": works,
  17. })
  18. }
  19. // ...otherwise, default to today's illustration ranking
  20. works, err := core.GetRanking(c, "daily", "illust", "", "1")
  21. if err != nil {
  22. return err
  23. }
  24. return c.Render("index", fiber.Map{
  25. "Title": "Landing", "NoTokenData": works,
  26. })
  27. }
  28. func Oembed(c *fiber.Ctx) error {
  29. pageURL := c.BaseURL()
  30. artistName := c.Query("a", "")
  31. artistURL := c.Query("u", "")
  32. data := fiber.Map{
  33. "version": "1.0",
  34. "embed_type": "rich",
  35. "provider_name": "PixivFE",
  36. "provider_url": pageURL,
  37. "author_name": artistName,
  38. "author_url": artistURL,
  39. }
  40. return c.JSON(data)
  41. }