4498ba10e8
The Issue: When saving an entry that is already bookmarked on Pinboard, Miniflux was overriding all existing data on Pinboard. This action removed any extended content or, worse, changed the private settings to public, making previously private bookmarks publicly available. The Fix: Now, upon saving an entry as a bookmark, I first fetch it. If it already exists, I apply the necessary modifications (adding tags and any state) that Miniflux would have normally done, then add it again. This way, no data is lost in the process. Pinboard has a stable API, so I don't anticipate any new fields being 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" status according to Miniflux settings. - Entry URL already exists on Pinboard: - Existing data remains unchanged. - Tags from Miniflux settings are properly added to the bookmark. - "To read" status is set to yes when the option is checked in Miniflux. Nothing is changed otherwise.
62 lines
1.5 KiB
Go
62 lines
1.5 KiB
Go
// SPDX-FileCopyrightText: Copyright The Miniflux Authors. All rights reserved.
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
package pinboard // import "miniflux.app/v2/internal/integration/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)
|
|
}
|