Offer the possibility to set Pocket Consumer Key as environment variable
This commit is contained in:
parent
44decae557
commit
b270159aae
10 changed files with 31 additions and 19 deletions
|
@ -197,6 +197,11 @@ func (c *Config) CreateAdmin() bool {
|
|||
return c.get("CREATE_ADMIN", "") != ""
|
||||
}
|
||||
|
||||
// PocketConsumerKey returns the Pocket Consumer Key if defined as environment variable.
|
||||
func (c *Config) PocketConsumerKey(defaultValue string) string {
|
||||
return c.get("POCKET_CONSUMER_KEY", defaultValue)
|
||||
}
|
||||
|
||||
// NewConfig returns a new Config.
|
||||
func NewConfig() *Config {
|
||||
return &Config{IsHTTPS: os.Getenv("HTTPS") != ""}
|
||||
|
|
|
@ -25,7 +25,7 @@ func routes(cfg *config.Config, store *storage.Storage, feedHandler *feed.Handle
|
|||
router := mux.NewRouter()
|
||||
templateEngine := template.NewEngine(cfg, router, translator)
|
||||
apiController := api.NewController(store, feedHandler)
|
||||
feverController := fever.NewController(store)
|
||||
feverController := fever.NewController(cfg, store)
|
||||
uiController := ui.NewController(cfg, store, pool, feedHandler, templateEngine, translator, router)
|
||||
middleware := middleware.New(cfg, store, router)
|
||||
|
||||
|
|
|
@ -10,6 +10,7 @@ import (
|
|||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/miniflux/miniflux/config"
|
||||
"github.com/miniflux/miniflux/http/context"
|
||||
"github.com/miniflux/miniflux/http/request"
|
||||
"github.com/miniflux/miniflux/http/response/json"
|
||||
|
@ -128,6 +129,7 @@ type favicon struct {
|
|||
|
||||
// Controller implements the Fever API.
|
||||
type Controller struct {
|
||||
cfg *config.Config
|
||||
store *storage.Storage
|
||||
}
|
||||
|
||||
|
@ -528,7 +530,7 @@ func (c *Controller) handleWriteItems(w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
|
||||
go func() {
|
||||
integration.SendEntry(entry, settings)
|
||||
integration.SendEntry(c.cfg, entry, settings)
|
||||
}()
|
||||
}
|
||||
|
||||
|
@ -642,6 +644,6 @@ func (c *Controller) buildFeedGroups(feeds model.Feeds) []feedsGroups {
|
|||
}
|
||||
|
||||
// NewController returns a new Fever API.
|
||||
func NewController(store *storage.Storage) *Controller {
|
||||
return &Controller{store: store}
|
||||
func NewController(cfg *config.Config, store *storage.Storage) *Controller {
|
||||
return &Controller{cfg, store}
|
||||
}
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
package integration
|
||||
|
||||
import (
|
||||
"github.com/miniflux/miniflux/config"
|
||||
"github.com/miniflux/miniflux/integration/instapaper"
|
||||
"github.com/miniflux/miniflux/integration/nunuxkeeper"
|
||||
"github.com/miniflux/miniflux/integration/pinboard"
|
||||
|
@ -15,7 +16,7 @@ import (
|
|||
)
|
||||
|
||||
// SendEntry send the entry to the activated providers.
|
||||
func SendEntry(entry *model.Entry, integration *model.Integration) {
|
||||
func SendEntry(cfg *config.Config, entry *model.Entry, integration *model.Integration) {
|
||||
if integration.PinboardEnabled {
|
||||
client := pinboard.NewClient(integration.PinboardToken)
|
||||
err := client.AddBookmark(
|
||||
|
@ -63,10 +64,9 @@ func SendEntry(entry *model.Entry, integration *model.Integration) {
|
|||
}
|
||||
|
||||
if integration.PocketEnabled {
|
||||
client := pocket.NewClient(integration.PocketAccessToken, integration.PocketConsumerKey)
|
||||
client := pocket.NewClient(cfg.PocketConsumerKey(integration.PocketConsumerKey), integration.PocketAccessToken)
|
||||
if err := client.AddURL(entry.URL, entry.Title); err != nil {
|
||||
logger.Error("[Integration] UserID #%d: %v", integration.UserID, err)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -12,8 +12,8 @@ import (
|
|||
|
||||
// Client represents a Pocket client.
|
||||
type Client struct {
|
||||
accessToken string
|
||||
consumerKey string
|
||||
accessToken string
|
||||
}
|
||||
|
||||
// AddURL sends a single link to Pocket.
|
||||
|
@ -50,6 +50,6 @@ func (c *Client) AddURL(link, title string) error {
|
|||
}
|
||||
|
||||
// NewClient returns a new Pocket client.
|
||||
func NewClient(accessToken, consumerKey string) *Client {
|
||||
return &Client{accessToken: accessToken, consumerKey: consumerKey}
|
||||
func NewClient(consumerKey, accessToken string) *Client {
|
||||
return &Client{consumerKey, accessToken}
|
||||
}
|
||||
|
|
|
@ -79,8 +79,10 @@
|
|||
<input type="checkbox" name="pocket_enabled" value="1" {{ if .form.PocketEnabled }}checked{{ end }}> {{ t "Save articles to Pocket" }}
|
||||
</label>
|
||||
|
||||
<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 }}">
|
||||
{{ if not .hasPocketConsumerKeyConfigured }}
|
||||
<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 }}">
|
||||
{{ end }}
|
||||
|
||||
<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 }}">
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
// Code generated by go generate; DO NOT EDIT.
|
||||
// 2018-05-20 15:22:33.785042033 -0700 PDT m=+0.016512546
|
||||
// 2018-05-21 12:14:59.39668234 -0700 PDT m=+0.007850936
|
||||
|
||||
package template
|
||||
|
||||
|
@ -892,8 +892,10 @@ var templateViewsMap = map[string]string{
|
|||
<input type="checkbox" name="pocket_enabled" value="1" {{ if .form.PocketEnabled }}checked{{ end }}> {{ t "Save articles to Pocket" }}
|
||||
</label>
|
||||
|
||||
<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 }}">
|
||||
{{ if not .hasPocketConsumerKeyConfigured }}
|
||||
<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 }}">
|
||||
{{ end }}
|
||||
|
||||
<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 }}">
|
||||
|
@ -1263,7 +1265,7 @@ var templateViewsMapChecksums = map[string]string{
|
|||
"feeds": "2a5abe37968ea34a0576dbef52341645cb1fc9562e351382fbf721491da6f4fa",
|
||||
"history_entries": "451f0b202f47c9db5344d3e73862f5b7afbd4323fbdba21b6087866c40f045d3",
|
||||
"import": "73b5112e20bfd232bf73334544186ea419505936bc237d481517a8622901878f",
|
||||
"integrations": "9b31a245d7d10e28a5682ec993b173972b3d69a86e731e8b09cf13a9ecbf6a09",
|
||||
"integrations": "4f93dab2630e6b3bf8bf51fc844e48fc763b8e7d6bb98c3c1692ea43f0e93930",
|
||||
"login": "7d83c3067c02f1f6aafdd8816c7f97a4eb5a5a4bdaaaa4cc1e2fbb9c17ea65e8",
|
||||
"sessions": "3fa79031dd883847eba92fbafe5f535fa3a4e1614bb610f20588b6f8fc8b3624",
|
||||
"settings": "ea2505b9d0a6d6bb594dba87a92079de19baa6d494f0651693a7685489fb7de9",
|
||||
|
|
|
@ -47,7 +47,7 @@ func (c *Controller) SaveEntry(w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
|
||||
go func() {
|
||||
integration.SendEntry(entry, settings)
|
||||
integration.SendEntry(c.cfg, entry, settings)
|
||||
}()
|
||||
|
||||
json.Created(w, map[string]string{"message": "saved"})
|
||||
|
|
|
@ -33,7 +33,7 @@ func (c *Controller) PocketAuthorize(w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
|
||||
sess := session.New(c.store, ctx)
|
||||
connector := pocket.NewConnector(integration.PocketConsumerKey)
|
||||
connector := pocket.NewConnector(c.cfg.PocketConsumerKey(integration.PocketConsumerKey))
|
||||
redirectURL := c.cfg.BaseURL() + route.Path(c.router, "pocketCallback")
|
||||
requestToken, err := connector.RequestToken(redirectURL)
|
||||
if err != nil {
|
||||
|
@ -64,7 +64,7 @@ func (c *Controller) PocketCallback(w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
connector := pocket.NewConnector(integration.PocketConsumerKey)
|
||||
connector := pocket.NewConnector(c.cfg.PocketConsumerKey(integration.PocketConsumerKey))
|
||||
accessToken, err := connector.AccessToken(ctx.PocketRequestToken())
|
||||
if err != nil {
|
||||
logger.Error("[Pocket:Callback] %v", err)
|
||||
|
|
|
@ -61,6 +61,7 @@ func (c *Controller) ShowIntegrations(w http.ResponseWriter, r *http.Request) {
|
|||
view.Set("menu", "settings")
|
||||
view.Set("user", user)
|
||||
view.Set("countUnread", c.store.CountUnreadEntries(user.ID))
|
||||
view.Set("hasPocketConsumerKeyConfigured", c.cfg.PocketConsumerKey("") != "")
|
||||
|
||||
html.OK(w, view.Render("integrations"))
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue