tag.go 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. package routes
  2. import (
  3. "net/http"
  4. "net/url"
  5. "strconv"
  6. "codeberg.org/vnpower/pixivfe/v2/core"
  7. "codeberg.org/vnpower/pixivfe/v2/utils"
  8. "github.com/gofiber/fiber/v2"
  9. )
  10. func TagPage(c *fiber.Ctx) error {
  11. param := c.Params("name", c.Query("name"))
  12. name, err := url.PathUnescape(param)
  13. if err != nil {
  14. return err
  15. }
  16. page := c.Query("page", "1")
  17. pageInt, err := strconv.Atoi(page)
  18. if err != nil {
  19. return err
  20. }
  21. // Because of the large amount of queries available for this route,
  22. // I made a struct type just to manage the queries
  23. queries := core.SearchPageSettings{
  24. Name: name,
  25. Category: c.Query("category", "artworks"),
  26. Order: c.Query("order", "date_d"),
  27. Mode: c.Query("mode", "safe"),
  28. Ratio: c.Query("ratio", ""),
  29. Wlt: c.Query("wlt", ""),
  30. Wgt: c.Query("wgt", ""),
  31. Hlt: c.Query("hlt", ""),
  32. Hgt: c.Query("hgt", ""),
  33. Tool: c.Query("tool", ""),
  34. Scd: c.Query("scd", ""),
  35. Ecd: c.Query("ecd", ""),
  36. Page: page,
  37. }
  38. tag, err := core.GetTagData(c, name)
  39. if err != nil {
  40. return err
  41. }
  42. result, err := core.GetSearch(c, queries)
  43. if err != nil {
  44. return err
  45. }
  46. urlc := utils.PartialURL{Path: "tags", Query: queries.ReturnMap()}
  47. return Render(c, Data_tag{Title: "Results for " + name, Tag: tag, Data: *result, QueriesC: urlc, TrueTag: param, Page: pageInt})
  48. }
  49. func AdvancedTagPost(c *fiber.Ctx) error {
  50. return c.RedirectToRoute("/tags", fiber.Map{
  51. "queries": map[string]string{
  52. "name": c.Query("name", c.FormValue("name")),
  53. "category": c.Query("category", "artworks"),
  54. "order": c.Query("order", "date_d"),
  55. "mode": c.Query("mode", "safe"),
  56. "ratio": c.Query("ratio"),
  57. "page": c.Query("page", "1"),
  58. "wlt": c.Query("wlt", c.FormValue("wlt")),
  59. "wgt": c.Query("wgt", c.FormValue("wgt")),
  60. "hlt": c.Query("hlt", c.FormValue("hlt")),
  61. "hgt": c.Query("hgt", c.FormValue("hgt")),
  62. "tool": c.Query("tool", c.FormValue("tool")),
  63. "scd": c.Query("scd", c.FormValue("scd")),
  64. "ecd": c.Query("ecd", c.FormValue("ecd")),
  65. },
  66. }, http.StatusFound)
  67. }