-
Notifications
You must be signed in to change notification settings - Fork 736
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix:interation:Pinboard Do not override existing bookmarks
The issue: When saving an entry that is already bookmarked on pinboard, miniflux was basically overriding all existing data on piboard with this action. This removed any `extended` content or worse changed the `private` settings to no private making any previously private bookmark publicly available. The fix: Now, upon saving an entry as bookmark I first fetch it. If it already exists, I do the proper modifications (adding tag and any state) miniflux would have normally done, then do the add again. This way, no data is lost in the process. Pinboard has a pretty stable API, I don't think any new fields will be added soon. I manually tested the integration by hitting the save button in the following situations: - Entry url does not exist on pinboard - Bookmark is properly added on pinboard with tags and `to read` acroding to miniflux settings - Entry url already exist on piboard - Existing data stays unchanged - Tags in miniflux settings are properly added to the bookmark - Set `to read` is properly set to `yes` when the option is checked on miniflux. Nothing is changed otherwise
- Loading branch information
Showing
2 changed files
with
121 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package pinboard | ||
|
||
import ( | ||
"encoding/xml" | ||
"net/url" | ||
"strings" | ||
"time" | ||
) | ||
|
||
// Post a Pinboard bookmark. "inspiration" from https://github.com/drags/pinboard/blob/master/posts.go#L32-L42 | ||
type Post struct { | ||
XMLName xml.Name `xml:"post"` | ||
Url string `xml:"href,attr"` | ||
Description string `xml:"description,attr"` | ||
Tags string `xml:"tag,attr"` | ||
Extended string `xml:"extended,attr"` | ||
Date time.Time `xml:"time,attr"` | ||
Shared string `xml:"shared,attr"` | ||
Toread string `xml:"toread,attr"` | ||
} | ||
|
||
// Posts A result of a Pinboard API call | ||
type posts struct { | ||
XMLName xml.Name `xml:"posts"` | ||
Posts []Post `xml:"post"` | ||
} | ||
|
||
func NewPost(url string, description string) *Post { | ||
return &Post{ | ||
Url: url, | ||
Description: description, | ||
Date: time.Now(), | ||
Toread: "no", | ||
} | ||
} | ||
|
||
func (p *Post) addTag(tag string) { | ||
if !strings.Contains(p.Tags, tag) { | ||
p.Tags += " " + tag | ||
} | ||
} | ||
|
||
func (p *Post) SetToread() { | ||
p.Toread = "yes" | ||
} | ||
|
||
func (p *Post) AddValues(values url.Values) { | ||
values.Add("url", p.Url) | ||
values.Add("description", p.Description) | ||
values.Add("tags", p.Tags) | ||
if p.Toread != "" { | ||
values.Add("toread", p.Toread) | ||
} | ||
if p.Shared != "" { | ||
values.Add("shared", p.Shared) | ||
} | ||
values.Add("dt", p.Date.Format(time.RFC3339)) | ||
values.Add("extended", p.Extended) | ||
} |