subscription_choose.go 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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. IgnoreEntryUpdates: subscriptionForm.IgnoreEntryUpdates,
  47. AllowSelfSignedCertificates: subscriptionForm.AllowSelfSignedCertificates,
  48. UserAgent: subscriptionForm.UserAgent,
  49. Cookie: subscriptionForm.Cookie,
  50. Username: subscriptionForm.Username,
  51. Password: subscriptionForm.Password,
  52. ScraperRules: subscriptionForm.ScraperRules,
  53. RewriteRules: subscriptionForm.RewriteRules,
  54. UrlRewriteRules: subscriptionForm.UrlRewriteRules,
  55. BlocklistRules: subscriptionForm.BlocklistRules,
  56. KeeplistRules: subscriptionForm.KeeplistRules,
  57. KeepFilterEntryRules: subscriptionForm.KeepFilterEntryRules,
  58. BlockFilterEntryRules: subscriptionForm.BlockFilterEntryRules,
  59. FetchViaProxy: subscriptionForm.FetchViaProxy,
  60. DisableHTTP2: subscriptionForm.DisableHTTP2,
  61. ProxyURL: subscriptionForm.ProxyURL,
  62. })
  63. if localizedError != nil {
  64. view.Set("form", subscriptionForm)
  65. view.Set("errorMessage", localizedError.Translate(user.Language))
  66. html.OK(w, r, view.Render("add_subscription"))
  67. return
  68. }
  69. html.Redirect(w, r, route.Path(h.router, "feedEntries", "feedID", feed.ID))
  70. }