1
0
Fork 0

Add default tag names for Linkding integration

This commit is contained in:
Ryan Cao 2023-05-21 22:29:51 +08:00 committed by Frédéric Guillot
parent 118e18190d
commit c4e2eaa609
26 changed files with 66 additions and 18 deletions

View file

@ -653,4 +653,11 @@ 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_tags text default '';
`
_, err = tx.Exec(sql)
return err
},
}

View file

@ -104,6 +104,7 @@ func SendEntry(entry *model.Entry, integration *model.Integration) {
client := linkding.NewClient(
integration.LinkdingURL,
integration.LinkdingAPIKey,
integration.LinkdingTags,
)
if err := client.AddEntry(entry.Title, entry.URL); err != nil {
logger.Error("[Integration] UserID #%d: %v", integration.UserID, err)

View file

@ -7,25 +7,28 @@ package linkding // import "miniflux.app/integration/linkding"
import (
"fmt"
"net/url"
"strings"
"miniflux.app/http/client"
)
// Document structure of a Linkding document
type Document struct {
Url string `json:"url,omitempty"`
Title string `json:"title,omitempty"`
Url string `json:"url,omitempty"`
Title string `json:"title,omitempty"`
TagNames []string `json:"tag_names,omitempty"`
}
// Client represents an Linkding client.
type Client struct {
baseURL string
apiKey string
tags string
}
// NewClient returns a new Linkding client.
func NewClient(baseURL, apiKey string) *Client {
return &Client{baseURL: baseURL, apiKey: apiKey}
func NewClient(baseURL, apiKey, tags string) *Client {
return &Client{baseURL: baseURL, apiKey: apiKey, tags: tags}
}
// AddEntry sends an entry to Linkding.
@ -34,9 +37,14 @@ func (c *Client) AddEntry(title, url string) error {
return fmt.Errorf("linkding: missing credentials")
}
tagsSplitFn := func(c rune) bool {
return c == ',' || c == ' '
}
doc := &Document{
Url: url,
Title: title,
Url: url,
Title: title,
TagNames: strings.FieldsFunc(c.tags, tagsSplitFn),
}
apiURL, err := getAPIEndpoint(c.baseURL, "/api/bookmarks/")

View file

@ -361,6 +361,7 @@
"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.integration.linkding_tags": "Linkding Tags",
"form.integration.matrix_bot_activate": "Neue Artikel in die Matrix übertragen",
"form.integration.matrix_bot_user": "Benutzername für Matrix",
"form.integration.matrix_bot_password": "Passwort für Matrix-Benutzer",

View file

@ -361,6 +361,7 @@
"form.integration.linkding_activate": "Αποθήκευση άρθρων στο Linkding",
"form.integration.linkding_endpoint": "Τελικό σημείο Linkding API",
"form.integration.linkding_api_key": "Κλειδί API Linkding",
"form.integration.linkding_tags": "Linkding Tags",
"form.integration.matrix_bot_activate": "Μεταφορά νέων άρθρων στο Matrix",
"form.integration.matrix_bot_user": "Όνομα χρήστη για το Matrix",
"form.integration.matrix_bot_password": "Κωδικός πρόσβασης για τον χρήστη Matrix",

View file

@ -361,6 +361,7 @@
"form.integration.linkding_activate": "Save entries to Linkding",
"form.integration.linkding_endpoint": "Linkding API Endpoint",
"form.integration.linkding_api_key": "Linkding API key",
"form.integration.linkding_tags": "Linkding Tags",
"form.integration.matrix_bot_activate": "Push new entries to Matrix",
"form.integration.matrix_bot_user": "Username for Matrix",
"form.integration.matrix_bot_password": "Password for Matrix user",

View file

@ -361,6 +361,7 @@
"form.integration.linkding_activate": "Enviar artículos a Linkding",
"form.integration.linkding_endpoint": "Acceso API de Linkding",
"form.integration.linkding_api_key": "Clave de API de Linkding",
"form.integration.linkding_tags": "Linkding Tags",
"form.integration.matrix_bot_activate": "Transferir nuevos artículos a Matrix",
"form.integration.matrix_bot_user": "Nombre de usuario para Matrix",
"form.integration.matrix_bot_password": "Contraseña para el usuario de Matrix",

View file

@ -361,6 +361,7 @@
"form.integration.linkding_activate": "Tallenna artikkelit Linkkiin",
"form.integration.linkding_endpoint": "Linkding API-päätepiste",
"form.integration.linkding_api_key": "Linkding API-avain",
"form.integration.linkding_tags": "Linkding Tags",
"form.integration.matrix_bot_activate": "Siirrä uudet artikkelit Matrixiin",
"form.integration.matrix_bot_user": "Matrixin käyttäjätunnus",
"form.integration.matrix_bot_password": "Matrix-käyttäjän salasana",

View file

@ -361,6 +361,7 @@
"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.integration.linkding_tags": "Linkding Tags",
"form.integration.matrix_bot_activate": "Envoyer les nouveaux articles vers Matrix",
"form.integration.matrix_bot_user": "Nom de l'utilisateur Matrix",
"form.integration.matrix_bot_password": "Mot de passe de l'utilisateur Matrix",

View file

@ -361,6 +361,7 @@
"form.integration.linkding_activate": "लिंक्डिन में विषयवस्तु सहेजें",
"form.integration.linkding_endpoint": "लिंकिंग एपीआई समापन बिंदु",
"form.integration.linkding_api_key": "लिंकिंग एपीआई कुंजी",
"form.integration.linkding_tags": "Linkding Tags",
"form.integration.matrix_bot_activate": "नए लेखों को मैट्रिक्स में स्थानांतरित करें",
"form.integration.matrix_bot_user": "मैट्रिक्स के लिए उपयोगकर्ता नाम",
"form.integration.matrix_bot_password": "मैट्रिक्स उपयोगकर्ता के लिए पासवर्ड",

View file

@ -358,6 +358,7 @@
"form.integration.linkding_activate": "Simpan artikel ke Linkding",
"form.integration.linkding_endpoint": "Titik URL API Linkding",
"form.integration.linkding_api_key": "Kunci API Linkding",
"form.integration.linkding_tags": "Linkding Tags",
"form.integration.matrix_bot_activate": "Kirim entri baru ke Matrix",
"form.integration.matrix_bot_user": "Nama Pengguna Matrix",
"form.integration.matrix_bot_password": "Kata Sandi Matrix",

View file

@ -361,6 +361,7 @@
"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.integration.linkding_tags": "Linkding Tags",
"form.integration.matrix_bot_activate": "Trasferimento di nuovi articoli a Matrix",
"form.integration.matrix_bot_user": "Nome utente per Matrix",
"form.integration.matrix_bot_password": "Password per l'utente Matrix",

View file

@ -361,6 +361,7 @@
"form.integration.linkding_activate": "Linkding に記事を保存する",
"form.integration.linkding_endpoint": "Linkding の API Endpoint",
"form.integration.linkding_api_key": "Linkding の API key",
"form.integration.linkding_tags": "Linkding Tags",
"form.integration.matrix_bot_activate": "新しい記事をMatrixに転送する",
"form.integration.matrix_bot_user": "Matrixのユーザー名",
"form.integration.matrix_bot_password": "Matrixユーザ用パスワード",

View file

@ -361,6 +361,7 @@
"form.integration.linkding_activate": "Opslaan naar Linkding",
"form.integration.linkding_endpoint": "Linkding URL",
"form.integration.linkding_api_key": "Linkding API-sleutel",
"form.integration.linkding_tags": "Linkding Tags",
"form.integration.matrix_bot_activate": "Nieuwe artikelen overbrengen naar Matrix",
"form.integration.matrix_bot_user": "Gebruikersnaam voor Matrix",
"form.integration.matrix_bot_password": "Wachtwoord voor Matrix-gebruiker",

View file

@ -363,6 +363,7 @@
"form.integration.linkding_activate": "Zapisz artykuły do Linkding",
"form.integration.linkding_endpoint": "Linkding URL",
"form.integration.linkding_api_key": "Linkding API key",
"form.integration.linkding_tags": "Linkding Tags",
"form.integration.matrix_bot_activate": "Przenieś nowe artykuły do Matrix",
"form.integration.matrix_bot_user": "Nazwa użytkownika dla Matrix",
"form.integration.matrix_bot_password": "Hasło dla użytkownika Matrix",

View file

@ -361,6 +361,7 @@
"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.integration.linkding_tags": "Linkding Tags",
"form.integration.matrix_bot_activate": "Transferir novos artigos para o Matrix",
"form.integration.matrix_bot_user": "Nome de utilizador para Matrix",
"form.integration.matrix_bot_password": "Palavra-passe para utilizador da Matrix",

View file

@ -363,6 +363,7 @@
"form.integration.linkding_activate": "Сохранять статьи в Linkding",
"form.integration.linkding_endpoint": "Конечная точка Linkding API",
"form.integration.linkding_api_key": "Linkding API key",
"form.integration.linkding_tags": "Linkding Tags",
"form.integration.matrix_bot_activate": "Перенос новых статей в Матрицу",
"form.integration.matrix_bot_user": "Имя пользователя для Matrix",
"form.integration.matrix_bot_password": "Пароль для пользователя Matrix",

View file

@ -361,6 +361,7 @@
"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.integration.linkding_tags": "Linkding Tags",
"form.integration.matrix_bot_activate": "Yeni makaleleri Matrix'e aktarın",
"form.integration.matrix_bot_user": "Matrix için Kullanıcı Adı",
"form.integration.matrix_bot_password": "Matrix kullanıcısı için şifre",

View file

@ -360,6 +360,7 @@
"form.integration.linkding_activate": "Зберігати статті до Linkding",
"form.integration.linkding_endpoint": "Linkding API Endpoint",
"form.integration.linkding_api_key": "Ключ API Linkding",
"form.integration.linkding_tags": "Linkding Tags",
"form.integration.matrix_bot_activate": "Перенесення нових статей в Матрицю",
"form.integration.matrix_bot_user": "Ім'я користувача для Matrix",
"form.integration.matrix_bot_password": "Пароль для користувача Matrix",

View file

@ -359,6 +359,7 @@
"form.integration.linkding_activate": "保存文章到 Linkding",
"form.integration.linkding_endpoint": "Linkding API 端点",
"form.integration.linkding_api_key": "Linkding API 密钥",
"form.integration.linkding_tags": "Linkding 默认标签",
"form.integration.matrix_bot_activate": "将新文章转移到 Matrix",
"form.integration.matrix_bot_user": "矩阵的用户名",
"form.integration.matrix_bot_password": "矩阵用户密码",

View file

@ -361,6 +361,7 @@
"form.integration.linkding_activate": "儲存文章到 Linkding",
"form.integration.linkding_endpoint": "Linkding API 端點",
"form.integration.linkding_api_key": "Linkding API 金鑰",
"form.integration.linkding_tags": "Linkding Tags",
"form.integration.matrix_bot_activate": "將新文章轉移到 Matrix",
"form.integration.matrix_bot_user": "矩陣的用戶名",
"form.integration.matrix_bot_password": "矩陣用戶密碼",

View file

@ -43,6 +43,7 @@ type Integration struct {
LinkdingEnabled bool
LinkdingURL string
LinkdingAPIKey string
LinkdingTags string
MatrixBotEnabled bool
MatrixBotUser string
MatrixBotPassword string

View file

@ -147,6 +147,7 @@ func (s *Storage) Integration(userID int64) (*model.Integration, error) {
linkding_enabled,
linkding_url,
linkding_api_key,
linkding_tags,
matrix_bot_enabled,
matrix_bot_user,
matrix_bot_password,
@ -196,6 +197,7 @@ func (s *Storage) Integration(userID int64) (*model.Integration, error) {
&integration.LinkdingEnabled,
&integration.LinkdingURL,
&integration.LinkdingAPIKey,
&integration.LinkdingTags,
&integration.MatrixBotEnabled,
&integration.MatrixBotUser,
&integration.MatrixBotPassword,
@ -260,13 +262,14 @@ func (s *Storage) UpdateIntegration(integration *model.Integration) error {
linkding_enabled=$34,
linkding_url=$35,
linkding_api_key=$36,
matrix_bot_enabled=$37,
matrix_bot_user=$38,
matrix_bot_password=$39,
matrix_bot_url=$40,
matrix_bot_chat_id=$41
linkding_tags=$37,
matrix_bot_enabled=$38,
matrix_bot_user=$39,
matrix_bot_password=$40,
matrix_bot_url=$41,
matrix_bot_chat_id=$42
WHERE
user_id=$42
user_id=$43
`
_, err = s.db.Exec(
query,
@ -306,6 +309,7 @@ func (s *Storage) UpdateIntegration(integration *model.Integration) error {
integration.LinkdingEnabled,
integration.LinkdingURL,
integration.LinkdingAPIKey,
integration.LinkdingTags,
integration.MatrixBotEnabled,
integration.MatrixBotUser,
integration.MatrixBotPassword,
@ -354,13 +358,14 @@ func (s *Storage) UpdateIntegration(integration *model.Integration) error {
linkding_enabled=$34,
linkding_url=$35,
linkding_api_key=$36,
matrix_bot_enabled=$37,
matrix_bot_user=$38,
matrix_bot_password=$39,
matrix_bot_url=$40,
matrix_bot_chat_id=$41
linkding_tags=$37,
matrix_bot_enabled=$38,
matrix_bot_user=$39,
matrix_bot_password=$40,
matrix_bot_url=$41,
matrix_bot_chat_id=$42
WHERE
user_id=$42
user_id=$43
`
_, err = s.db.Exec(
query,
@ -400,6 +405,7 @@ func (s *Storage) UpdateIntegration(integration *model.Integration) error {
integration.LinkdingEnabled,
integration.LinkdingURL,
integration.LinkdingAPIKey,
integration.LinkdingTags,
integration.MatrixBotEnabled,
integration.MatrixBotUser,
integration.MatrixBotPassword,

View file

@ -192,6 +192,9 @@
<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">
<label for="form-linkding-tags">{{ t "form.integration.linkding_tags" }}</label>
<input type="text" name="linkding_tags" id="form-linkding-tags" value="{{ .form.LinkdingTags }}" spellcheck="false">
<div class="buttons">
<button type="submit" class="button button-primary" data-label-loading="{{ t "form.submit.saving" }}">{{ t "action.update" }}</button>
</div>

View file

@ -48,6 +48,7 @@ type IntegrationForm struct {
LinkdingEnabled bool
LinkdingURL string
LinkdingAPIKey string
LinkdingTags string
MatrixBotEnabled bool
MatrixBotUser string
MatrixBotPassword string
@ -91,6 +92,7 @@ func (i IntegrationForm) Merge(integration *model.Integration) {
integration.LinkdingEnabled = i.LinkdingEnabled
integration.LinkdingURL = i.LinkdingURL
integration.LinkdingAPIKey = i.LinkdingAPIKey
integration.LinkdingTags = i.LinkdingTags
integration.MatrixBotEnabled = i.MatrixBotEnabled
integration.MatrixBotUser = i.MatrixBotUser
integration.MatrixBotPassword = i.MatrixBotPassword
@ -137,6 +139,7 @@ func NewIntegrationForm(r *http.Request) *IntegrationForm {
LinkdingEnabled: r.FormValue("linkding_enabled") == "1",
LinkdingURL: r.FormValue("linkding_url"),
LinkdingAPIKey: r.FormValue("linkding_api_key"),
LinkdingTags: r.FormValue("linkding_tags"),
MatrixBotEnabled: r.FormValue("matrix_bot_enabled") == "1",
MatrixBotUser: r.FormValue("matrix_bot_user"),
MatrixBotPassword: r.FormValue("matrix_bot_password"),

View file

@ -63,6 +63,7 @@ func (h *handler) showIntegrationPage(w http.ResponseWriter, r *http.Request) {
LinkdingEnabled: integration.LinkdingEnabled,
LinkdingURL: integration.LinkdingURL,
LinkdingAPIKey: integration.LinkdingAPIKey,
LinkdingTags: integration.LinkdingTags,
MatrixBotEnabled: integration.MatrixBotEnabled,
MatrixBotUser: integration.MatrixBotUser,
MatrixBotPassword: integration.MatrixBotPassword,