1
0
Fork 0

Added integration for Readwise Reader

This commit is contained in:
Corey McCaffrey 2023-07-27 23:51:44 -04:00 committed by GitHub
parent 3aad650622
commit 3bac768cda
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
26 changed files with 178 additions and 3 deletions

View file

@ -716,4 +716,12 @@ var migrations = []func(tx *sql.Tx) error{
_, err = tx.Exec(sql)
return err
},
func(tx *sql.Tx) (err error) {
sql := `
ALTER TABLE integrations ADD COLUMN readwise_enabled bool default 'f';
ALTER TABLE integrations ADD COLUMN readwise_api_key text default '';
`
_, err = tx.Exec(sql)
return err
},
}

View file

@ -13,6 +13,7 @@ import (
"miniflux.app/integration/nunuxkeeper"
"miniflux.app/integration/pinboard"
"miniflux.app/integration/pocket"
"miniflux.app/integration/readwise"
"miniflux.app/integration/telegrambot"
"miniflux.app/integration/wallabag"
"miniflux.app/logger"
@ -123,6 +124,18 @@ func SendEntry(entry *model.Entry, integration *model.Integration) {
logger.Error("[Integration] UserID #%d: %v", integration.UserID, err)
}
}
if integration.ReadwiseEnabled {
logger.Debug("[Integration] Sending Entry #%d %q for User #%d to Readwise Reader", entry.ID, entry.URL, integration.UserID)
client := readwise.NewClient(
integration.ReadwiseAPIKey,
)
if err := client.AddEntry(entry.URL); err != nil {
logger.Error("[Integration] UserID #%d: %v", integration.UserID, err)
}
}
}
// PushEntries pushes an entry array to third-party providers during feed refreshes.

View file

@ -0,0 +1,66 @@
// SPDX-FileCopyrightText: Copyright The Miniflux Authors. All rights reserved.
// SPDX-License-Identifier: Apache-2.0
// Readwise Reader API documentation: https://readwise.io/reader_api
package readwise // import "miniflux.app/integration/readwise"
import (
"fmt"
"net/url"
"miniflux.app/http/client"
)
// Document structure of a Readwise Reader document
// This initial version accepts only the one required field, the URL
type Document struct {
Url string `json:"url"`
}
// Client represents a Readwise Reader client.
type Client struct {
apiKey string
}
// NewClient returns a new Readwise Reader client.
func NewClient(apiKey string) *Client {
return &Client{apiKey: apiKey}
}
// AddEntry sends an entry to Readwise Reader.
func (c *Client) AddEntry(link string) error {
if c.apiKey == "" {
return fmt.Errorf("readwise: missing credentials")
}
doc := &Document{
Url: link,
}
apiURL, err := getAPIEndpoint("https://readwise.io/api/v3/save/")
if err != nil {
return err
}
clt := client.New(apiURL)
clt.WithAuthorization("Token " + c.apiKey)
response, err := clt.PostJSON(doc)
if err != nil {
return fmt.Errorf("readwise: unable to send entry: %v", err)
}
if response.HasServerFailure() {
return fmt.Errorf("readwise: unable to send entry, status=%d", response.StatusCode)
}
return nil
}
func getAPIEndpoint(pathURL string) (string, error) {
u, err := url.Parse(pathURL)
if err != nil {
return "", fmt.Errorf("readwise: invalid API endpoint: %v", err)
}
return u.String(), nil
}

View file

@ -361,6 +361,9 @@
"form.integration.espial_endpoint": "Espial API-Endpunkt",
"form.integration.espial_api_key": "Espial API-Schlüssel",
"form.integration.espial_tags": "Espial tags",
"form.integration.readwise_activate": "Save entries to Readwise Reader",
"form.integration.readwise_api_key": "Readwise Reader Access Token",
"form.integration.readwise_api_key_link": "Get your Readwise Access Token",
"form.integration.telegram_bot_activate": "Pushen Sie neue Artikel in den Telegram-Chat",
"form.integration.telegram_bot_token": "Bot token",
"form.integration.telegram_chat_id": "Chat ID",

View file

@ -361,6 +361,9 @@
"form.integration.espial_endpoint": "Τελικό σημείο Espial API",
"form.integration.espial_api_key": "Κλειδί API Espial",
"form.integration.espial_tags": "Ετικέτες Espial",
"form.integration.readwise_activate": "Save entries to Readwise Reader",
"form.integration.readwise_api_key": "Readwise Reader Access Token",
"form.integration.readwise_api_key_link": "Get your Readwise Access Token",
"form.integration.telegram_bot_activate": "Προωθήστε νέα άρθρα στη συνομιλία Telegram",
"form.integration.telegram_bot_token": "Διακριτικό bot",
"form.integration.telegram_chat_id": "Αναγνωριστικό συνομιλίας",

View file

@ -361,6 +361,9 @@
"form.integration.espial_endpoint": "Espial API Endpoint",
"form.integration.espial_api_key": "Espial API key",
"form.integration.espial_tags": "Espial Tags",
"form.integration.readwise_activate": "Save entries to Readwise Reader",
"form.integration.readwise_api_key": "Readwise Reader Access Token",
"form.integration.readwise_api_key_link": "Get your Readwise Access Token",
"form.integration.telegram_bot_activate": "Push new entries to Telegram chat",
"form.integration.telegram_bot_token": "Bot token",
"form.integration.telegram_chat_id": "Chat ID",

View file

@ -361,6 +361,9 @@
"form.integration.espial_endpoint": "Acceso API de Espial",
"form.integration.espial_api_key": "Clave de API de Espial",
"form.integration.espial_tags": "Etiquetas de Espial",
"form.integration.readwise_activate": "Save entries to Readwise Reader",
"form.integration.readwise_api_key": "Readwise Reader Access Token",
"form.integration.readwise_api_key_link": "Get your Readwise Access Token",
"form.integration.telegram_bot_activate": "Envíe nuevos artículos al chat de Telegram",
"form.integration.telegram_bot_token": "Token de bot",
"form.integration.telegram_chat_id": "ID de chat",

View file

@ -361,6 +361,9 @@
"form.integration.espial_endpoint": "Espial API-päätepiste",
"form.integration.espial_api_key": "Espial API-avain",
"form.integration.espial_tags": "Espial-tagit",
"form.integration.readwise_activate": "Save entries to Readwise Reader",
"form.integration.readwise_api_key": "Readwise Reader Access Token",
"form.integration.readwise_api_key_link": "Get your Readwise Access Token",
"form.integration.telegram_bot_activate": "Lähetä uusia artikkeleita Telegram-chatiin",
"form.integration.telegram_bot_token": "Bot-tunnus",
"form.integration.telegram_chat_id": "Chat ID",

View file

@ -361,6 +361,9 @@
"form.integration.espial_endpoint": "URL de l'API de Espial",
"form.integration.espial_api_key": "Clé d'API de Espial",
"form.integration.espial_tags": "Libellés de Espial",
"form.integration.readwise_activate": "Save entries to Readwise Reader",
"form.integration.readwise_api_key": "Readwise Reader Access Token",
"form.integration.readwise_api_key_link": "Get your Readwise Access Token",
"form.integration.telegram_bot_activate": "Envoyer les nouveaux articles vers Telegram",
"form.integration.telegram_bot_token": "Jeton de sécurité de l'API du Bot Telegram",
"form.integration.telegram_chat_id": "Identifiant de discussion",

View file

@ -361,6 +361,9 @@
"form.integration.espial_endpoint": "जासूसी एपीआई समापन बिंदु",
"form.integration.espial_api_key": "जासूसी एपीआई कुंजी",
"form.integration.espial_tags": "जासूसी टैग",
"form.integration.readwise_activate": "Save entries to Readwise Reader",
"form.integration.readwise_api_key": "Readwise Reader Access Token",
"form.integration.readwise_api_key_link": "Get your Readwise Access Token",
"form.integration.telegram_bot_activate": "टेलीग्राम चैट के लिए नई विषय-कविता पुश करें",
"form.integration.telegram_bot_token": "बॉट टोकन",
"form.integration.telegram_chat_id": "चैट आईडी",

View file

@ -358,6 +358,9 @@
"form.integration.espial_endpoint": "Titik URL API Espial",
"form.integration.espial_api_key": "Kunci API Espial",
"form.integration.espial_tags": "Tanda di Espial",
"form.integration.readwise_activate": "Save entries to Readwise Reader",
"form.integration.readwise_api_key": "Readwise Reader Access Token",
"form.integration.readwise_api_key_link": "Get your Readwise Access Token",
"form.integration.telegram_bot_activate": "Kirim artikel baru ke percakapan Telegram",
"form.integration.telegram_bot_token": "Token Bot",
"form.integration.telegram_chat_id": "ID Obrolan",

View file

@ -361,6 +361,9 @@
"form.integration.espial_endpoint": "Endpoint dell'API di Espial",
"form.integration.espial_api_key": "API key dell'account Espial",
"form.integration.espial_tags": "Tag di Espial",
"form.integration.readwise_activate": "Save entries to Readwise Reader",
"form.integration.readwise_api_key": "Readwise Reader Access Token",
"form.integration.readwise_api_key_link": "Get your Readwise Access Token",
"form.integration.telegram_bot_activate": "Invia nuovi articoli alla chat di Telegram",
"form.integration.telegram_bot_token": "Token bot",
"form.integration.telegram_chat_id": "ID chat",

View file

@ -361,6 +361,9 @@
"form.integration.espial_endpoint": "Espial の API Endpoint",
"form.integration.espial_api_key": "Espial の API key",
"form.integration.espial_tags": "Espial の Tag",
"form.integration.readwise_activate": "Save entries to Readwise Reader",
"form.integration.readwise_api_key": "Readwise Reader Access Token",
"form.integration.readwise_api_key_link": "Get your Readwise Access Token",
"form.integration.telegram_bot_activate": "新しい記事を Telegram チャットにプッシュする",
"form.integration.telegram_bot_token": "ボットトークン",
"form.integration.telegram_chat_id": "チャット ID",

View file

@ -361,6 +361,9 @@
"form.integration.espial_endpoint": "Espial URL",
"form.integration.espial_api_key": "Espial API-sleutel",
"form.integration.espial_tags": "Espial tags",
"form.integration.readwise_activate": "Save entries to Readwise Reader",
"form.integration.readwise_api_key": "Readwise Reader Access Token",
"form.integration.readwise_api_key_link": "Get your Readwise Access Token",
"form.integration.telegram_bot_activate": "Push nieuwe artikelen naar Telegram-chat",
"form.integration.telegram_bot_token": "Bot token",
"form.integration.telegram_chat_id": "Chat ID",

View file

@ -363,6 +363,9 @@
"form.integration.espial_endpoint": "Espial URL",
"form.integration.espial_api_key": "Espial API key",
"form.integration.espial_tags": "Espial Tags",
"form.integration.readwise_activate": "Save entries to Readwise Reader",
"form.integration.readwise_api_key": "Readwise Reader Access Token",
"form.integration.readwise_api_key_link": "Get your Readwise Access Token",
"form.integration.telegram_bot_activate": "Przesyłaj nowe artykuły do czatu Telegram",
"form.integration.telegram_bot_token": "Token bota",
"form.integration.telegram_chat_id": "Identyfikator czatu",

View file

@ -361,6 +361,9 @@
"form.integration.espial_endpoint": "Endpoint de API do Espial",
"form.integration.espial_api_key": "Chave de API do Espial",
"form.integration.espial_tags": "Etiquetas (tags) do Espial",
"form.integration.readwise_activate": "Save entries to Readwise Reader",
"form.integration.readwise_api_key": "Readwise Reader Access Token",
"form.integration.readwise_api_key_link": "Get your Readwise Access Token",
"form.integration.telegram_bot_activate": "Envie novos artigos para o chat do Telegram",
"form.integration.telegram_bot_token": "Token de bot",
"form.integration.telegram_chat_id": "ID de bate-papo",

View file

@ -363,6 +363,9 @@
"form.integration.espial_endpoint": "Конечная точка Espial API",
"form.integration.espial_api_key": "API-ключ Espial",
"form.integration.espial_tags": "Теги Espial",
"form.integration.readwise_activate": "Save entries to Readwise Reader",
"form.integration.readwise_api_key": "Readwise Reader Access Token",
"form.integration.readwise_api_key_link": "Get your Readwise Access Token",
"form.integration.telegram_bot_activate": "Репостить новые статьи в Telegram-чат",
"form.integration.telegram_bot_token": "Токен бота",
"form.integration.telegram_chat_id": "ID чата",

View file

@ -361,6 +361,9 @@
"form.integration.espial_endpoint": "Espial API Uç Noktası",
"form.integration.espial_api_key": "Espial API Anahtarı",
"form.integration.espial_tags": "Espial Etiketleri",
"form.integration.readwise_activate": "Save entries to Readwise Reader",
"form.integration.readwise_api_key": "Readwise Reader Access Token",
"form.integration.readwise_api_key_link": "Get your Readwise Access Token",
"form.integration.telegram_bot_activate": "Yeni makaleleri Telegram sohbetine gönderin",
"form.integration.telegram_bot_token": "Bot jetonu",
"form.integration.telegram_chat_id": "Sohbet kimliği",

View file

@ -360,6 +360,9 @@
"form.integration.espial_endpoint": "Espial API Endpoint",
"form.integration.espial_api_key": "Ключ API Espial",
"form.integration.espial_tags": "Теги для Espial",
"form.integration.readwise_activate": "Save entries to Readwise Reader",
"form.integration.readwise_api_key": "Readwise Reader Access Token",
"form.integration.readwise_api_key_link": "Get your Readwise Access Token",
"form.integration.telegram_bot_activate": "Відправляти нові статті до чату Telegram",
"form.integration.telegram_bot_token": "Токен боту",
"form.integration.telegram_chat_id": "ID чату",

View file

@ -359,6 +359,9 @@
"form.integration.espial_endpoint": "Espial API 端点",
"form.integration.espial_api_key": "Espial API 密钥",
"form.integration.espial_tags": "Espial 标签",
"form.integration.readwise_activate": "Save entries to Readwise Reader",
"form.integration.readwise_api_key": "Readwise Reader Access Token",
"form.integration.readwise_api_key_link": "Get your Readwise Access Token",
"form.integration.telegram_bot_activate": "将新文章推送到 Telegram",
"form.integration.telegram_bot_token": "机器人令牌",
"form.integration.telegram_chat_id": "聊天ID",

View file

@ -361,6 +361,9 @@
"form.integration.espial_endpoint": "Espial API 端點",
"form.integration.espial_api_key": "Espial API 金鑰",
"form.integration.espial_tags": "Espial 標籤",
"form.integration.readwise_activate": "Save entries to Readwise Reader",
"form.integration.readwise_api_key": "Readwise Reader Access Token",
"form.integration.readwise_api_key_link": "Get your Readwise Access Token",
"form.integration.telegram_bot_activate": "將新文章推送到 Telegram",
"form.integration.telegram_bot_token": "Bot token",
"form.integration.telegram_chat_id": "Chat ID",

View file

@ -36,6 +36,8 @@ type Integration struct {
EspialURL string
EspialAPIKey string
EspialTags string
ReadwiseEnabled bool
ReadwiseAPIKey string
PocketEnabled bool
PocketAccessToken string
PocketConsumerKey string

View file

@ -140,6 +140,8 @@ func (s *Storage) Integration(userID int64) (*model.Integration, error) {
espial_url,
espial_api_key,
espial_tags,
readwise_enabled,
readwise_api_key,
pocket_enabled,
pocket_access_token,
pocket_consumer_key,
@ -194,6 +196,8 @@ func (s *Storage) Integration(userID int64) (*model.Integration, error) {
&integration.EspialURL,
&integration.EspialAPIKey,
&integration.EspialTags,
&integration.ReadwiseEnabled,
&integration.ReadwiseAPIKey,
&integration.PocketEnabled,
&integration.PocketAccessToken,
&integration.PocketConsumerKey,
@ -272,9 +276,11 @@ func (s *Storage) UpdateIntegration(integration *model.Integration) error {
matrix_bot_chat_id=$43,
notion_enabled=$44,
notion_token=$45,
notion_page_id=$46
notion_page_id=$46,
readwise_enabled=$47,
readwise_api_key=$48
WHERE
user_id=$47
user_id=$49
`
_, err := s.db.Exec(
query,
@ -324,6 +330,8 @@ func (s *Storage) UpdateIntegration(integration *model.Integration) error {
integration.NotionEnabled,
integration.NotionToken,
integration.NotionPageID,
integration.ReadwiseEnabled,
integration.ReadwiseAPIKey,
integration.UserID,
)
@ -344,7 +352,7 @@ func (s *Storage) HasSaveEntry(userID int64) (result bool) {
WHERE
user_id=$1
AND
(pinboard_enabled='t' OR instapaper_enabled='t' OR wallabag_enabled='t' OR notion_enabled='t' OR nunux_keeper_enabled='t' OR espial_enabled='t' OR pocket_enabled='t' OR linkding_enabled='t')
(pinboard_enabled='t' OR instapaper_enabled='t' OR wallabag_enabled='t' OR notion_enabled='t' OR nunux_keeper_enabled='t' OR espial_enabled='t' OR readwise_enabled='t' OR pocket_enabled='t' OR linkding_enabled='t')
`
if err := s.db.QueryRow(query, userID).Scan(&result); err != nil {
result = false

View file

@ -195,6 +195,22 @@
</div>
</div>
<h3>Readwise Reader</h3>
<div class="form-section">
<label>
<input type="checkbox" name="readwise_enabled" value="1" {{ if .form.ReadwiseEnabled }}checked{{ end }}> {{ t "form.integration.readwise_activate" }}
</label>
<label for="form-readwise-api-key">{{ t "form.integration.readwise_api_key" }}</label>
<input type="text" name="readwise_api_key" id="form-readwise-api-key" value="{{ .form.ReadwiseAPIKey }}" spellcheck="false">
<p><a href="https://readwise.io/access_token" target="_blank">{{ t "form.integration.readwise_api_key_link" }}</a></p>
<div class="buttons">
<button type="submit" class="button button-primary" data-label-loading="{{ t "form.submit.saving" }}">{{ t "action.update" }}</button>
</div>
</div>
<h3>Linkding</h3>
<div class="form-section">
<label>

View file

@ -41,6 +41,8 @@ type IntegrationForm struct {
EspialURL string
EspialAPIKey string
EspialTags string
ReadwiseEnabled bool
ReadwiseAPIKey string
PocketEnabled bool
PocketAccessToken string
PocketConsumerKey string
@ -89,6 +91,8 @@ func (i IntegrationForm) Merge(integration *model.Integration) {
integration.EspialURL = i.EspialURL
integration.EspialAPIKey = i.EspialAPIKey
integration.EspialTags = i.EspialTags
integration.ReadwiseEnabled = i.ReadwiseEnabled
integration.ReadwiseAPIKey = i.ReadwiseAPIKey
integration.PocketEnabled = i.PocketEnabled
integration.PocketAccessToken = i.PocketAccessToken
integration.PocketConsumerKey = i.PocketConsumerKey
@ -140,6 +144,8 @@ func NewIntegrationForm(r *http.Request) *IntegrationForm {
EspialURL: r.FormValue("espial_url"),
EspialAPIKey: r.FormValue("espial_api_key"),
EspialTags: r.FormValue("espial_tags"),
ReadwiseEnabled: r.FormValue("readwise_enabled") == "1",
ReadwiseAPIKey: r.FormValue("readwise_api_key"),
PocketEnabled: r.FormValue("pocket_enabled") == "1",
PocketAccessToken: r.FormValue("pocket_access_token"),
PocketConsumerKey: r.FormValue("pocket_consumer_key"),

View file

@ -56,6 +56,8 @@ func (h *handler) showIntegrationPage(w http.ResponseWriter, r *http.Request) {
EspialURL: integration.EspialURL,
EspialAPIKey: integration.EspialAPIKey,
EspialTags: integration.EspialTags,
ReadwiseEnabled: integration.ReadwiseEnabled,
ReadwiseAPIKey: integration.ReadwiseAPIKey,
PocketEnabled: integration.PocketEnabled,
PocketAccessToken: integration.PocketAccessToken,
PocketConsumerKey: integration.PocketConsumerKey,