Fix FUSE attachment sizes and item filenames
This commit is contained in:
+29
-1
@@ -137,6 +137,30 @@ func (c *DocspellClient) GetItem(ctx context.Context, id string) (*SearchItem, e
|
||||
return &out, nil
|
||||
}
|
||||
|
||||
func (c *DocspellClient) AttachmentSize(ctx context.Context, id string) (int64, error) {
|
||||
req, err := http.NewRequestWithContext(ctx, http.MethodHead, c.url("/api/v1/sec/attachment/"+url.PathEscape(id)), nil)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
if c.Token != "" {
|
||||
req.Header.Set(c.AuthHeader, c.Token)
|
||||
}
|
||||
httpClient := c.HTTPClient
|
||||
if httpClient == nil {
|
||||
httpClient = http.DefaultClient
|
||||
}
|
||||
resp, err := httpClient.Do(req)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
if resp.StatusCode < 200 || resp.StatusCode >= 300 {
|
||||
body, _ := io.ReadAll(resp.Body)
|
||||
return 0, fmt.Errorf("%s %s: %s: %s", req.Method, req.URL, resp.Status, strings.TrimSpace(string(body)))
|
||||
}
|
||||
return resp.ContentLength, nil
|
||||
}
|
||||
|
||||
func (c *DocspellClient) DownloadAttachment(ctx context.Context, id string) ([]byte, error) {
|
||||
return c.doBytes(ctx, http.MethodGet, "/api/v1/sec/attachment/"+url.PathEscape(id), nil)
|
||||
}
|
||||
@@ -179,7 +203,11 @@ func (c *DocspellClient) do(req *http.Request) ([]byte, error) {
|
||||
if c.Token != "" {
|
||||
req.Header.Set(c.AuthHeader, c.Token)
|
||||
}
|
||||
resp, err := c.HTTPClient.Do(req)
|
||||
httpClient := c.HTTPClient
|
||||
if httpClient == nil {
|
||||
httpClient = http.DefaultClient
|
||||
}
|
||||
resp, err := httpClient.Do(req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user