fix today memory after restart
This commit is contained in:
@@ -67,6 +67,34 @@ func (c *Client) ListMemos(ctx context.Context, filter string, pageSize int, pag
|
||||
return &result, nil
|
||||
}
|
||||
|
||||
// GetMemo fetches a single memo by its resource name (e.g. "memos/123").
|
||||
func (c *Client) GetMemo(ctx context.Context, name string) (*Memo, error) {
|
||||
reqURL := fmt.Sprintf("%s/api/v1/%s", c.baseURL, name)
|
||||
|
||||
req, err := http.NewRequestWithContext(ctx, http.MethodGet, reqURL, http.NoBody)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("create request: %w", err)
|
||||
}
|
||||
req.Header.Set("Authorization", "Bearer "+c.token)
|
||||
|
||||
resp, err := c.httpClient.Do(req)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("do request: %w", err)
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
body, _ := io.ReadAll(resp.Body)
|
||||
return nil, fmt.Errorf("memos API returned %d: %s", resp.StatusCode, body)
|
||||
}
|
||||
|
||||
var memo Memo
|
||||
if err := json.NewDecoder(resp.Body).Decode(&memo); err != nil {
|
||||
return nil, fmt.Errorf("decode memo: %w", err)
|
||||
}
|
||||
return &memo, nil
|
||||
}
|
||||
|
||||
// DownloadAttachment downloads the attachment data as bytes.
|
||||
func (c *Client) DownloadAttachment(ctx context.Context, att Attachment) ([]byte, error) {
|
||||
var reqURL string
|
||||
|
||||
Reference in New Issue
Block a user