subscription_choose.go 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. // SPDX-FileCopyrightText: Copyright The Miniflux Authors. All rights reserved.
  2. // SPDX-License-Identifier: Apache-2.0
  3. package ui // import "miniflux.app/v2/internal/ui"
  4. import (
  5. "net/http"
  6. "miniflux.app/v2/internal/config"
  7. "miniflux.app/v2/internal/http/request"
  8. "miniflux.app/v2/internal/http/response/html"
  9. "miniflux.app/v2/internal/http/route"
  10. "miniflux.app/v2/internal/model"
  11. feedHandler "miniflux.app/v2/internal/reader/handler"
  12. "miniflux.app/v2/internal/ui/form"
  13. "miniflux.app/v2/internal/ui/session"
  14. "miniflux.app/v2/internal/ui/view"
  15. )
  16. func (h *handler) showChooseSubscriptionPage(w http.ResponseWriter, r *http.Request) {
  17. user, err := h.store.UserByID(request.UserID(r))
  18. if err != nil {
  19. html.ServerError(w, r, err)
  20. return
  21. }
  22. categories, err := h.store.Categories(user.ID)
  23. if err != nil {
  24. html.ServerError(w, r, err)
  25. return
  26. }
  27. sess := session.New(h.store, request.SessionID(r))
  28. view := view.New(h.tpl, r, sess)
  29. view.Set("categories", categories)
  30. view.Set("menu", "feeds")
  31. view.Set("user", user)
  32. view.Set("countUnread", h.store.CountUnreadEntries(user.ID))
  33. view.Set("countErrorFeeds", h.store.CountUserFeedsWithErrors(user.ID))
  34. view.Set("defaultUserAgent", config.Opts.HTTPClientUserAgent())
  35. subscriptionForm := form.NewSubscriptionForm(r)
  36. if validationErr := subscriptionForm.Validate(); validationErr != nil {
  37. view.Set("form", subscriptionForm)
  38. view.Set("errorMessage", validationErr.Translate(user.Language))
  39. html.OK(w, r, view.Render("add_subscription"))
  40. return
  41. }
  42. feed, localizedError := feedHandler.CreateFeed(h.store, user.ID, &model.FeedCreationRequest{
  43. CategoryID: subscriptionForm.CategoryID,
  44. FeedURL: subscriptionForm.URL,
  45. Crawler: subscriptionForm.Crawler,
  46. AllowSelfSignedCertificates: subscriptionForm.AllowSelfSignedCertificates,
  47. UserAgent: subscriptionForm.UserAgent,
  48. Cookie: subscriptionForm.Cookie,
  49. Username: subscriptionForm.Username,
  50. Password: subscriptionForm.Password,
  51. ScraperRules: subscriptionForm.ScraperRules,
  52. RewriteRules: subscriptionForm.RewriteRules,
  53. UrlRewriteRules: subscriptionForm.UrlRewriteRules,
  54. BlocklistRules: subscriptionForm.BlocklistRules,
  55. KeeplistRules: subscriptionForm.KeeplistRules,
  56. KeepFilterEntryRules: subscriptionForm.KeepFilterEntryRules,
  57. BlockFilterEntryRules: subscriptionForm.BlockFilterEntryRules,
  58. FetchViaProxy: subscriptionForm.FetchViaProxy,
  59. DisableHTTP2: subscriptionForm.DisableHTTP2,
  60. ProxyURL: subscriptionForm.ProxyURL,
  61. })
  62. if localizedError != nil {
  63. view.Set("form", subscriptionForm)
  64. view.Set("errorMessage", localizedError.Translate(user.Language))
  65. html.OK(w, r, view.Render("add_subscription"))
  66. return
  67. }
  68. html.Redirect(w, r, route.Path(h.router, "feedEntries", "feedID", feed.ID))
  69. }