subscription_choose.go 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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"
  9. "miniflux.app/v2/internal/model"
  10. feedHandler "miniflux.app/v2/internal/reader/handler"
  11. "miniflux.app/v2/internal/ui/form"
  12. "miniflux.app/v2/internal/ui/view"
  13. )
  14. func (h *handler) showChooseSubscriptionPage(w http.ResponseWriter, r *http.Request) {
  15. user, err := h.store.UserByID(request.UserID(r))
  16. if err != nil {
  17. response.HTMLServerError(w, r, err)
  18. return
  19. }
  20. categories, err := h.store.Categories(user.ID)
  21. if err != nil {
  22. response.HTMLServerError(w, r, err)
  23. return
  24. }
  25. view := view.New(h.tpl, r)
  26. view.Set("categories", categories)
  27. view.Set("menu", "feeds")
  28. view.Set("user", user)
  29. view.Set("countUnread", h.store.CountUnreadEntries(user.ID))
  30. view.Set("countErrorFeeds", h.store.CountUserFeedsWithErrors(user.ID))
  31. view.Set("defaultUserAgent", config.Opts.HTTPClientUserAgent())
  32. subscriptionForm := form.NewSubscriptionForm(r)
  33. if validationErr := subscriptionForm.Validate(); validationErr != nil {
  34. view.Set("form", subscriptionForm)
  35. view.Set("errorMessage", validationErr.Translate(user.Language))
  36. response.HTML(w, r, view.Render("add_subscription"))
  37. return
  38. }
  39. feed, localizedError := feedHandler.CreateFeed(h.store, user.ID, &model.FeedCreationRequest{
  40. CategoryID: subscriptionForm.CategoryID,
  41. FeedURL: subscriptionForm.URL,
  42. Crawler: subscriptionForm.Crawler,
  43. IgnoreEntryUpdates: subscriptionForm.IgnoreEntryUpdates,
  44. AllowSelfSignedCertificates: subscriptionForm.AllowSelfSignedCertificates,
  45. UserAgent: subscriptionForm.UserAgent,
  46. Cookie: subscriptionForm.Cookie,
  47. Username: subscriptionForm.Username,
  48. Password: subscriptionForm.Password,
  49. ScraperRules: subscriptionForm.ScraperRules,
  50. RewriteRules: subscriptionForm.RewriteRules,
  51. UrlRewriteRules: subscriptionForm.UrlRewriteRules,
  52. BlocklistRules: subscriptionForm.BlocklistRules,
  53. KeeplistRules: subscriptionForm.KeeplistRules,
  54. KeepFilterEntryRules: subscriptionForm.KeepFilterEntryRules,
  55. BlockFilterEntryRules: subscriptionForm.BlockFilterEntryRules,
  56. FetchViaProxy: subscriptionForm.FetchViaProxy,
  57. DisableHTTP2: subscriptionForm.DisableHTTP2,
  58. ProxyURL: subscriptionForm.ProxyURL,
  59. })
  60. if localizedError != nil {
  61. view.Set("form", subscriptionForm)
  62. view.Set("errorMessage", localizedError.Translate(user.Language))
  63. response.HTML(w, r, view.Render("add_subscription"))
  64. return
  65. }
  66. response.HTMLRedirect(w, r, h.routePath("/feed/%d/entries", feed.ID))
  67. }