Skip to content

Commit

Permalink
Offer the possibility to set Pocket Consumer Key as environment variable
Browse files Browse the repository at this point in the history
  • Loading branch information
fguillot committed May 21, 2018
1 parent 44decae commit b270159
Show file tree
Hide file tree
Showing 10 changed files with 31 additions and 19 deletions.
5 changes: 5 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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") != ""}
Expand Down
2 changes: 1 addition & 1 deletion daemon/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
8 changes: 5 additions & 3 deletions fever/fever.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -128,6 +129,7 @@ type favicon struct {

// Controller implements the Fever API.
type Controller struct {
cfg *config.Config
store *storage.Storage
}

Expand Down Expand Up @@ -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)
}()
}

Expand Down Expand Up @@ -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}
}
6 changes: 3 additions & 3 deletions integration/integration.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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(
Expand Down Expand Up @@ -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)
}
}

}
6 changes: 3 additions & 3 deletions integration/pocket/pocket.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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}
}
6 changes: 4 additions & 2 deletions template/html/integrations.html
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,10 @@ <h3>Pocket</h3>
<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 }}">
Expand Down
10 changes: 6 additions & 4 deletions template/views.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion ui/entry_save.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"})
Expand Down
4 changes: 2 additions & 2 deletions ui/integration_pocket.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions ui/integration_show.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
}

0 comments on commit b270159

Please sign in to comment.