Add Pocket integration
This commit is contained in:
parent
f19ab21b7d
commit
0f3f5e442f
16 changed files with 137 additions and 15 deletions
|
@ -8,6 +8,7 @@ import (
|
|||
"github.com/miniflux/miniflux/integration/instapaper"
|
||||
"github.com/miniflux/miniflux/integration/nunuxkeeper"
|
||||
"github.com/miniflux/miniflux/integration/pinboard"
|
||||
"github.com/miniflux/miniflux/integration/pocket"
|
||||
"github.com/miniflux/miniflux/integration/wallabag"
|
||||
"github.com/miniflux/miniflux/logger"
|
||||
"github.com/miniflux/miniflux/model"
|
||||
|
@ -60,4 +61,12 @@ func SendEntry(entry *model.Entry, integration *model.Integration) {
|
|||
logger.Error("[Integration] UserID #%d: %v", integration.UserID, err)
|
||||
}
|
||||
}
|
||||
|
||||
if integration.PocketEnabled {
|
||||
client := pocket.NewClient(integration.PocketAccessToken, integration.PocketConsumerKey)
|
||||
if err := client.AddURL(entry.URL, entry.Title); err != nil {
|
||||
logger.Error("[Integration] UserID #%d: %v", integration.UserID, err)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
52
integration/pocket/pocket.go
Normal file
52
integration/pocket/pocket.go
Normal file
|
@ -0,0 +1,52 @@
|
|||
// 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 pocket
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/miniflux/miniflux/http/client"
|
||||
)
|
||||
|
||||
// Client represents a Pocket client.
|
||||
type Client struct {
|
||||
accessToken string
|
||||
consumerKey string
|
||||
}
|
||||
|
||||
// Parameters for a Pocket add call.
|
||||
type Parameters struct {
|
||||
AccessToken string `json:"access_token"`
|
||||
ConsumerKey string `json:"consumer_key"`
|
||||
Title string `json:"title,omitempty"`
|
||||
URL string `json:"url,omitempty"`
|
||||
}
|
||||
|
||||
// AddURL sends a single link to Pocket.
|
||||
func (c *Client) AddURL(link, title string) error {
|
||||
if c.consumerKey == "" || c.accessToken == "" {
|
||||
return fmt.Errorf("pocket: missing credentials")
|
||||
}
|
||||
|
||||
parameters := &Parameters{
|
||||
AccessToken: c.accessToken,
|
||||
ConsumerKey: c.consumerKey,
|
||||
Title: title,
|
||||
URL: link,
|
||||
}
|
||||
|
||||
clt := client.New("https://getpocket.com/v3/add")
|
||||
response, err := clt.PostJSON(parameters)
|
||||
if response.HasServerFailure() {
|
||||
return fmt.Errorf("pocket: unable to send url, status=%d", response.StatusCode)
|
||||
}
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
// NewClient returns a new Pocket client.
|
||||
func NewClient(accessToken, consumerKey string) *Client {
|
||||
return &Client{accessToken: accessToken, consumerKey: consumerKey}
|
||||
}
|
|
@ -1,5 +1,5 @@
|
|||
// Code generated by go generate; DO NOT EDIT.
|
||||
// 2018-04-29 16:59:49.591693595 -0700 PDT m=+0.022587229
|
||||
// 2018-05-20 11:35:19.498340382 -0700 PDT m=+0.010175046
|
||||
|
||||
package locale
|
||||
|
||||
|
|
|
@ -27,4 +27,7 @@ type Integration struct {
|
|||
NunuxKeeperEnabled bool
|
||||
NunuxKeeperURL string
|
||||
NunuxKeeperAPIKey string
|
||||
PocketEnabled bool
|
||||
PocketAccessToken string
|
||||
PocketConsumerKey string
|
||||
}
|
||||
|
|
3
sql/schema_version_17.sql
Normal file
3
sql/schema_version_17.sql
Normal file
|
@ -0,0 +1,3 @@
|
|||
alter table integrations add column pocket_enabled bool default 'f';
|
||||
alter table integrations add column pocket_access_token text default '';
|
||||
alter table integrations add column pocket_consumer_key text default '';
|
|
@ -1,5 +1,5 @@
|
|||
// Code generated by go generate; DO NOT EDIT.
|
||||
// 2018-04-06 23:00:49.983090069 +0100 BST m=+0.002610702
|
||||
// 2018-05-20 11:35:19.489434225 -0700 PDT m=+0.001268896
|
||||
|
||||
package sql
|
||||
|
||||
|
@ -131,6 +131,10 @@ alter table integrations add column nunux_keeper_url text default '';
|
|||
alter table integrations add column nunux_keeper_api_key text default '';`,
|
||||
"schema_version_15": `alter table enclosures alter column size set data type bigint;`,
|
||||
"schema_version_16": `alter table entries add column comments_url text default '';`,
|
||||
"schema_version_17": `alter table integrations add column pocket_enabled bool default 'f';
|
||||
alter table integrations add column pocket_access_token text default '';
|
||||
alter table integrations add column pocket_consumer_key text default '';
|
||||
`,
|
||||
"schema_version_2": `create extension if not exists hstore;
|
||||
alter table users add column extra hstore;
|
||||
create index users_extra_idx on users using gin(extra);
|
||||
|
@ -178,6 +182,7 @@ var SqlMapChecksums = map[string]string{
|
|||
"schema_version_14": "4622e42c4a5a88b6fe1e61f3d367b295968f7260ab5b96481760775ba9f9e1fe",
|
||||
"schema_version_15": "13ff91462bdf4cda5a94a4c7a09f757761b0f2c32b4be713ba4786a4837750e4",
|
||||
"schema_version_16": "9d006faca62fd7ab787f64aef0e0a5933d142466ec4cab0e096bb920d2797e34",
|
||||
"schema_version_17": "b9f15d6217275fedcf6d948dd85ebe978b869bf37f42a86fd5b50a51919fa0e1",
|
||||
"schema_version_2": "e8e9ff32478df04fcddad10a34cba2e8bb1e67e7977b5bd6cdc4c31ec94282b4",
|
||||
"schema_version_3": "a54745dbc1c51c000f74d4e5068f1e2f43e83309f023415b1749a47d5c1e0f12",
|
||||
"schema_version_4": "216ea3a7d3e1704e40c797b5dc47456517c27dbb6ca98bf88812f4f63d74b5d9",
|
||||
|
|
|
@ -70,7 +70,10 @@ func (s *Storage) Integration(userID int64) (*model.Integration, error) {
|
|||
wallabag_password,
|
||||
nunux_keeper_enabled,
|
||||
nunux_keeper_url,
|
||||
nunux_keeper_api_key
|
||||
nunux_keeper_api_key,
|
||||
pocket_enabled,
|
||||
pocket_access_token,
|
||||
pocket_consumer_key
|
||||
FROM integrations
|
||||
WHERE user_id=$1
|
||||
`
|
||||
|
@ -97,6 +100,9 @@ func (s *Storage) Integration(userID int64) (*model.Integration, error) {
|
|||
&integration.NunuxKeeperEnabled,
|
||||
&integration.NunuxKeeperURL,
|
||||
&integration.NunuxKeeperAPIKey,
|
||||
&integration.PocketEnabled,
|
||||
&integration.PocketAccessToken,
|
||||
&integration.PocketConsumerKey,
|
||||
)
|
||||
switch {
|
||||
case err == sql.ErrNoRows:
|
||||
|
@ -131,8 +137,11 @@ func (s *Storage) UpdateIntegration(integration *model.Integration) error {
|
|||
wallabag_password=$17,
|
||||
nunux_keeper_enabled=$18,
|
||||
nunux_keeper_url=$19,
|
||||
nunux_keeper_api_key=$20
|
||||
WHERE user_id=$21
|
||||
nunux_keeper_api_key=$20,
|
||||
pocket_enabled=$21,
|
||||
pocket_access_token=$22,
|
||||
pocket_consumer_key=$23
|
||||
WHERE user_id=$24
|
||||
`
|
||||
_, err := s.db.Exec(
|
||||
query,
|
||||
|
@ -156,6 +165,9 @@ func (s *Storage) UpdateIntegration(integration *model.Integration) error {
|
|||
integration.NunuxKeeperEnabled,
|
||||
integration.NunuxKeeperURL,
|
||||
integration.NunuxKeeperAPIKey,
|
||||
integration.PocketEnabled,
|
||||
integration.PocketAccessToken,
|
||||
integration.PocketConsumerKey,
|
||||
integration.UserID,
|
||||
)
|
||||
|
||||
|
@ -182,7 +194,7 @@ func (s *Storage) HasSaveEntry(userID int64) (result bool) {
|
|||
query := `
|
||||
SELECT true FROM integrations
|
||||
WHERE user_id=$1 AND
|
||||
(pinboard_enabled='t' OR instapaper_enabled='t' OR wallabag_enabled='t' OR nunux_keeper_enabled='t')
|
||||
(pinboard_enabled='t' OR instapaper_enabled='t' OR wallabag_enabled='t' OR nunux_keeper_enabled='t' OR pocket_enabled='t')
|
||||
`
|
||||
|
||||
if err := s.db.QueryRow(query, userID).Scan(&result); err != nil {
|
||||
|
|
|
@ -12,7 +12,7 @@ import (
|
|||
"github.com/miniflux/miniflux/sql"
|
||||
)
|
||||
|
||||
const schemaVersion = 16
|
||||
const schemaVersion = 17
|
||||
|
||||
// Migrate run database migrations.
|
||||
func (s *Storage) Migrate() {
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
// Code generated by go generate; DO NOT EDIT.
|
||||
// 2018-04-29 17:36:50.459886967 -0700 PDT m=+0.024552529
|
||||
// 2018-05-20 11:35:19.497832269 -0700 PDT m=+0.009666945
|
||||
|
||||
package template
|
||||
|
||||
|
|
|
@ -94,7 +94,7 @@
|
|||
<label for="form-wallabag-password">{{ t "Wallabag Password" }}</label>
|
||||
<input type="password" name="wallabag_password" id="form-wallabag-password" value="{{ .form.WallabagPassword }}">
|
||||
</div>
|
||||
|
||||
|
||||
<h3>Nunux Keeper</h3>
|
||||
<div class="form-section">
|
||||
<label>
|
||||
|
@ -108,6 +108,19 @@
|
|||
<input type="text" name="nunux_keeper_api_key" id="form-nunux-keeper-api-key" value="{{ .form.NunuxKeeperAPIKey }}">
|
||||
</div>
|
||||
|
||||
<h3>Pocket</h3>
|
||||
<div class="form-section">
|
||||
<label>
|
||||
<input type="checkbox" name="pocket_enabled" value="1" {{ if .form.PocketEnabled }}checked{{ end }}> {{ t "Save articles to Pocket" }}
|
||||
</label>
|
||||
|
||||
<label for="form-pocket-access-token">{{ t "Pocket Access Token" }}</label>
|
||||
<input type="password" name="pocket_access_token" id="form-pocket-access-token" value="{{ .form.PocketAccessToken }}">
|
||||
|
||||
<label for="form-pocket-consumer-key">{{ t "Pocket Consumer Key" }}</label>
|
||||
<input type="text" name="pocket_consumer_key" id="form-pocket-consumer-key" value="{{ .form.PocketConsumerKey }}">
|
||||
</div>
|
||||
|
||||
<div class="buttons">
|
||||
<button type="submit" class="button button-primary" data-label-loading="{{ t "Loading..." }}">{{ t "Update" }}</button>
|
||||
</div>
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
// Code generated by go generate; DO NOT EDIT.
|
||||
// 2018-04-29 17:36:50.450844913 -0700 PDT m=+0.015510475
|
||||
// 2018-05-20 11:35:19.495047296 -0700 PDT m=+0.006881961
|
||||
|
||||
package template
|
||||
|
||||
|
@ -907,7 +907,7 @@ var templateViewsMap = map[string]string{
|
|||
<label for="form-wallabag-password">{{ t "Wallabag Password" }}</label>
|
||||
<input type="password" name="wallabag_password" id="form-wallabag-password" value="{{ .form.WallabagPassword }}">
|
||||
</div>
|
||||
|
||||
|
||||
<h3>Nunux Keeper</h3>
|
||||
<div class="form-section">
|
||||
<label>
|
||||
|
@ -921,6 +921,19 @@ var templateViewsMap = map[string]string{
|
|||
<input type="text" name="nunux_keeper_api_key" id="form-nunux-keeper-api-key" value="{{ .form.NunuxKeeperAPIKey }}">
|
||||
</div>
|
||||
|
||||
<h3>Pocket</h3>
|
||||
<div class="form-section">
|
||||
<label>
|
||||
<input type="checkbox" name="pocket_enabled" value="1" {{ if .form.PocketEnabled }}checked{{ end }}> {{ t "Save articles to Pocket" }}
|
||||
</label>
|
||||
|
||||
<label for="form-pocket-access-token">{{ t "Pocket Access Token" }}</label>
|
||||
<input type="password" name="pocket_access_token" id="form-pocket-access-token" value="{{ .form.PocketAccessToken }}">
|
||||
|
||||
<label for="form-pocket-consumer-key">{{ t "Pocket Consumer Key" }}</label>
|
||||
<input type="text" name="pocket_consumer_key" id="form-pocket-consumer-key" value="{{ .form.PocketConsumerKey }}">
|
||||
</div>
|
||||
|
||||
<div class="buttons">
|
||||
<button type="submit" class="button button-primary" data-label-loading="{{ t "Loading..." }}">{{ t "Update" }}</button>
|
||||
</div>
|
||||
|
@ -1246,7 +1259,7 @@ var templateViewsMapChecksums = map[string]string{
|
|||
"feeds": "2a5abe37968ea34a0576dbef52341645cb1fc9562e351382fbf721491da6f4fa",
|
||||
"history_entries": "451f0b202f47c9db5344d3e73862f5b7afbd4323fbdba21b6087866c40f045d3",
|
||||
"import": "73b5112e20bfd232bf73334544186ea419505936bc237d481517a8622901878f",
|
||||
"integrations": "979193f39c2a3b43cec192aa119713cc9cbe2d5fdaedf8d2b3573c752823446c",
|
||||
"integrations": "919b73a7dec91c2973db840eecf709de1e2e004f5a592d7e377ef1cb0926adce",
|
||||
"login": "7d83c3067c02f1f6aafdd8816c7f97a4eb5a5a4bdaaaa4cc1e2fbb9c17ea65e8",
|
||||
"sessions": "3fa79031dd883847eba92fbafe5f535fa3a4e1614bb610f20588b6f8fc8b3624",
|
||||
"settings": "ea2505b9d0a6d6bb594dba87a92079de19baa6d494f0651693a7685489fb7de9",
|
||||
|
|
|
@ -31,6 +31,9 @@ type IntegrationForm struct {
|
|||
NunuxKeeperEnabled bool
|
||||
NunuxKeeperURL string
|
||||
NunuxKeeperAPIKey string
|
||||
PocketEnabled bool
|
||||
PocketAccessToken string
|
||||
PocketConsumerKey string
|
||||
}
|
||||
|
||||
// Merge copy form values to the model.
|
||||
|
@ -54,6 +57,9 @@ func (i IntegrationForm) Merge(integration *model.Integration) {
|
|||
integration.NunuxKeeperEnabled = i.NunuxKeeperEnabled
|
||||
integration.NunuxKeeperURL = i.NunuxKeeperURL
|
||||
integration.NunuxKeeperAPIKey = i.NunuxKeeperAPIKey
|
||||
integration.PocketEnabled = i.PocketEnabled
|
||||
integration.PocketAccessToken = i.PocketAccessToken
|
||||
integration.PocketConsumerKey = i.PocketConsumerKey
|
||||
}
|
||||
|
||||
// NewIntegrationForm returns a new AuthForm.
|
||||
|
@ -78,5 +84,8 @@ func NewIntegrationForm(r *http.Request) *IntegrationForm {
|
|||
NunuxKeeperEnabled: r.FormValue("nunux_keeper_enabled") == "1",
|
||||
NunuxKeeperURL: r.FormValue("nunux_keeper_url"),
|
||||
NunuxKeeperAPIKey: r.FormValue("nunux_keeper_api_key"),
|
||||
PocketEnabled: r.FormValue("pocket_enabled") == "1",
|
||||
PocketAccessToken: r.FormValue("pocket_access_token"),
|
||||
PocketConsumerKey: r.FormValue("pocket_consumer_key"),
|
||||
}
|
||||
}
|
||||
|
|
|
@ -50,6 +50,9 @@ func (c *Controller) ShowIntegrations(w http.ResponseWriter, r *http.Request) {
|
|||
NunuxKeeperEnabled: integration.NunuxKeeperEnabled,
|
||||
NunuxKeeperURL: integration.NunuxKeeperURL,
|
||||
NunuxKeeperAPIKey: integration.NunuxKeeperAPIKey,
|
||||
PocketEnabled: integration.PocketEnabled,
|
||||
PocketAccessToken: integration.PocketAccessToken,
|
||||
PocketConsumerKey: integration.PocketConsumerKey,
|
||||
}
|
||||
|
||||
sess := session.New(c.store, ctx)
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
// Code generated by go generate; DO NOT EDIT.
|
||||
// 2018-02-24 17:47:34.994475549 +0000 GMT
|
||||
// 2018-05-20 11:35:19.492969127 -0700 PDT m=+0.004803782
|
||||
|
||||
package static
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
// Code generated by go generate; DO NOT EDIT.
|
||||
// 2018-05-19 15:45:16.654304958 -0700 PDT m=+0.017095824
|
||||
// 2018-05-20 11:35:19.493979584 -0700 PDT m=+0.005814260
|
||||
|
||||
package static
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
// Code generated by go generate; DO NOT EDIT.
|
||||
// 2018-02-24 17:47:34.995856638 +0000 GMT
|
||||
// 2018-05-20 11:35:19.494515654 -0700 PDT m=+0.006350329
|
||||
|
||||
package static
|
||||
|
||||
|
|
Loading…
Reference in a new issue