index.go 1.2 KB

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