mirror of
https://github.com/miniflux/v2.git
synced 2025-08-01 17:38:37 +00:00
feat(integration-shiori): updated shiori API to new endpoint for login/bookmark
This commit is contained in:
parent
7c5d6cf35f
commit
7759ea1b43
1 changed files with 26 additions and 12 deletions
|
@ -31,7 +31,7 @@ func (c *Client) CreateBookmark(entryURL, entryTitle string) error {
|
||||||
return fmt.Errorf("shiori: missing base URL, username or password")
|
return fmt.Errorf("shiori: missing base URL, username or password")
|
||||||
}
|
}
|
||||||
|
|
||||||
sessionID, err := c.authenticate()
|
token, err := c.authenticate()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("shiori: unable to authenticate: %v", err)
|
return fmt.Errorf("shiori: unable to authenticate: %v", err)
|
||||||
}
|
}
|
||||||
|
@ -44,7 +44,11 @@ func (c *Client) CreateBookmark(entryURL, entryTitle string) error {
|
||||||
requestBody, err := json.Marshal(&addBookmarkRequest{
|
requestBody, err := json.Marshal(&addBookmarkRequest{
|
||||||
URL: entryURL,
|
URL: entryURL,
|
||||||
Title: entryTitle,
|
Title: entryTitle,
|
||||||
|
Excerpt: "",
|
||||||
CreateArchive: true,
|
CreateArchive: true,
|
||||||
|
CreateEbook: false,
|
||||||
|
Public: 0,
|
||||||
|
Tags: make([]string, 0),
|
||||||
})
|
})
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -58,7 +62,7 @@ func (c *Client) CreateBookmark(entryURL, entryTitle string) error {
|
||||||
|
|
||||||
request.Header.Set("Content-Type", "application/json")
|
request.Header.Set("Content-Type", "application/json")
|
||||||
request.Header.Set("User-Agent", "Miniflux/"+version.Version)
|
request.Header.Set("User-Agent", "Miniflux/"+version.Version)
|
||||||
request.Header.Set("X-Session-Id", sessionID)
|
request.Header.Set("Authorization", "Bearer "+token)
|
||||||
|
|
||||||
httpClient := &http.Client{Timeout: defaultClientTimeout}
|
httpClient := &http.Client{Timeout: defaultClientTimeout}
|
||||||
|
|
||||||
|
@ -75,13 +79,13 @@ func (c *Client) CreateBookmark(entryURL, entryTitle string) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Client) authenticate() (sessionID string, err error) {
|
func (c *Client) authenticate() (token string, err error) {
|
||||||
apiEndpoint, err := urllib.JoinBaseURLAndPath(c.baseURL, "/api/login")
|
apiEndpoint, err := urllib.JoinBaseURLAndPath(c.baseURL, "/api/v1/auth/login")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", fmt.Errorf("shiori: invalid API endpoint: %v", err)
|
return "", fmt.Errorf("shiori: invalid API endpoint: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
requestBody, err := json.Marshal(&authRequest{Username: c.username, Password: c.password})
|
requestBody, err := json.Marshal(&authRequest{Username: c.username, Password: c.password, RememberMe: false})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", fmt.Errorf("shiori: unable to encode request body: %v", err)
|
return "", fmt.Errorf("shiori: unable to encode request body: %v", err)
|
||||||
}
|
}
|
||||||
|
@ -111,21 +115,31 @@ func (c *Client) authenticate() (sessionID string, err error) {
|
||||||
if err := json.NewDecoder(response.Body).Decode(&authResponse); err != nil {
|
if err := json.NewDecoder(response.Body).Decode(&authResponse); err != nil {
|
||||||
return "", fmt.Errorf("shiori: unable to decode response: %v", err)
|
return "", fmt.Errorf("shiori: unable to decode response: %v", err)
|
||||||
}
|
}
|
||||||
|
return authResponse.Message.Token, nil
|
||||||
return authResponse.SessionID, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type authRequest struct {
|
type authRequest struct {
|
||||||
Username string `json:"username"`
|
Username string `json:"username"`
|
||||||
Password string `json:"password"`
|
Password string `json:"password"`
|
||||||
|
RememberMe bool `json:"remember_me"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type authResponse struct {
|
type authResponse struct {
|
||||||
|
OK bool `json:"ok"`
|
||||||
|
Message authResponseMessage `json:"message"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type authResponseMessage struct {
|
||||||
SessionID string `json:"session"`
|
SessionID string `json:"session"`
|
||||||
|
Token string `json:"token"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type addBookmarkRequest struct {
|
type addBookmarkRequest struct {
|
||||||
URL string `json:"url"`
|
URL string `json:"url"`
|
||||||
Title string `json:"title"`
|
Title string `json:"title"`
|
||||||
CreateArchive bool `json:"createArchive"`
|
CreateArchive bool `json:"create_archive"`
|
||||||
|
CreateEbook bool `json:"create_ebook"`
|
||||||
|
Public int `json:"public"`
|
||||||
|
Excerpt string `json:"excerpt"`
|
||||||
|
Tags []string `json:"tags"`
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue