Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add siyuannote integration to miniflux #2082

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions internal/database/migrations.go
Original file line number Diff line number Diff line change
Expand Up @@ -776,4 +776,15 @@ 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 siyuannote_enabled bool default 'f';
ALTER TABLE integrations ADD COLUMN siyuannote_url text default '';
ALTER TABLE integrations ADD COLUMN siyuannote_token text default '';
ALTER TABLE integrations ADD COLUMN siyuannote_notebook_name text default '';
ALTER TABLE integrations ADD COLUMN siyuannote_page_path text default '';
`
_, err = tx.Exec(sql)
return err
},
}
15 changes: 15 additions & 0 deletions internal/integration/integration.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"miniflux.app/v2/internal/integration/readwise"
"miniflux.app/v2/internal/integration/shaarli"
"miniflux.app/v2/internal/integration/shiori"
"miniflux.app/v2/internal/integration/siyuan-note"

Check failure on line 20 in internal/integration/integration.go

View workflow job for this annotation

GitHub Actions / Golang Linter

File is not `goimports`-ed (goimports)
"miniflux.app/v2/internal/integration/telegrambot"
"miniflux.app/v2/internal/integration/wallabag"
"miniflux.app/v2/internal/integration/webhook"
Expand Down Expand Up @@ -176,6 +177,20 @@
logger.Error("[Integration] UserID #%d: %v", integration.UserID, err)
}
}

if integration.SiyuanNoteEnabled {
logger.Debug("[Integration] Sending entry #%d %q for user #%d to Siyuan-Note", entry.ID, entry.URL, integration.UserID)

client := siyuannote.NewClient(
integration.SiyuanNoteURL,
integration.SiyuanNoteToken,
integration.SiyuanNoteNotebookName,
integration.SiyuanNotePagePath,
)
if err := client.UpdateDocument(entry.URL, entry.Title, entry.Content); err != nil {
logger.Error("[Integration] UserID #%d: %v", integration.UserID, err)
}
}
}

// PushEntries pushes a list of entries to activated third-party providers during feed refreshes.
Expand Down
121 changes: 121 additions & 0 deletions internal/integration/siyuan-note/siyuan-note.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
// SPDX-FileCopyrightText: Copyright The Miniflux Authors. All rights reserved.
// SPDX-License-Identifier: Apache-2.0

package siyuannote

import (
"bytes"
"encoding/json"
"fmt"
"io"
"net/http"
"time"
)

const defaultClientTimeout = 10 * time.Second

Check failure on line 15 in internal/integration/siyuan-note/siyuan-note.go

View workflow job for this annotation

GitHub Actions / Golang Linter

const `defaultClientTimeout` is unused (unused)

type Client struct {
URL string
NotebookName string
PagePath string
Token string
}

type NotebookData struct {
Code int `json:"code"`
Msg string `json:"msg"`
Data struct {
Notebooks []struct {
ID string `json:"id"`
Name string `json:"name"`
Icon string `json:"icon"`
Sort int `json:"sort"`
Closed bool `json:"closed"`
} `json:"notebooks"`
} `json:"data"`
}

type DocumentGeneration struct {
Notebook string `json:"notebook"`
Path string `json:"path"`
Markdown string `json:"markdown"`
}

func NewClient(URL string, apiToken, notebookName string, pagePath string) *Client {
return &Client{URL, notebookName, pagePath, apiToken}
}

func (c *Client) UpdateDocument(entryURL string, entryTitle string, entryDocument string) error {
if c.URL == "" {
return fmt.Errorf("SiyuanNote Integration: missing URL")
}

notebookApiEndpoint := c.URL + "/api/notebook/lsNotebooks"
documentApiEndpoint := c.URL + "/api/filetree/createDocWithMd"

// Get the list of notebooks to get the right ID
request, error := http.Post(notebookApiEndpoint, "application/json", nil)
request.Header.Set("Authorization", c.Token)
if error != nil {
return fmt.Errorf("SiyuanNote Integration: Error during HTTP post request to siyuan %s", error)
}

defer request.Body.Close()

if request.StatusCode == http.StatusOK {
body, err := io.ReadAll(request.Body)
if err != nil {
//Failed to read response.
return fmt.Errorf("SiyuanNote Integration: Error during HTTP post reading response %s", err)
}

var notebook_data NotebookData
json_error := json.Unmarshal(body, &notebook_data)

if json_error != nil {
return fmt.Errorf("SiyuanNote Integration: Error during JSON Unmarshalling %s", json_error)
}
var notebook_found bool

// Scan the list of notebooks to find the correct one
for _, value := range notebook_data.Data.Notebooks {
if value.Name == c.NotebookName {
notebook_found = true

// Create the RSS document under the requested path
var document DocumentGeneration
document.Notebook = value.ID

document.Path = c.PagePath + "/" + entryTitle

document.Markdown = "---\n<" + entryURL + ">\n" + "---\n" + entryDocument
json_data, json_error := json.Marshal(document)
if json_error != nil {
return fmt.Errorf("SiyuanNote Integration: Error during JSON Marshalling %s", json_error)
}

res, error := http.Post(documentApiEndpoint, "application/json", bytes.NewBuffer(json_data))
if error != nil {
return fmt.Errorf("SiyuanNote Integration: Error during Document Creation Post Request %s", error)
}
defer res.Body.Close()
if request.StatusCode == http.StatusOK {
_, err := io.ReadAll(res.Body)
if err != nil {
//Failed to read response.
return fmt.Errorf("SiyuanNote Integration: Error during Document Creation Post response reading %s", error)
}
} else {
return fmt.Errorf("SiyuanNote Integration: Error during Document Creation Post request %d", request.StatusCode)
}
}
}
if notebook_found == false {

Check failure on line 113 in internal/integration/siyuan-note/siyuan-note.go

View workflow job for this annotation

GitHub Actions / Golang Linter

S1002: should omit comparison to bool constant, can be simplified to `!notebook_found` (gosimple)
return fmt.Errorf("SiyuanNote Integration: The notebook %s not found ", c.NotebookName)
}
} else {
return fmt.Errorf("SiyuanNote Integration: Post Request to get list of notebooks failed with error code: %s", request.Status)
}

return nil
}
5 changes: 5 additions & 0 deletions internal/locale/translations/de_DE.json
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,11 @@
"form.integration.webhook_activate": "Enable Webhook",
"form.integration.webhook_url": "Webhook URL",
"form.integration.webhook_secret": "Webhook Secret",
"form.integration.siyuannote_activate": "Save Entries to Siyuan Note",
"form.integration.siyuannote_url": "Siyuan Server URL",
"form.integration.siyuannote_notebook_name": "Siyuan Notebook Name",
"form.integration.siyuannote_page_path": "Siyuan Page Path",
"form.integration.siyuannote_token": "Siyuan Secret Token",
"form.api_key.label.description": "API-Schlüsselbezeichnung",
"form.submit.loading": "Lade...",
"form.submit.saving": "Speichern...",
Expand Down
5 changes: 5 additions & 0 deletions internal/locale/translations/el_EL.json
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,11 @@
"form.integration.webhook_activate": "Enable Webhook",
"form.integration.webhook_url": "Webhook URL",
"form.integration.webhook_secret": "Webhook Secret",
"form.integration.siyuannote_activate": "Save Entries to Siyuan Note",
"form.integration.siyuannote_url": "Siyuan Server URL",
"form.integration.siyuannote_notebook_name": "Siyuan Notebook Name",
"form.integration.siyuannote_page_path": "Siyuan Page Path",
"form.integration.siyuannote_token": "Siyuan Secret Token",
"form.api_key.label.description": "Ετικέτα κλειδιού API",
"form.submit.loading": "Φόρτωση...",
"form.submit.saving": "Αποθήκευση...",
Expand Down
5 changes: 5 additions & 0 deletions internal/locale/translations/en_US.json
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,11 @@
"form.integration.webhook_activate": "Enable Webhook",
"form.integration.webhook_url": "Webhook URL",
"form.integration.webhook_secret": "Webhook Secret",
"form.integration.siyuannote_activate": "Save Entries to Siyuan Note",
"form.integration.siyuannote_url": "Siyuan Server URL",
"form.integration.siyuannote_notebook_name": "Siyuan Notebook Name",
"form.integration.siyuannote_page_path": "Siyuan Page Path",
"form.integration.siyuannote_token": "Siyuan Secret Token",
"form.api_key.label.description": "API Key Label",
"form.submit.loading": "Loading…",
"form.submit.saving": "Saving…",
Expand Down
5 changes: 5 additions & 0 deletions internal/locale/translations/es_ES.json
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,11 @@
"form.integration.webhook_activate": "Enable Webhook",
"form.integration.webhook_url": "Webhook URL",
"form.integration.webhook_secret": "Webhook Secret",
"form.integration.siyuannote_activate": "Save Entries to Siyuan Note",
"form.integration.siyuannote_url": "Siyuan Server URL",
"form.integration.siyuannote_notebook_name": "Siyuan Notebook Name",
"form.integration.siyuannote_page_path": "Siyuan Page Path",
"form.integration.siyuannote_token": "Siyuan Secret Token",
"form.api_key.label.description": "Etiqueta de clave API",
"form.submit.loading": "Cargando...",
"form.submit.saving": "Guardando...",
Expand Down
5 changes: 5 additions & 0 deletions internal/locale/translations/fi_FI.json
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,11 @@
"form.integration.webhook_activate": "Enable Webhook",
"form.integration.webhook_url": "Webhook URL",
"form.integration.webhook_secret": "Webhook Secret",
"form.integration.siyuannote_activate": "Save Entries to Siyuan Note",
"form.integration.siyuannote_url": "Siyuan Server URL",
"form.integration.siyuannote_notebook_name": "Siyuan Notebook Name",
"form.integration.siyuannote_page_path": "Siyuan Page Path",
"form.integration.siyuannote_token": "Siyuan Secret Token",
"form.api_key.label.description": "API Key Label",
"form.submit.loading": "Ladataan...",
"form.submit.saving": "Tallennetaan...",
Expand Down
5 changes: 5 additions & 0 deletions internal/locale/translations/fr_FR.json
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,11 @@
"form.integration.webhook_activate": "Activer le webhook",
"form.integration.webhook_url": "URL du webhook",
"form.integration.webhook_secret": "Secret du webhook",
"form.integration.siyuannote_activate": "Save Entries to Siyuan Note",
"form.integration.siyuannote_url": "Siyuan Server URL",
"form.integration.siyuannote_notebook_name": "Siyuan Notebook Name",
"form.integration.siyuannote_page_path": "Siyuan Page Path",
"form.integration.siyuannote_token": "Siyuan Secret Token",
"form.api_key.label.description": "Libellé de la clé d'API",
"form.submit.loading": "Chargement...",
"form.submit.saving": "Sauvegarde en cours...",
Expand Down
5 changes: 5 additions & 0 deletions internal/locale/translations/hi_IN.json
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,11 @@
"form.integration.webhook_activate": "Enable Webhook",
"form.integration.webhook_url": "Webhook URL",
"form.integration.webhook_secret": "Webhook Secret",
"form.integration.siyuannote_activate": "Save Entries to Siyuan Note",
"form.integration.siyuannote_url": "Siyuan Server URL",
"form.integration.siyuannote_notebook_name": "Siyuan Notebook Name",
"form.integration.siyuannote_page_path": "Siyuan Page Path",
"form.integration.siyuannote_token": "Siyuan Secret Token",
"form.api_key.label.description": "एपीआई कुंजी लेबल",
"form.submit.loading": "लोड हो रहा है...",
"form.submit.saving": "सहेजा जा रहा है...",
Expand Down
5 changes: 5 additions & 0 deletions internal/locale/translations/id_ID.json
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,11 @@
"form.integration.webhook_activate": "Enable Webhook",
"form.integration.webhook_url": "Webhook URL",
"form.integration.webhook_secret": "Webhook Secret",
"form.integration.siyuannote_activate": "Save Entries to Siyuan Note",
"form.integration.siyuannote_url": "Siyuan Server URL",
"form.integration.siyuannote_notebook_name": "Siyuan Notebook Name",
"form.integration.siyuannote_page_path": "Siyuan Page Path",
"form.integration.siyuannote_token": "Siyuan Secret Token",
"form.api_key.label.description": "Label Kunci API",
"form.submit.loading": "Memuat...",
"form.submit.saving": "Menyimpan...",
Expand Down
5 changes: 5 additions & 0 deletions internal/locale/translations/it_IT.json
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,11 @@
"form.integration.webhook_activate": "Enable Webhook",
"form.integration.webhook_url": "Webhook URL",
"form.integration.webhook_secret": "Webhook Secret",
"form.integration.siyuannote_activate": "Save Entries to Siyuan Note",
"form.integration.siyuannote_url": "Siyuan Server URL",
"form.integration.siyuannote_notebook_name": "Siyuan Notebook Name",
"form.integration.siyuannote_page_path": "Siyuan Page Path",
"form.integration.siyuannote_token": "Siyuan Secret Token",
"form.api_key.label.description": "Etichetta chiave API",
"form.submit.loading": "Caricamento in corso...",
"form.submit.saving": "Salvataggio in corso...",
Expand Down
5 changes: 5 additions & 0 deletions internal/locale/translations/ja_JP.json
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,11 @@
"form.integration.webhook_activate": "Enable Webhook",
"form.integration.webhook_url": "Webhook URL",
"form.integration.webhook_secret": "Webhook Secret",
"form.integration.siyuannote_activate": "Save Entries to Siyuan Note",
"form.integration.siyuannote_url": "Siyuan Server URL",
"form.integration.siyuannote_notebook_name": "Siyuan Notebook Name",
"form.integration.siyuannote_page_path": "Siyuan Page Path",
"form.integration.siyuannote_token": "Siyuan Secret Token",
"form.api_key.label.description": "API キーラベル",
"form.submit.loading": "読み込み中…",
"form.submit.saving": "保存中…",
Expand Down
5 changes: 5 additions & 0 deletions internal/locale/translations/nl_NL.json
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,11 @@
"form.integration.webhook_activate": "Enable Webhook",
"form.integration.webhook_url": "Webhook URL",
"form.integration.webhook_secret": "Webhook Secret",
"form.integration.siyuannote_activate": "Save Entries to Siyuan Note",
"form.integration.siyuannote_url": "Siyuan Server URL",
"form.integration.siyuannote_notebook_name": "Siyuan Notebook Name",
"form.integration.siyuannote_page_path": "Siyuan Page Path",
"form.integration.siyuannote_token": "Siyuan Secret Token",
"form.api_key.label.description": "API-sleutellabel",
"form.submit.loading": "Laden...",
"form.submit.saving": "Opslaag...",
Expand Down
5 changes: 5 additions & 0 deletions internal/locale/translations/pl_PL.json
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,11 @@
"form.integration.webhook_activate": "Enable Webhook",
"form.integration.webhook_url": "Webhook URL",
"form.integration.webhook_secret": "Webhook Secret",
"form.integration.siyuannote_activate": "Save Entries to Siyuan Note",
"form.integration.siyuannote_url": "Siyuan Server URL",
"form.integration.siyuannote_notebook_name": "Siyuan Notebook Name",
"form.integration.siyuannote_page_path": "Siyuan Page Path",
"form.integration.siyuannote_token": "Siyuan Secret Token",
"form.api_key.label.description": "Etykieta klucza API",
"form.submit.loading": "Ładowanie...",
"form.submit.saving": "Zapisywanie...",
Expand Down
5 changes: 5 additions & 0 deletions internal/locale/translations/pt_BR.json
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,11 @@
"form.integration.webhook_activate": "Enable Webhook",
"form.integration.webhook_url": "Webhook URL",
"form.integration.webhook_secret": "Webhook Secret",
"form.integration.siyuannote_activate": "Save Entries to Siyuan Note",
"form.integration.siyuannote_url": "Siyuan Server URL",
"form.integration.siyuannote_notebook_name": "Siyuan Notebook Name",
"form.integration.siyuannote_page_path": "Siyuan Page Path",
"form.integration.siyuannote_token": "Siyuan Secret Token",
"form.api_key.label.description": "Etiqueta da chave de API",
"form.submit.loading": "Carregando...",
"form.submit.saving": "Salvando...",
Expand Down
5 changes: 5 additions & 0 deletions internal/locale/translations/ru_RU.json
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,11 @@
"form.integration.webhook_activate": "Включить вебхуки",
"form.integration.webhook_url": "Адрес вебхуков",
"form.integration.webhook_secret": "Секретный ключ для вебхуков",
"form.integration.siyuannote_activate": "Save Entries to Siyuan Note",
"form.integration.siyuannote_url": "Siyuan Server URL",
"form.integration.siyuannote_notebook_name": "Siyuan Notebook Name",
"form.integration.siyuannote_page_path": "Siyuan Page Path",
"form.integration.siyuannote_token": "Siyuan Secret Token",
"form.api_key.label.description": "Описание API-ключа",
"form.submit.loading": "Загрузка…",
"form.submit.saving": "Сохранение…",
Expand Down
5 changes: 5 additions & 0 deletions internal/locale/translations/tr_TR.json
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,11 @@
"form.integration.webhook_activate": "Enable Webhook",
"form.integration.webhook_url": "Webhook URL",
"form.integration.webhook_secret": "Webhook Secret",
"form.integration.siyuannote_activate": "Save Entries to Siyuan Note",
"form.integration.siyuannote_url": "Siyuan Server URL",
"form.integration.siyuannote_notebook_name": "Siyuan Notebook Name",
"form.integration.siyuannote_page_path": "Siyuan Page Path",
"form.integration.siyuannote_token": "Siyuan Secret Token",
"form.api_key.label.description": "API Anahtar Etiketi",
"form.submit.loading": "Yükleniyor...",
"form.submit.saving": "Kaydediliyor...",
Expand Down
7 changes: 6 additions & 1 deletion internal/locale/translations/uk_UA.json
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,11 @@
"form.integration.webhook_activate": "Enable Webhook",
"form.integration.webhook_url": "Webhook URL",
"form.integration.webhook_secret": "Webhook Secret",
"form.integration.siyuannote_activate": "Save Entries to Siyuan Note",
"form.integration.siyuannote_url": "Siyuan Server URL",
"form.integration.siyuannote_notebook_name": "Siyuan Notebook Name",
"form.integration.siyuannote_page_path": "Siyuan Page Path",
"form.integration.siyuannote_token": "Siyuan Secret Token",
"form.api_key.label.description": "Назва ключа API",
"form.submit.loading": "Завантаження...",
"form.submit.saving": "Зберігаю...",
Expand Down Expand Up @@ -441,4 +446,4 @@
"%d роки тому",
"%d років тому"
]
}
}
5 changes: 5 additions & 0 deletions internal/locale/translations/zh_CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,11 @@
"form.integration.webhook_activate": "Enable Webhook",
"form.integration.webhook_url": "Webhook URL",
"form.integration.webhook_secret": "Webhook Secret",
"form.integration.siyuannote_activate": "Save Entries to Siyuan Note",
"form.integration.siyuannote_url": "Siyuan Server URL",
"form.integration.siyuannote_notebook_name": "Siyuan Notebook Name",
"form.integration.siyuannote_page_path": "Siyuan Page Path",
"form.integration.siyuannote_token": "Siyuan Secret Token",
"form.api_key.label.description": "API密钥标签",
"form.submit.loading": "载入中…",
"form.submit.saving": "保存中…",
Expand Down
5 changes: 5 additions & 0 deletions internal/locale/translations/zh_TW.json
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,11 @@
"form.integration.webhook_activate": "Enable Webhook",
"form.integration.webhook_url": "Webhook URL",
"form.integration.webhook_secret": "Webhook Secret",
"form.integration.siyuannote_activate": "Save Entries to Siyuan Note",
"form.integration.siyuannote_url": "Siyuan Server URL",
"form.integration.siyuannote_notebook_name": "Siyuan Notebook Name",
"form.integration.siyuannote_page_path": "Siyuan Page Path",
"form.integration.siyuannote_token": "Siyuan Secret Token",
"form.api_key.label.description": "API金鑰標籤",
"form.submit.loading": "載入中…",
"form.submit.saving": "儲存中…",
Expand Down
5 changes: 5 additions & 0 deletions internal/model/integration.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,9 @@
WebhookEnabled bool
WebhookURL string
WebhookSecret string
SiyuanNoteEnabled bool
SiyuanNoteURL string
SiyuanNoteToken string

Check failure on line 75 in internal/model/integration.go

View workflow job for this annotation

GitHub Actions / Golang Linter

File is not `gofmt`-ed with `-s` (gofmt)
SiyuanNoteNotebookName string
SiyuanNotePagePath string
}
Loading
Loading