From 8e28e41b02a065097992fa4b71549140e9b174f0 Mon Sep 17 00:00:00 2001 From: jvoisin Date: Mon, 18 Mar 2024 11:14:34 +0100 Subject: [PATCH] Use struct embedding to reduce code duplication --- internal/model/feed.go | 20 +--------------- internal/ui/subscription_submit.go | 38 ++++++++++++++++-------------- 2 files changed, 21 insertions(+), 37 deletions(-) diff --git a/internal/model/feed.go b/internal/model/feed.go index f9181ed9..5273eea2 100644 --- a/internal/model/feed.go +++ b/internal/model/feed.go @@ -159,25 +159,7 @@ type FeedCreationRequestFromSubscriptionDiscovery struct { ETag string LastModified string - FeedURL string `json:"feed_url"` - CategoryID int64 `json:"category_id"` - UserAgent string `json:"user_agent"` - Cookie string `json:"cookie"` - Username string `json:"username"` - Password string `json:"password"` - Crawler bool `json:"crawler"` - Disabled bool `json:"disabled"` - NoMediaPlayer bool `json:"no_media_player"` - IgnoreHTTPCache bool `json:"ignore_http_cache"` - AllowSelfSignedCertificates bool `json:"allow_self_signed_certificates"` - FetchViaProxy bool `json:"fetch_via_proxy"` - ScraperRules string `json:"scraper_rules"` - RewriteRules string `json:"rewrite_rules"` - BlocklistRules string `json:"blocklist_rules"` - KeeplistRules string `json:"keeplist_rules"` - HideGlobally bool `json:"hide_globally"` - UrlRewriteRules string `json:"urlrewrite_rules"` - DisableHTTP2 bool `json:"disable_http2"` + FeedCreationRequest } // FeedModificationRequest represents the request to update a feed. diff --git a/internal/ui/subscription_submit.go b/internal/ui/subscription_submit.go index 267e9d7c..fd8e43ef 100644 --- a/internal/ui/subscription_submit.go +++ b/internal/ui/subscription_submit.go @@ -86,24 +86,26 @@ func (h *handler) submitSubscription(w http.ResponseWriter, r *http.Request) { html.OK(w, r, v.Render("add_subscription")) case n == 1 && subscriptionFinder.IsFeedAlreadyDownloaded(): feed, localizedError := feedHandler.CreateFeedFromSubscriptionDiscovery(h.store, user.ID, &model.FeedCreationRequestFromSubscriptionDiscovery{ - Content: subscriptionFinder.FeedResponseInfo().Content, - ETag: subscriptionFinder.FeedResponseInfo().ETag, - LastModified: subscriptionFinder.FeedResponseInfo().LastModified, - CategoryID: subscriptionForm.CategoryID, - FeedURL: subscriptions[0].URL, - Crawler: subscriptionForm.Crawler, - AllowSelfSignedCertificates: subscriptionForm.AllowSelfSignedCertificates, - UserAgent: subscriptionForm.UserAgent, - Cookie: subscriptionForm.Cookie, - Username: subscriptionForm.Username, - Password: subscriptionForm.Password, - ScraperRules: subscriptionForm.ScraperRules, - RewriteRules: subscriptionForm.RewriteRules, - BlocklistRules: subscriptionForm.BlocklistRules, - KeeplistRules: subscriptionForm.KeeplistRules, - UrlRewriteRules: subscriptionForm.UrlRewriteRules, - FetchViaProxy: subscriptionForm.FetchViaProxy, - DisableHTTP2: subscriptionForm.DisableHTTP2, + Content: subscriptionFinder.FeedResponseInfo().Content, + ETag: subscriptionFinder.FeedResponseInfo().ETag, + LastModified: subscriptionFinder.FeedResponseInfo().LastModified, + FeedCreationRequest: model.FeedCreationRequest{ + CategoryID: subscriptionForm.CategoryID, + FeedURL: subscriptions[0].URL, + AllowSelfSignedCertificates: subscriptionForm.AllowSelfSignedCertificates, + Crawler: subscriptionForm.Crawler, + UserAgent: subscriptionForm.UserAgent, + Cookie: subscriptionForm.Cookie, + Username: subscriptionForm.Username, + Password: subscriptionForm.Password, + ScraperRules: subscriptionForm.ScraperRules, + RewriteRules: subscriptionForm.RewriteRules, + BlocklistRules: subscriptionForm.BlocklistRules, + KeeplistRules: subscriptionForm.KeeplistRules, + UrlRewriteRules: subscriptionForm.UrlRewriteRules, + FetchViaProxy: subscriptionForm.FetchViaProxy, + DisableHTTP2: subscriptionForm.DisableHTTP2, + }, }) if localizedError != nil { v.Set("form", subscriptionForm)