1
0
Fork 0

Add Linkding integration

This commit is contained in:
kencx 2022-05-23 23:53:06 +08:00 committed by Frédéric Guillot
parent 780c9e3696
commit 1658db7f10
23 changed files with 198 additions and 7 deletions

View file

@ -582,4 +582,13 @@ 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 linkding_enabled bool default 'f';
ALTER TABLE integrations ADD COLUMN linkding_url text default '';
ALTER TABLE integrations ADD COLUMN linkding_api_key text default '';
`
_, err = tx.Exec(sql)
return err
},
}

View file

@ -8,6 +8,7 @@ import (
"miniflux.app/config"
"miniflux.app/integration/espial"
"miniflux.app/integration/instapaper"
"miniflux.app/integration/linkding"
"miniflux.app/integration/nunuxkeeper"
"miniflux.app/integration/pinboard"
"miniflux.app/integration/pocket"
@ -94,6 +95,18 @@ func SendEntry(entry *model.Entry, integration *model.Integration) {
logger.Error("[Integration] UserID #%d: %v", integration.UserID, err)
}
}
if integration.LinkdingEnabled {
logger.Debug("[Integration] Sending Entry #%d %q for User #%d to Linkding", entry.ID, entry.URL, integration.UserID)
client := linkding.NewClient(
integration.LinkdingURL,
integration.LinkdingAPIKey,
)
if err := client.AddEntry(entry.Title, entry.URL); err != nil {
logger.Error("[Integration] UserID #%d: %v", integration.UserID, err)
}
}
}
// PushEntry pushes an entry to third-party providers during feed refreshes.

View file

@ -0,0 +1,74 @@
// 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 linkding // import "miniflux.app/integration/linkding"
import (
"fmt"
"net/url"
"miniflux.app/http/client"
)
// Document structure of a Linkding document
type Document struct {
Url string `json:"url,omitempty"`
Title string `json:"title,omitempty"`
}
// Client represents an Linkding client.
type Client struct {
baseURL string
apiKey string
}
// NewClient returns a new Linkding client.
func NewClient(baseURL, apiKey string) *Client {
return &Client{baseURL: baseURL, apiKey: apiKey}
}
// AddEntry sends an entry to Linkding.
func (c *Client) AddEntry(title, url string) error {
if c.baseURL == "" || c.apiKey == "" {
return fmt.Errorf("linkding: missing credentials")
}
doc := &Document{
Url: url,
Title: title,
}
apiURL, err := getAPIEndpoint(c.baseURL, "/api/bookmarks/")
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("linkding: unable to send entry: %v", err)
}
if response.HasServerFailure() {
return fmt.Errorf("linkding: unable to send entry, status=%d", response.StatusCode)
}
return nil
}
func getAPIEndpoint(baseURL, pathURL string) (string, error) {
u, err := url.Parse(baseURL)
if err != nil {
return "", fmt.Errorf("linkding: invalid API endpoint: %v", err)
}
relative, err := url.Parse(pathURL)
if err != nil {
return "", fmt.Errorf("linkding: invalid API endpoint: %v", err)
}
u = u.ResolveReference(relative)
return u.String(), nil
}

View file

@ -342,6 +342,9 @@
"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",
"form.integration.linkding_activate": "Artikel in Linkding speichern",
"form.integration.linkding_endpoint": "Linkding API-Endpunkt",
"form.integration.linkding_api_key": "Linkding API-Schlüssel",
"form.api_key.label.description": "API-Schlüsselbezeichnung",
"form.submit.loading": "Lade...",
"form.submit.saving": "Speichern...",

View file

@ -342,6 +342,9 @@
"form.integration.telegram_bot_activate": "Προωθήστε νέα άρθρα στη συνομιλία Telegram",
"form.integration.telegram_bot_token": "Διακριτικό bot",
"form.integration.telegram_chat_id": "Αναγνωριστικό συνομιλίας",
"form.integration.linkding_activate": "Αποθήκευση άρθρων στο Linkding",
"form.integration.linkding_endpoint": "Τελικό σημείο Linkding API",
"form.integration.linkding_api_key": "Κλειδί API Linkding",
"form.api_key.label.description": "Ετικέτα κλειδιού API",
"form.submit.loading": "Φόρτωση...",
"form.submit.saving": "Αποθήκευση...",

View file

@ -342,6 +342,9 @@
"form.integration.telegram_bot_activate": "Push new articles to Telegram chat",
"form.integration.telegram_bot_token": "Bot token",
"form.integration.telegram_chat_id": "Chat ID",
"form.integration.linkding_activate": "Save articles to Linkding",
"form.integration.linkding_endpoint": "Linkding API Endpoint",
"form.integration.linkding_api_key": "Linkding API key",
"form.api_key.label.description": "API Key Label",
"form.submit.loading": "Loading...",
"form.submit.saving": "Saving...",

View file

@ -342,6 +342,9 @@
"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",
"form.integration.linkding_activate": "Guardar artículos a Linkding",
"form.integration.linkding_endpoint": "Extremo de API de Linkding",
"form.integration.linkding_api_key": "Clave de API de Linkding",
"form.api_key.label.description": "Etiqueta de clave API",
"form.submit.loading": "Cargando...",
"form.submit.saving": "Guardando...",

View file

@ -342,6 +342,9 @@
"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",
"form.integration.linkding_activate": "Tallenna artikkelit Linkkiin",
"form.integration.linkding_endpoint": "Linkding API-päätepiste",
"form.integration.linkding_api_key": "Linkding API-avain",
"form.api_key.label.description": "API Key Label",
"form.submit.loading": "Ladataan...",
"form.submit.saving": "Tallennetaan...",

View file

@ -342,6 +342,9 @@
"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",
"form.integration.linkding_activate": "Sauvegarder les articles vers Linkding",
"form.integration.linkding_endpoint": "URL de l'API de Linkding",
"form.integration.linkding_api_key": "Clé d'API de Linkding",
"form.api_key.label.description": "Libellé de la clé d'API",
"form.submit.loading": "Chargement...",
"form.submit.saving": "Sauvegarde en cours...",

View file

@ -342,6 +342,9 @@
"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",
"form.integration.linkding_activate": "Salva gli articoli su Linkding",
"form.integration.linkding_endpoint": "Endpoint dell'API di Linkding",
"form.integration.linkding_api_key": "API key dell'account Linkding",
"form.api_key.label.description": "Etichetta chiave API",
"form.submit.loading": "Caricamento in corso...",
"form.submit.saving": "Salvataggio in corso...",

View file

@ -342,6 +342,9 @@
"form.integration.telegram_bot_activate": "新しい記事をTelegramチャットにプッシュする",
"form.integration.telegram_bot_token": "ボットトークン",
"form.integration.telegram_chat_id": "チャットID",
"form.integration.linkding_activate": "Linkding に記事を保存する",
"form.integration.linkding_endpoint": "Linkding の API Endpoint",
"form.integration.linkding_api_key": "Linkding の API key",
"form.api_key.label.description": "APIキーラベル",
"form.submit.loading": "読み込み中…",
"form.submit.saving": "保存中…",

View file

@ -342,6 +342,9 @@
"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",
"form.integration.linkding_activate": "Opslaan naar Linkding",
"form.integration.linkding_endpoint": "Linkding URL",
"form.integration.linkding_api_key": "Linkding API-sleutel",
"form.api_key.label.description": "API-sleutellabel",
"form.submit.loading": "Laden...",
"form.submit.saving": "Opslaag...",

View file

@ -344,6 +344,9 @@
"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",
"form.integration.linkding_activate": "Zapisz artykuły do Linkding",
"form.integration.linkding_endpoint": "Linkding URL",
"form.integration.linkding_api_key": "Linkding API key",
"form.api_key.label.description": "Etykieta klucza API",
"form.submit.loading": "Ładowanie...",
"form.submit.saving": "Zapisywanie...",

View file

@ -342,6 +342,9 @@
"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",
"form.integration.linkding_activate": "Salvar itens no Linkding",
"form.integration.linkding_endpoint": "Endpoint de API do Linkding",
"form.integration.linkding_api_key": "Chave de API do Linkding",
"form.api_key.label.description": "Etiqueta da chave de API",
"form.submit.loading": "Carregando...",
"form.submit.saving": "Salvando...",

View file

@ -344,6 +344,9 @@
"form.integration.telegram_bot_activate": "Публикуйте новые статьи в Telegram-чате",
"form.integration.telegram_bot_token": "Токен бота",
"form.integration.telegram_chat_id": "ID чата",
"form.integration.linkding_activate": "Сохранять статьи в Linkding",
"form.integration.linkding_endpoint": "Конечная точка Linkding API",
"form.integration.linkding_api_key": "Linkding API key",
"form.api_key.label.description": "Описание API-ключа",
"form.submit.loading": "Загрузка…",
"form.submit.saving": "Сохранение…",

View file

@ -342,6 +342,9 @@
"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",
"form.integration.linkding_activate": "Makaleleri Linkding'e kaydet",
"form.integration.linkding_endpoint": "Linkding API Uç Noktası",
"form.integration.linkding_api_key": "Linkding API Anahtarı",
"form.api_key.label.description": "API Anahtar Etiketi",
"form.submit.loading": "Yükleniyor...",
"form.submit.saving": "Kaydediliyor...",

View file

@ -340,6 +340,9 @@
"form.integration.telegram_bot_activate": "将新文章推送到 Telegram",
"form.integration.telegram_bot_token": "机器人令牌",
"form.integration.telegram_chat_id": "聊天ID",
"form.integration.linkding_activate": "保存文章到 Linkding",
"form.integration.linkding_endpoint": "Linkding API 端点",
"form.integration.linkding_api_key": "Linkding API 密钥",
"form.api_key.label.description": "API密钥标签",
"form.submit.loading": "载入中…",
"form.submit.saving": "保存中…",

View file

@ -342,6 +342,9 @@
"form.integration.telegram_bot_activate": "將新文章推送到 Telegram",
"form.integration.telegram_bot_token": "Bot token",
"form.integration.telegram_chat_id": "Chat ID",
"form.integration.linkding_activate": "儲存文章到 Linkding",
"form.integration.linkding_endpoint": "Linkding API 端點",
"form.integration.linkding_api_key": "Linkding API 金鑰",
"form.api_key.label.description": "API金鑰標籤",
"form.submit.loading": "載入中…",
"form.submit.saving": "儲存中…",

View file

@ -39,4 +39,7 @@ type Integration struct {
TelegramBotEnabled bool
TelegramBotToken string
TelegramBotChatID string
LinkdingEnabled bool
LinkdingURL string
LinkdingAPIKey string
}

View file

@ -142,7 +142,10 @@ func (s *Storage) Integration(userID int64) (*model.Integration, error) {
pocket_consumer_key,
telegram_bot_enabled,
telegram_bot_token,
telegram_bot_chat_id
telegram_bot_chat_id,
linkding_enabled,
linkding_url,
linkding_api_key
FROM
integrations
WHERE
@ -183,6 +186,9 @@ func (s *Storage) Integration(userID int64) (*model.Integration, error) {
&integration.TelegramBotEnabled,
&integration.TelegramBotToken,
&integration.TelegramBotChatID,
&integration.LinkdingEnabled,
&integration.LinkdingURL,
&integration.LinkdingAPIKey,
)
switch {
case err == sql.ErrNoRows:
@ -238,8 +244,11 @@ func (s *Storage) UpdateIntegration(integration *model.Integration) error {
espial_url=$30,
espial_api_key=$31,
espial_tags=$32,
linkding_enabled=$33,
linkding_url=$34,
linkding_api_key=$35
WHERE
user_id=$33
user_id=$36
`
_, err = s.db.Exec(
query,
@ -275,6 +284,9 @@ func (s *Storage) UpdateIntegration(integration *model.Integration) error {
integration.EspialURL,
integration.EspialAPIKey,
integration.EspialTags,
integration.LinkdingEnabled,
integration.LinkdingURL,
integration.LinkdingAPIKey,
integration.UserID,
)
} else {
@ -313,9 +325,12 @@ func (s *Storage) UpdateIntegration(integration *model.Integration) error {
espial_enabled=$29,
espial_url=$30,
espial_api_key=$31,
espial_tags=$32
espial_tags=$32,
linkding_enabled=$33,
linkding_url=$34,
linkding_api_key=$35
WHERE
user_id=$33
user_id=$36
`
_, err = s.db.Exec(
query,
@ -351,6 +366,9 @@ func (s *Storage) UpdateIntegration(integration *model.Integration) error {
integration.EspialURL,
integration.EspialAPIKey,
integration.EspialTags,
integration.LinkdingEnabled,
integration.LinkdingURL,
integration.LinkdingAPIKey,
integration.UserID,
)
}
@ -372,7 +390,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 nunux_keeper_enabled='t' OR espial_enabled='t' OR pocket_enabled='t')
(pinboard_enabled='t' OR instapaper_enabled='t' OR wallabag_enabled='t' OR nunux_keeper_enabled='t' OR espial_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

@ -31,7 +31,7 @@
<button type="submit" class="button button-primary" data-label-loading="{{ t "form.submit.saving" }}">{{ t "action.update" }}</button>
</div>
</div>
<h3>Google Reader</h3>
<div class="form-section">
<label>
@ -150,7 +150,7 @@
<label for="form-nunux-keeper-api-key">{{ t "form.integration.nunux_keeper_api_key" }}</label>
<input type="text" name="nunux_keeper_api_key" id="form-nunux-keeper-api-key" value="{{ .form.NunuxKeeperAPIKey }}" spellcheck="false">
<div class="buttons">
<button type="submit" class="button button-primary" data-label-loading="{{ t "form.submit.saving" }}">{{ t "action.update" }}</button>
</div>
@ -176,6 +176,23 @@
</div>
</div>
<h3>Linkding</h3>
<div class="form-section">
<label>
<input type="checkbox" name="linkding_enabled" value="1" {{ if .form.LinkdingEnabled }}checked{{ end }}> {{ t "form.integration.linkding_activate" }}
</label>
<label for="form-linkding-url">{{ t "form.integration.linkding_endpoint" }}</label>
<input type="url" name="linkding_url" id="form-linkding-url" value="{{ .form.LinkdingURL }}" placeholder="https://linkding.com" spellcheck="false">
<label for="form-linkding-api-key">{{ t "form.integration.linkding_api_key" }}</label>
<input type="text" name="linkding_api_key" id="form-linkding-api-key" value="{{ .form.LinkdingAPIKey }}" spellcheck="false">
<div class="buttons">
<button type="submit" class="button button-primary" data-label-loading="{{ t "form.submit.saving" }}">{{ t "action.update" }}</button>
</div>
</div>
<h3>Telegram Bot</h3>
<div class="form-section">
<label>

View file

@ -44,6 +44,9 @@ type IntegrationForm struct {
TelegramBotEnabled bool
TelegramBotToken string
TelegramBotChatID string
LinkdingEnabled bool
LinkdingURL string
LinkdingAPIKey string
}
// Merge copy form values to the model.
@ -78,6 +81,9 @@ func (i IntegrationForm) Merge(integration *model.Integration) {
integration.TelegramBotEnabled = i.TelegramBotEnabled
integration.TelegramBotToken = i.TelegramBotToken
integration.TelegramBotChatID = i.TelegramBotChatID
integration.LinkdingEnabled = i.LinkdingEnabled
integration.LinkdingURL = i.LinkdingURL
integration.LinkdingAPIKey = i.LinkdingAPIKey
}
// NewIntegrationForm returns a new IntegrationForm.
@ -115,5 +121,8 @@ func NewIntegrationForm(r *http.Request) *IntegrationForm {
TelegramBotEnabled: r.FormValue("telegram_bot_enabled") == "1",
TelegramBotToken: r.FormValue("telegram_bot_token"),
TelegramBotChatID: r.FormValue("telegram_bot_chat_id"),
LinkdingEnabled: r.FormValue("linkding_enabled") == "1",
LinkdingURL: r.FormValue("linkding_url"),
LinkdingAPIKey: r.FormValue("linkding_api_key"),
}
}

View file

@ -59,6 +59,9 @@ func (h *handler) showIntegrationPage(w http.ResponseWriter, r *http.Request) {
TelegramBotEnabled: integration.TelegramBotEnabled,
TelegramBotToken: integration.TelegramBotToken,
TelegramBotChatID: integration.TelegramBotChatID,
LinkdingEnabled: integration.LinkdingEnabled,
LinkdingURL: integration.LinkdingURL,
LinkdingAPIKey: integration.LinkdingAPIKey,
}
sess := session.New(h.store, request.SessionID(r))