tag.go 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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/template"
  8. "codeberg.org/vnpower/pixivfe/v2/utils"
  9. )
  10. func TagPage(w http.ResponseWriter, r *http.Request) error {
  11. param := GetPathVar(r, "name", GetQueryParam(r, "name"))
  12. name, err := url.PathUnescape(param)
  13. if err != nil {
  14. return err
  15. }
  16. page := GetQueryParam(r, "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: GetQueryParam(r, "category", "artworks"),
  26. Order: GetQueryParam(r, "order", "date_d"),
  27. Mode: GetQueryParam(r, "mode", "safe"),
  28. Ratio: GetQueryParam(r, "ratio", ""),
  29. Wlt: GetQueryParam(r, "wlt", ""),
  30. Wgt: GetQueryParam(r, "wgt", ""),
  31. Hlt: GetQueryParam(r, "hlt", ""),
  32. Hgt: GetQueryParam(r, "hgt", ""),
  33. Tool: GetQueryParam(r, "tool", ""),
  34. Scd: GetQueryParam(r, "scd", ""),
  35. Ecd: GetQueryParam(r, "ecd", ""),
  36. Page: page,
  37. }
  38. tag, err := core.GetTagData(r, name)
  39. if err != nil {
  40. return err
  41. }
  42. result, err := core.GetSearch(r, queries)
  43. if err != nil {
  44. return err
  45. }
  46. urlc := template.PartialURL{Path: "tags", Query: queries.ReturnMap()}
  47. data := Data_tag{Title: "Results for " + name, Tag: tag, Data: *result, QueriesC: urlc, TrueTag: param, Page: pageInt}
  48. return Render(w, r, data)
  49. }
  50. func AdvancedTagPost(w http.ResponseWriter, r *http.Request) error {
  51. return utils.RedirectTo(w, r, "/tags", map[string]string{
  52. "name": GetQueryParam(r, "name", r.FormValue("name")),
  53. "category": GetQueryParam(r, "category", "artworks"),
  54. "order": GetQueryParam(r, "order", "date_d"),
  55. "mode": GetQueryParam(r, "mode", "safe"),
  56. "ratio": GetQueryParam(r, "ratio"),
  57. "page": GetQueryParam(r, "page", "1"),
  58. "wlt": GetQueryParam(r, "wlt", r.FormValue("wlt")),
  59. "wgt": GetQueryParam(r, "wgt", r.FormValue("wgt")),
  60. "hlt": GetQueryParam(r, "hlt", r.FormValue("hlt")),
  61. "hgt": GetQueryParam(r, "hgt", r.FormValue("hgt")),
  62. "tool": GetQueryParam(r, "tool", r.FormValue("tool")),
  63. "scd": GetQueryParam(r, "scd", r.FormValue("scd")),
  64. "ecd": GetQueryParam(r, "ecd", r.FormValue("ecd")),
  65. })
  66. }