aboutsummaryrefslogtreecommitdiff
path: root/internal
diff options
context:
space:
mode:
authorGravatar Frédéric Guillot <f@miniflux.net> 2023-09-10 12:50:58 -0700
committerGravatar Frédéric Guillot <f@miniflux.net> 2023-09-10 13:20:04 -0700
commitca6af9684a108a40054684259a119f0bfed7d4d5 (patch)
tree12d30154dd18a7761aa2ac5659a780df76852599 /internal
parentcb228e73ada44c4641bf92d61c274a6d18dda69c (diff)
downloadv2-ca6af9684a108a40054684259a119f0bfed7d4d5.tar.gz
v2-ca6af9684a108a40054684259a119f0bfed7d4d5.tar.zst
v2-ca6af9684a108a40054684259a119f0bfed7d4d5.zip
Add feed information into webhook event
Diffstat (limited to 'internal')
-rw-r--r--internal/integration/integration.go4
-rw-r--r--internal/integration/webhook/webhook.go31
-rw-r--r--internal/model/feed.go2
3 files changed, 32 insertions, 5 deletions
diff --git a/internal/integration/integration.go b/internal/integration/integration.go
index eb9f842e..cd2baf79 100644
--- a/internal/integration/integration.go
+++ b/internal/integration/integration.go
@@ -181,10 +181,10 @@ func PushEntries(feed *model.Feed, entries model.Entries, userIntegrations *mode
}
if userIntegrations.WebhookEnabled {
- logger.Debug("[Integration] Sending %d entries for User #%d to Webhook URL: %s", len(entries), userIntegrations.UserID, userIntegrations.WebhookURL)
+ logger.Debug("[Integration] Sending %d entries for user #%d to Webhook URL: %s", len(entries), userIntegrations.UserID, userIntegrations.WebhookURL)
webhookClient := webhook.NewClient(userIntegrations.WebhookURL, userIntegrations.WebhookSecret)
- if err := webhookClient.SendWebhook(entries); err != nil {
+ if err := webhookClient.SendWebhook(feed, entries); err != nil {
logger.Error("[Integration] sending entries to webhook failed: %v", err)
}
}
diff --git a/internal/integration/webhook/webhook.go b/internal/integration/webhook/webhook.go
index 65f5fa8c..766c54a3 100644
--- a/internal/integration/webhook/webhook.go
+++ b/internal/integration/webhook/webhook.go
@@ -26,7 +26,7 @@ func NewClient(webhookURL, webhookSecret string) *Client {
return &Client{webhookURL, webhookSecret}
}
-func (c *Client) SendWebhook(entries model.Entries) error {
+func (c *Client) SendWebhook(feed *model.Feed, entries model.Entries) error {
if c.webhookURL == "" {
return fmt.Errorf(`webhook: missing webhook URL`)
}
@@ -35,7 +35,20 @@ func (c *Client) SendWebhook(entries model.Entries) error {
return nil
}
- requestBody, err := json.Marshal(entries)
+ webhookEvent := &WebhookEvent{
+ // Send only a subset of the fields to avoid leaking sensitive data.
+ Feed: &WebhookFeed{
+ ID: feed.ID,
+ UserID: feed.UserID,
+ FeedURL: feed.FeedURL,
+ SiteURL: feed.SiteURL,
+ Title: feed.Title,
+ CheckedAt: feed.CheckedAt,
+ },
+ Entries: entries,
+ }
+
+ requestBody, err := json.Marshal(webhookEvent)
if err != nil {
return fmt.Errorf("webhook: unable to encode request body: %v", err)
}
@@ -62,3 +75,17 @@ func (c *Client) SendWebhook(entries model.Entries) error {
return nil
}
+
+type WebhookFeed struct {
+ ID int64 `json:"id"`
+ UserID int64 `json:"user_id"`
+ FeedURL string `json:"feed_url"`
+ SiteURL string `json:"site_url"`
+ Title string `json:"title"`
+ CheckedAt time.Time `json:"checked_at"`
+}
+
+type WebhookEvent struct {
+ Feed *WebhookFeed `json:"feed"`
+ Entries model.Entries `json:"entries"`
+}
diff --git a/internal/model/feed.go b/internal/model/feed.go
index a6e228d8..f35ebc56 100644
--- a/internal/model/feed.go
+++ b/internal/model/feed.go
@@ -51,7 +51,7 @@ type Feed struct {
FetchViaProxy bool `json:"fetch_via_proxy"`
Category *Category `json:"category,omitempty"`
Entries Entries `json:"entries,omitempty"`
- IconURL string `json:"icon_url"`
+ IconURL string `json:"-"`
Icon *FeedIcon `json:"icon"`
HideGlobally bool `json:"hide_globally"`
UnreadCount int `json:"-"`