mirror of
https://github.com/miniflux/v2.git
synced 2025-08-06 17:41:00 +00:00
Add Pinboard integration
This commit is contained in:
parent
2f1367a8d4
commit
2356ddad28
28 changed files with 550 additions and 49 deletions
|
@ -4,10 +4,25 @@
|
|||
|
||||
package controller
|
||||
|
||||
import "github.com/miniflux/miniflux2/server/core"
|
||||
import (
|
||||
"errors"
|
||||
"log"
|
||||
|
||||
"github.com/miniflux/miniflux2/integration/pinboard"
|
||||
"github.com/miniflux/miniflux2/model"
|
||||
"github.com/miniflux/miniflux2/server/core"
|
||||
"github.com/miniflux/miniflux2/server/ui/form"
|
||||
)
|
||||
|
||||
// ShowIntegrations renders the page with all external integrations.
|
||||
func (c *Controller) ShowIntegrations(ctx *core.Context, request *core.Request, response *core.Response) {
|
||||
user := ctx.LoggedUser()
|
||||
integration, err := c.store.Integration(user.ID)
|
||||
if err != nil {
|
||||
response.HTML().ServerError(err)
|
||||
return
|
||||
}
|
||||
|
||||
args, err := c.getCommonTemplateArgs(ctx)
|
||||
if err != nil {
|
||||
response.HTML().ServerError(err)
|
||||
|
@ -16,5 +31,75 @@ func (c *Controller) ShowIntegrations(ctx *core.Context, request *core.Request,
|
|||
|
||||
response.HTML().Render("integrations", args.Merge(tplParams{
|
||||
"menu": "settings",
|
||||
"form": form.IntegrationForm{
|
||||
PinboardEnabled: integration.PinboardEnabled,
|
||||
PinboardToken: integration.PinboardToken,
|
||||
PinboardTags: integration.PinboardTags,
|
||||
PinboardMarkAsUnread: integration.PinboardMarkAsUnread,
|
||||
},
|
||||
}))
|
||||
}
|
||||
|
||||
// UpdateIntegration updates integration settings.
|
||||
func (c *Controller) UpdateIntegration(ctx *core.Context, request *core.Request, response *core.Response) {
|
||||
user := ctx.LoggedUser()
|
||||
integration, err := c.store.Integration(user.ID)
|
||||
if err != nil {
|
||||
response.HTML().ServerError(err)
|
||||
return
|
||||
}
|
||||
|
||||
integrationForm := form.NewIntegrationForm(request.Request())
|
||||
integrationForm.Merge(integration)
|
||||
|
||||
err = c.store.UpdateIntegration(integration)
|
||||
if err != nil {
|
||||
response.HTML().ServerError(err)
|
||||
return
|
||||
}
|
||||
|
||||
response.Redirect(ctx.Route("integrations"))
|
||||
}
|
||||
|
||||
// SaveEntry send the link to external services.
|
||||
func (c *Controller) SaveEntry(ctx *core.Context, request *core.Request, response *core.Response) {
|
||||
entryID, err := request.IntegerParam("entryID")
|
||||
if err != nil {
|
||||
response.HTML().BadRequest(err)
|
||||
return
|
||||
}
|
||||
|
||||
user := ctx.LoggedUser()
|
||||
builder := c.store.GetEntryQueryBuilder(user.ID, user.Timezone)
|
||||
builder.WithEntryID(entryID)
|
||||
builder.WithoutStatus(model.EntryStatusRemoved)
|
||||
|
||||
entry, err := builder.GetEntry()
|
||||
if err != nil {
|
||||
response.JSON().ServerError(err)
|
||||
return
|
||||
}
|
||||
|
||||
if entry == nil {
|
||||
response.JSON().NotFound(errors.New("Entry not found"))
|
||||
return
|
||||
}
|
||||
|
||||
integration, err := c.store.Integration(user.ID)
|
||||
if err != nil {
|
||||
response.JSON().ServerError(err)
|
||||
return
|
||||
}
|
||||
|
||||
go func() {
|
||||
if integration.PinboardEnabled {
|
||||
client := pinboard.NewClient(integration.PinboardToken)
|
||||
err := client.AddBookmark(entry.URL, entry.Title, integration.PinboardTags, integration.PinboardMarkAsUnread)
|
||||
if err != nil {
|
||||
log.Println("[Pinboard]", err)
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
||||
response.JSON().Created(map[string]string{"message": "saved"})
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue