1
0
Fork 0

Add Instapaper integration

This commit is contained in:
Frédéric Guillot 2017-12-02 21:12:03 -08:00
parent 6f5350a497
commit ae62e543d3
19 changed files with 191 additions and 51 deletions

View file

@ -0,0 +1,39 @@
// Copyright 2017 Frédéric Guillot. All rights reserved.
// Use of this source code is governed by the Apache 2.0
// license that can be found in the LICENSE file.
package instapaper
import (
"fmt"
"net/url"
"github.com/miniflux/miniflux2/http"
)
// Client represents an Instapaper client.
type Client struct {
username string
password string
}
// AddURL sends a link to Instapaper.
func (c *Client) AddURL(link, title string) error {
values := url.Values{}
values.Add("url", link)
values.Add("title", title)
apiURL := "https://www.instapaper.com/api/add?" + values.Encode()
client := http.NewClientWithCredentials(apiURL, c.username, c.password)
response, err := client.Get()
if response.HasServerFailure() {
return fmt.Errorf("unable to send bookmark to instapaper, status=%d", response.StatusCode)
}
return err
}
// NewClient returns a new Instapaper client.
func NewClient(username, password string) *Client {
return &Client{username: username, password: password}
}

View file

@ -0,0 +1,32 @@
// Copyright 2017 Frédéric Guillot. All rights reserved.
// Use of this source code is governed by the Apache 2.0
// license that can be found in the LICENSE file.
package integration
import (
"log"
"github.com/miniflux/miniflux2/integration/instapaper"
"github.com/miniflux/miniflux2/integration/pinboard"
"github.com/miniflux/miniflux2/model"
)
// SendEntry send the entry to the activated providers.
func SendEntry(entry *model.Entry, integration *model.Integration) {
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)
}
}
if integration.InstapaperEnabled {
client := instapaper.NewClient(integration.InstapaperUsername, integration.InstapaperPassword)
err := client.AddURL(entry.URL, entry.Title)
if err != nil {
log.Println("[Instapaper]", err)
}
}
}

View file

@ -11,7 +11,7 @@ import (
"github.com/miniflux/miniflux2/http"
)
// Client represents a Pinboard token.
// Client represents a Pinboard client.
type Client struct {
authToken string
}

View file

@ -1,5 +1,5 @@
// Code generated by go generate; DO NOT EDIT.
// 2017-12-02 19:31:37.042505019 -0800 PST m=+0.027446145
// 2017-12-02 21:11:24.028184492 -0800 PST m=+0.019358340
package locale
@ -160,12 +160,15 @@ var translations = map[string]string{
"Mark bookmark as unread": "Marquer le lien comme non lu",
"Pinboard Tags": "Libellés de Pinboard",
"Pinboard API Token": "Jeton de sécurité de l'API de Pinboard",
"Enable Pinboard": "Activer Pinboard"
"Enable Pinboard": "Activer Pinboard",
"Enable Instapaper": "Activer Instapaper",
"Instapaper Username": "Nom d'utilisateur Instapaper",
"Instapaper Password": "Mot de passe Instapaper"
}
`,
}
var translationsChecksums = map[string]string{
"en_US": "6fe95384260941e8a5a3c695a655a932e0a8a6a572c1e45cb2b1ae8baa01b897",
"fr_FR": "fce31dfc3b8d45ee1c5d0c7aca4449553a8228a2428491e5cf5cf9e507dddb31",
"fr_FR": "17a85afeb45665dc1a74cfb1fde83e0ed4ba335a8da56a328cf20ee4baec7567",
}

View file

@ -144,5 +144,8 @@
"Mark bookmark as unread": "Marquer le lien comme non lu",
"Pinboard Tags": "Libellés de Pinboard",
"Pinboard API Token": "Jeton de sécurité de l'API de Pinboard",
"Enable Pinboard": "Activer Pinboard"
"Enable Pinboard": "Activer Pinboard",
"Enable Instapaper": "Activer Instapaper",
"Instapaper Username": "Nom d'utilisateur Instapaper",
"Instapaper Password": "Mot de passe Instapaper"
}

View file

@ -11,4 +11,7 @@ type Integration struct {
PinboardToken string
PinboardTags string
PinboardMarkAsUnread bool
InstapaperEnabled bool
InstapaperUsername string
InstapaperPassword string
}

View file

@ -1,5 +1,5 @@
// Code generated by go generate; DO NOT EDIT.
// 2017-12-02 19:31:37.021832102 -0800 PST m=+0.006773228
// 2017-12-02 21:11:24.016429412 -0800 PST m=+0.007603260
package static

File diff suppressed because one or more lines are too long

View file

@ -105,6 +105,7 @@ input[type="text"]:focus {
.panel {
background: #333;
border-color: #555;
color: #9b9b9b;
}
/* Counter */

View file

@ -223,7 +223,7 @@ input[type="text"]:focus {
}
input[type="checkbox"] {
margin-bottom: 10px;
margin-bottom: 15px;
}
::-moz-placeholder,
@ -239,6 +239,12 @@ input[type="checkbox"] {
margin-bottom: 15px;
}
.form-section {
border-left: 2px dotted #ddd;
padding-left: 20px;
margin-left: 10px;
}
/* Buttons */
a.button {
text-decoration: none;

View file

@ -1,5 +1,5 @@
// Code generated by go generate; DO NOT EDIT.
// 2017-12-02 19:31:37.026479459 -0800 PST m=+0.011420585
// 2017-12-02 21:11:24.018743922 -0800 PST m=+0.009917770
package static

View file

@ -1,5 +1,5 @@
// Code generated by go generate; DO NOT EDIT.
// 2017-12-02 19:31:37.041375649 -0800 PST m=+0.026316775
// 2017-12-02 21:11:24.027142168 -0800 PST m=+0.018316016
package template

View file

@ -29,6 +29,7 @@
{{ end }}
<h3>Pinboard</h3>
<div class="form-section">
<label>
<input type="checkbox" name="pinboard_enabled" value="1" {{ if .form.PinboardEnabled }}checked{{ end }}> {{ t "Enable Pinboard" }}
</label>
@ -42,6 +43,20 @@
<label>
<input type="checkbox" name="pinboard_mark_as_unread" value="1" {{ if .form.PinboardMarkAsUnread }}checked{{ end }}> {{ t "Mark bookmark as unread" }}
</label>
</div>
<h3>Instapaper</h3>
<div class="form-section">
<label>
<input type="checkbox" name="instapaper_enabled" value="1" {{ if .form.InstapaperEnabled }}checked{{ end }}> {{ t "Enable Instapaper" }}
</label>
<label for="form-instapaper-username">{{ t "Instapaper Username" }}</label>
<input type="text" name="instapaper_username" id="form-instapaper-username" value="{{ .form.InstapaperUsername }}">
<label for="form-instapaper-password">{{ t "Instapaper Password" }}</label>
<input type="password" name="instapaper_password" id="form-instapaper-password" value="{{ .form.InstapaperPassword }}">
</div>
<div class="buttons">
<button type="submit" class="button button-primary" data-label-loading="{{ t "Loading..." }}">{{ t "Update" }}</button>

View file

@ -1,5 +1,5 @@
// Code generated by go generate; DO NOT EDIT.
// 2017-12-02 19:31:37.027317932 -0800 PST m=+0.012259058
// 2017-12-02 21:11:24.019569008 -0800 PST m=+0.010742856
package template
@ -812,6 +812,7 @@ var templateViewsMap = map[string]string{
{{ end }}
<h3>Pinboard</h3>
<div class="form-section">
<label>
<input type="checkbox" name="pinboard_enabled" value="1" {{ if .form.PinboardEnabled }}checked{{ end }}> {{ t "Enable Pinboard" }}
</label>
@ -825,6 +826,20 @@ var templateViewsMap = map[string]string{
<label>
<input type="checkbox" name="pinboard_mark_as_unread" value="1" {{ if .form.PinboardMarkAsUnread }}checked{{ end }}> {{ t "Mark bookmark as unread" }}
</label>
</div>
<h3>Instapaper</h3>
<div class="form-section">
<label>
<input type="checkbox" name="instapaper_enabled" value="1" {{ if .form.InstapaperEnabled }}checked{{ end }}> {{ t "Enable Instapaper" }}
</label>
<label for="form-instapaper-username">{{ t "Instapaper Username" }}</label>
<input type="text" name="instapaper_username" id="form-instapaper-username" value="{{ .form.InstapaperUsername }}">
<label for="form-instapaper-password">{{ t "Instapaper Password" }}</label>
<input type="password" name="instapaper_password" id="form-instapaper-password" value="{{ .form.InstapaperPassword }}">
</div>
<div class="buttons">
<button type="submit" class="button button-primary" data-label-loading="{{ t "Loading..." }}">{{ t "Update" }}</button>
@ -1145,7 +1160,7 @@ var templateViewsMapChecksums = map[string]string{
"feeds": "c22af39b42ba9ca69ea0914ca789303ec2c5b484abcd4eaa49016e365381257c",
"history": "9a67599a5d8d67ef958e3f07da339b749f42892667547c9e60a54477e8d32a56",
"import": "73b5112e20bfd232bf73334544186ea419505936bc237d481517a8622901878f",
"integrations": "e3cb653bf3d45fada18b64c53860fcae18a9a3f18162d42c56b290cd1aaa4e18",
"integrations": "4e51fabe73b4ee2c2268f77dbbf7987c2a176c5a5714ea29ac31986928f22b8a",
"login": "04f3ce79bfa5753f69e0d956c2a8999c0da549c7925634a3e8134975da0b0e0f",
"sessions": "878dbe8f8ea783b44130c495814179519fa5c3aa2666ac87508f94d58dd008bf",
"settings": "ea2505b9d0a6d6bb594dba87a92079de19baa6d494f0651693a7685489fb7de9",

View file

@ -6,9 +6,8 @@ package controller
import (
"errors"
"log"
"github.com/miniflux/miniflux2/integration/pinboard"
"github.com/miniflux/miniflux2/integration"
"github.com/miniflux/miniflux2/model"
"github.com/miniflux/miniflux2/server/core"
"github.com/miniflux/miniflux2/server/ui/form"
@ -36,6 +35,9 @@ func (c *Controller) ShowIntegrations(ctx *core.Context, request *core.Request,
PinboardToken: integration.PinboardToken,
PinboardTags: integration.PinboardTags,
PinboardMarkAsUnread: integration.PinboardMarkAsUnread,
InstapaperEnabled: integration.InstapaperEnabled,
InstapaperUsername: integration.InstapaperUsername,
InstapaperPassword: integration.InstapaperPassword,
},
}))
}
@ -85,20 +87,14 @@ func (c *Controller) SaveEntry(ctx *core.Context, request *core.Request, respons
return
}
integration, err := c.store.Integration(user.ID)
settings, 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)
}
}
integration.SendEntry(entry, settings)
}()
response.JSON().Created(map[string]string{"message": "saved"})

View file

@ -16,6 +16,9 @@ type IntegrationForm struct {
PinboardToken string
PinboardTags string
PinboardMarkAsUnread bool
InstapaperEnabled bool
InstapaperUsername string
InstapaperPassword string
}
// Merge copy form values to the model.
@ -24,6 +27,9 @@ func (i IntegrationForm) Merge(integration *model.Integration) {
integration.PinboardToken = i.PinboardToken
integration.PinboardTags = i.PinboardTags
integration.PinboardMarkAsUnread = i.PinboardMarkAsUnread
integration.InstapaperEnabled = i.InstapaperEnabled
integration.InstapaperUsername = i.InstapaperUsername
integration.InstapaperPassword = i.InstapaperPassword
}
// NewIntegrationForm returns a new AuthForm.
@ -33,5 +39,8 @@ func NewIntegrationForm(r *http.Request) *IntegrationForm {
PinboardToken: r.FormValue("pinboard_token"),
PinboardTags: r.FormValue("pinboard_tags"),
PinboardMarkAsUnread: r.FormValue("pinboard_mark_as_unread") == "1",
InstapaperEnabled: r.FormValue("instapaper_enabled") == "1",
InstapaperUsername: r.FormValue("instapaper_username"),
InstapaperPassword: r.FormValue("instapaper_password"),
}
}

View file

@ -4,5 +4,8 @@ create table integrations (
pinboard_token text default '',
pinboard_tags text default 'miniflux',
pinboard_mark_as_unread bool default 'f',
instapaper_enabled bool default 'f',
instapaper_username text default '',
instapaper_password text default '',
primary key(user_id)
)

View file

@ -1,5 +1,5 @@
// Code generated by go generate; DO NOT EDIT.
// 2017-12-02 19:31:37.017577269 -0800 PST m=+0.002518395
// 2017-12-02 21:11:24.01125036 -0800 PST m=+0.002424208
package sql
@ -127,6 +127,9 @@ alter table users add column entry_direction entry_sorting_direction default 'as
pinboard_token text default '',
pinboard_tags text default 'miniflux',
pinboard_mark_as_unread bool default 'f',
instapaper_enabled bool default 'f',
instapaper_username text default '',
instapaper_password text default '',
primary key(user_id)
)
`,
@ -137,5 +140,5 @@ var SqlMapChecksums = map[string]string{
"schema_version_2": "e8e9ff32478df04fcddad10a34cba2e8bb1e67e7977b5bd6cdc4c31ec94282b4",
"schema_version_3": "a54745dbc1c51c000f74d4e5068f1e2f43e83309f023415b1749a47d5c1e0f12",
"schema_version_4": "216ea3a7d3e1704e40c797b5dc47456517c27dbb6ca98bf88812f4f63d74b5d9",
"schema_version_5": "69c0aff4d72f86a3f3c3cac33674a943d4f293dd88a8552706144814a85b5629",
"schema_version_5": "4e7958c01f15def3f8619fc5bee6f0d99e773353aeea08188f77ef089fc9d3e7",
}

View file

@ -18,7 +18,10 @@ func (s *Storage) Integration(userID int64) (*model.Integration, error) {
pinboard_enabled,
pinboard_token,
pinboard_tags,
pinboard_mark_as_unread
pinboard_mark_as_unread,
instapaper_enabled,
instapaper_username,
instapaper_password
FROM integrations
WHERE user_id=$1
`
@ -29,6 +32,9 @@ func (s *Storage) Integration(userID int64) (*model.Integration, error) {
&integration.PinboardToken,
&integration.PinboardTags,
&integration.PinboardMarkAsUnread,
&integration.InstapaperEnabled,
&integration.InstapaperUsername,
&integration.InstapaperPassword,
)
switch {
case err == sql.ErrNoRows:
@ -47,8 +53,11 @@ func (s *Storage) UpdateIntegration(integration *model.Integration) error {
pinboard_enabled=$1,
pinboard_token=$2,
pinboard_tags=$3,
pinboard_mark_as_unread=$4
WHERE user_id=$5
pinboard_mark_as_unread=$4,
instapaper_enabled=$5,
instapaper_username=$6,
instapaper_password=$7
WHERE user_id=$8
`
_, err := s.db.Exec(
query,
@ -56,6 +65,9 @@ func (s *Storage) UpdateIntegration(integration *model.Integration) error {
integration.PinboardToken,
integration.PinboardTags,
integration.PinboardMarkAsUnread,
integration.InstapaperEnabled,
integration.InstapaperUsername,
integration.InstapaperPassword,
integration.UserID,
)