Add mark as unread for Linkding integration
This commit is contained in:
parent
765b4c6424
commit
736fb7320e
8 changed files with 40 additions and 14 deletions
|
@ -667,4 +667,11 @@ var migrations = []func(tx *sql.Tx) error{
|
||||||
_, err = tx.Exec(sql)
|
_, err = tx.Exec(sql)
|
||||||
return err
|
return err
|
||||||
},
|
},
|
||||||
|
func(tx *sql.Tx) (err error) {
|
||||||
|
sql := `
|
||||||
|
ALTER TABLE integrations ADD COLUMN linkding_mark_as_unread bool default 'f';
|
||||||
|
`
|
||||||
|
_, err = tx.Exec(sql)
|
||||||
|
return err
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
|
@ -104,6 +104,7 @@ func SendEntry(entry *model.Entry, integration *model.Integration) {
|
||||||
integration.LinkdingURL,
|
integration.LinkdingURL,
|
||||||
integration.LinkdingAPIKey,
|
integration.LinkdingAPIKey,
|
||||||
integration.LinkdingTags,
|
integration.LinkdingTags,
|
||||||
|
integration.LinkdingMarkAsUnread,
|
||||||
)
|
)
|
||||||
if err := client.AddEntry(entry.Title, entry.URL); err != nil {
|
if err := client.AddEntry(entry.Title, entry.URL); err != nil {
|
||||||
logger.Error("[Integration] UserID #%d: %v", integration.UserID, err)
|
logger.Error("[Integration] UserID #%d: %v", integration.UserID, err)
|
||||||
|
|
|
@ -16,6 +16,7 @@ type Document struct {
|
||||||
Url string `json:"url,omitempty"`
|
Url string `json:"url,omitempty"`
|
||||||
Title string `json:"title,omitempty"`
|
Title string `json:"title,omitempty"`
|
||||||
TagNames []string `json:"tag_names,omitempty"`
|
TagNames []string `json:"tag_names,omitempty"`
|
||||||
|
Unread bool `json:"unread,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Client represents an Linkding client.
|
// Client represents an Linkding client.
|
||||||
|
@ -23,11 +24,12 @@ type Client struct {
|
||||||
baseURL string
|
baseURL string
|
||||||
apiKey string
|
apiKey string
|
||||||
tags string
|
tags string
|
||||||
|
unread bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewClient returns a new Linkding client.
|
// NewClient returns a new Linkding client.
|
||||||
func NewClient(baseURL, apiKey, tags string) *Client {
|
func NewClient(baseURL, apiKey, tags string, unread bool) *Client {
|
||||||
return &Client{baseURL: baseURL, apiKey: apiKey, tags: tags}
|
return &Client{baseURL: baseURL, apiKey: apiKey, tags: tags, unread: unread}
|
||||||
}
|
}
|
||||||
|
|
||||||
// AddEntry sends an entry to Linkding.
|
// AddEntry sends an entry to Linkding.
|
||||||
|
@ -44,6 +46,7 @@ func (c *Client) AddEntry(title, url string) error {
|
||||||
Url: url,
|
Url: url,
|
||||||
Title: title,
|
Title: title,
|
||||||
TagNames: strings.FieldsFunc(c.tags, tagsSplitFn),
|
TagNames: strings.FieldsFunc(c.tags, tagsSplitFn),
|
||||||
|
Unread: c.unread,
|
||||||
}
|
}
|
||||||
|
|
||||||
apiURL, err := getAPIEndpoint(c.baseURL, "/api/bookmarks/")
|
apiURL, err := getAPIEndpoint(c.baseURL, "/api/bookmarks/")
|
||||||
|
|
|
@ -43,6 +43,7 @@ type Integration struct {
|
||||||
LinkdingURL string
|
LinkdingURL string
|
||||||
LinkdingAPIKey string
|
LinkdingAPIKey string
|
||||||
LinkdingTags string
|
LinkdingTags string
|
||||||
|
LinkdingMarkAsUnread bool
|
||||||
MatrixBotEnabled bool
|
MatrixBotEnabled bool
|
||||||
MatrixBotUser string
|
MatrixBotUser string
|
||||||
MatrixBotPassword string
|
MatrixBotPassword string
|
||||||
|
|
|
@ -147,6 +147,7 @@ func (s *Storage) Integration(userID int64) (*model.Integration, error) {
|
||||||
linkding_url,
|
linkding_url,
|
||||||
linkding_api_key,
|
linkding_api_key,
|
||||||
linkding_tags,
|
linkding_tags,
|
||||||
|
linkding_mark_as_unread,
|
||||||
matrix_bot_enabled,
|
matrix_bot_enabled,
|
||||||
matrix_bot_user,
|
matrix_bot_user,
|
||||||
matrix_bot_password,
|
matrix_bot_password,
|
||||||
|
@ -197,6 +198,7 @@ func (s *Storage) Integration(userID int64) (*model.Integration, error) {
|
||||||
&integration.LinkdingURL,
|
&integration.LinkdingURL,
|
||||||
&integration.LinkdingAPIKey,
|
&integration.LinkdingAPIKey,
|
||||||
&integration.LinkdingTags,
|
&integration.LinkdingTags,
|
||||||
|
&integration.LinkdingMarkAsUnread,
|
||||||
&integration.MatrixBotEnabled,
|
&integration.MatrixBotEnabled,
|
||||||
&integration.MatrixBotUser,
|
&integration.MatrixBotUser,
|
||||||
&integration.MatrixBotPassword,
|
&integration.MatrixBotPassword,
|
||||||
|
@ -262,13 +264,14 @@ func (s *Storage) UpdateIntegration(integration *model.Integration) error {
|
||||||
linkding_url=$35,
|
linkding_url=$35,
|
||||||
linkding_api_key=$36,
|
linkding_api_key=$36,
|
||||||
linkding_tags=$37,
|
linkding_tags=$37,
|
||||||
matrix_bot_enabled=$38,
|
linkding_mark_as_unread=$38,
|
||||||
matrix_bot_user=$39,
|
matrix_bot_enabled=$39,
|
||||||
matrix_bot_password=$40,
|
matrix_bot_user=$40,
|
||||||
matrix_bot_url=$41,
|
matrix_bot_password=$41,
|
||||||
matrix_bot_chat_id=$42
|
matrix_bot_url=$42,
|
||||||
|
matrix_bot_chat_id=$43
|
||||||
WHERE
|
WHERE
|
||||||
user_id=$43
|
user_id=$44
|
||||||
`
|
`
|
||||||
_, err = s.db.Exec(
|
_, err = s.db.Exec(
|
||||||
query,
|
query,
|
||||||
|
@ -309,6 +312,7 @@ func (s *Storage) UpdateIntegration(integration *model.Integration) error {
|
||||||
integration.LinkdingURL,
|
integration.LinkdingURL,
|
||||||
integration.LinkdingAPIKey,
|
integration.LinkdingAPIKey,
|
||||||
integration.LinkdingTags,
|
integration.LinkdingTags,
|
||||||
|
integration.LinkdingMarkAsUnread,
|
||||||
integration.MatrixBotEnabled,
|
integration.MatrixBotEnabled,
|
||||||
integration.MatrixBotUser,
|
integration.MatrixBotUser,
|
||||||
integration.MatrixBotPassword,
|
integration.MatrixBotPassword,
|
||||||
|
@ -358,13 +362,14 @@ func (s *Storage) UpdateIntegration(integration *model.Integration) error {
|
||||||
linkding_url=$35,
|
linkding_url=$35,
|
||||||
linkding_api_key=$36,
|
linkding_api_key=$36,
|
||||||
linkding_tags=$37,
|
linkding_tags=$37,
|
||||||
matrix_bot_enabled=$38,
|
linkding_mark_as_unread=$38,
|
||||||
matrix_bot_user=$39,
|
matrix_bot_enabled=$39,
|
||||||
matrix_bot_password=$40,
|
matrix_bot_user=$40,
|
||||||
matrix_bot_url=$41,
|
matrix_bot_password=$41,
|
||||||
matrix_bot_chat_id=$42
|
matrix_bot_url=$42,
|
||||||
|
matrix_bot_chat_id=$43
|
||||||
WHERE
|
WHERE
|
||||||
user_id=$43
|
user_id=$44
|
||||||
`
|
`
|
||||||
_, err = s.db.Exec(
|
_, err = s.db.Exec(
|
||||||
query,
|
query,
|
||||||
|
@ -405,6 +410,7 @@ func (s *Storage) UpdateIntegration(integration *model.Integration) error {
|
||||||
integration.LinkdingURL,
|
integration.LinkdingURL,
|
||||||
integration.LinkdingAPIKey,
|
integration.LinkdingAPIKey,
|
||||||
integration.LinkdingTags,
|
integration.LinkdingTags,
|
||||||
|
integration.LinkdingMarkAsUnread,
|
||||||
integration.MatrixBotEnabled,
|
integration.MatrixBotEnabled,
|
||||||
integration.MatrixBotUser,
|
integration.MatrixBotUser,
|
||||||
integration.MatrixBotPassword,
|
integration.MatrixBotPassword,
|
||||||
|
|
|
@ -195,6 +195,10 @@
|
||||||
<label for="form-linkding-tags">{{ t "form.integration.linkding_tags" }}</label>
|
<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">
|
<input type="text" name="linkding_tags" id="form-linkding-tags" value="{{ .form.LinkdingTags }}" spellcheck="false">
|
||||||
|
|
||||||
|
<label>
|
||||||
|
<input type="checkbox" name="linkding_mark_as_unread" value="1" {{ if .form.LinkdingMarkAsUnread }}checked{{ end }}> {{ t "form.integration.pinboard_bookmark" }}
|
||||||
|
</label>
|
||||||
|
|
||||||
<div class="buttons">
|
<div class="buttons">
|
||||||
<button type="submit" class="button button-primary" data-label-loading="{{ t "form.submit.saving" }}">{{ t "action.update" }}</button>
|
<button type="submit" class="button button-primary" data-label-loading="{{ t "form.submit.saving" }}">{{ t "action.update" }}</button>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -48,6 +48,7 @@ type IntegrationForm struct {
|
||||||
LinkdingURL string
|
LinkdingURL string
|
||||||
LinkdingAPIKey string
|
LinkdingAPIKey string
|
||||||
LinkdingTags string
|
LinkdingTags string
|
||||||
|
LinkdingMarkAsUnread bool
|
||||||
MatrixBotEnabled bool
|
MatrixBotEnabled bool
|
||||||
MatrixBotUser string
|
MatrixBotUser string
|
||||||
MatrixBotPassword string
|
MatrixBotPassword string
|
||||||
|
@ -92,6 +93,7 @@ func (i IntegrationForm) Merge(integration *model.Integration) {
|
||||||
integration.LinkdingURL = i.LinkdingURL
|
integration.LinkdingURL = i.LinkdingURL
|
||||||
integration.LinkdingAPIKey = i.LinkdingAPIKey
|
integration.LinkdingAPIKey = i.LinkdingAPIKey
|
||||||
integration.LinkdingTags = i.LinkdingTags
|
integration.LinkdingTags = i.LinkdingTags
|
||||||
|
integration.LinkdingMarkAsUnread = i.LinkdingMarkAsUnread
|
||||||
integration.MatrixBotEnabled = i.MatrixBotEnabled
|
integration.MatrixBotEnabled = i.MatrixBotEnabled
|
||||||
integration.MatrixBotUser = i.MatrixBotUser
|
integration.MatrixBotUser = i.MatrixBotUser
|
||||||
integration.MatrixBotPassword = i.MatrixBotPassword
|
integration.MatrixBotPassword = i.MatrixBotPassword
|
||||||
|
@ -139,6 +141,7 @@ func NewIntegrationForm(r *http.Request) *IntegrationForm {
|
||||||
LinkdingURL: r.FormValue("linkding_url"),
|
LinkdingURL: r.FormValue("linkding_url"),
|
||||||
LinkdingAPIKey: r.FormValue("linkding_api_key"),
|
LinkdingAPIKey: r.FormValue("linkding_api_key"),
|
||||||
LinkdingTags: r.FormValue("linkding_tags"),
|
LinkdingTags: r.FormValue("linkding_tags"),
|
||||||
|
LinkdingMarkAsUnread: r.FormValue("linkding_mark_as_unread") == "1",
|
||||||
MatrixBotEnabled: r.FormValue("matrix_bot_enabled") == "1",
|
MatrixBotEnabled: r.FormValue("matrix_bot_enabled") == "1",
|
||||||
MatrixBotUser: r.FormValue("matrix_bot_user"),
|
MatrixBotUser: r.FormValue("matrix_bot_user"),
|
||||||
MatrixBotPassword: r.FormValue("matrix_bot_password"),
|
MatrixBotPassword: r.FormValue("matrix_bot_password"),
|
||||||
|
|
|
@ -63,6 +63,7 @@ func (h *handler) showIntegrationPage(w http.ResponseWriter, r *http.Request) {
|
||||||
LinkdingURL: integration.LinkdingURL,
|
LinkdingURL: integration.LinkdingURL,
|
||||||
LinkdingAPIKey: integration.LinkdingAPIKey,
|
LinkdingAPIKey: integration.LinkdingAPIKey,
|
||||||
LinkdingTags: integration.LinkdingTags,
|
LinkdingTags: integration.LinkdingTags,
|
||||||
|
LinkdingMarkAsUnread: integration.LinkdingMarkAsUnread,
|
||||||
MatrixBotEnabled: integration.MatrixBotEnabled,
|
MatrixBotEnabled: integration.MatrixBotEnabled,
|
||||||
MatrixBotUser: integration.MatrixBotUser,
|
MatrixBotUser: integration.MatrixBotUser,
|
||||||
MatrixBotPassword: integration.MatrixBotPassword,
|
MatrixBotPassword: integration.MatrixBotPassword,
|
||||||
|
|
Loading…
Reference in a new issue