Parcourir la source

Send full article content to wallabag

Gabriel Augendre il y a 5 ans
Parent
commit
e5b2eab727
2 fichiers modifiés avec 6 ajouts et 5 suppressions
  1. 1 1
      integration/integration.go
  2. 5 4
      integration/wallabag/wallabag.go

+ 1 - 1
integration/integration.go

@@ -47,7 +47,7 @@ func SendEntry(entry *model.Entry, integration *model.Integration) {
 			integration.WallabagPassword,
 		)
 
-		if err := client.AddEntry(entry.URL, entry.Title); err != nil {
+		if err := client.AddEntry(entry.URL, entry.Title, entry.Content); err != nil {
 			logger.Error("[Integration] UserID #%d: %v", integration.UserID, err)
 		}
 	}

+ 5 - 4
integration/wallabag/wallabag.go

@@ -23,7 +23,8 @@ type Client struct {
 }
 
 // AddEntry sends a link to Wallabag.
-func (c *Client) AddEntry(link, title string) error {
+// Pass an empty string in `content` to let Wallabag fetch the article content.
+func (c *Client) AddEntry(link, title, content string) error {
 	if c.baseURL == "" || c.clientID == "" || c.clientSecret == "" || c.username == "" || c.password == "" {
 		return fmt.Errorf("wallabag: missing credentials")
 	}
@@ -33,10 +34,10 @@ func (c *Client) AddEntry(link, title string) error {
 		return err
 	}
 
-	return c.createEntry(accessToken, link, title)
+	return c.createEntry(accessToken, link, title, content)
 }
 
-func (c *Client) createEntry(accessToken, link, title string) error {
+func (c *Client) createEntry(accessToken, link, title, content string) error {
 	endpoint, err := getAPIEndpoint(c.baseURL, "/api/entries.json")
 	if err != nil {
 		return fmt.Errorf("wallbag: unable to get entries endpoint: %v", err)
@@ -44,7 +45,7 @@ func (c *Client) createEntry(accessToken, link, title string) error {
 
 	clt := client.New(endpoint)
 	clt.WithAuthorization("Bearer " + accessToken)
-	response, err := clt.PostJSON(map[string]string{"url": link, "title": title})
+	response, err := clt.PostJSON(map[string]string{"url": link, "title": title, "content": content})
 	if err != nil {
 		return fmt.Errorf("wallabag: unable to post entry: %v", err)
 	}