Skip to content

Commit a27435a

Browse files
committed
Add animated
1 parent 28952f3 commit a27435a

2 files changed

Lines changed: 32 additions & 6 deletions

File tree

capture.go

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ const (
2020
RequestTypePDF RequestType = "pdf"
2121
RequestTypeContent RequestType = "content"
2222
RequestTypeMetadata RequestType = "metadata"
23+
RequestTypeAnimated RequestType = "animated"
2324
)
2425

2526
type RequestOptions map[string]interface{}
@@ -77,10 +78,6 @@ func (c *Capture) toQueryString(options RequestOptions) string {
7778
params := make(map[string]string)
7879

7980
for key, value := range options {
80-
if key == "format" {
81-
continue
82-
}
83-
8481
if value == nil || value == "" {
8582
continue
8683
}
@@ -171,6 +168,10 @@ func (c *Capture) BuildMetadataURL(targetURL string, options RequestOptions) (st
171168
return c.buildURL(RequestTypeMetadata, targetURL, options)
172169
}
173170

171+
func (c *Capture) BuildAnimatedURL(targetURL string, options RequestOptions) (string, error) {
172+
return c.buildURL(RequestTypeAnimated, targetURL, options)
173+
}
174+
174175
func (c *Capture) FetchImage(targetURL string, options RequestOptions) ([]byte, error) {
175176
url, err := c.BuildImageURL(targetURL, options)
176177
if err != nil {
@@ -223,6 +224,7 @@ type ContentResponse struct {
223224
Success bool `json:"success"`
224225
HTML string `json:"html"`
225226
TextContent string `json:"textContent"`
227+
Markdown string `json:"markdown"`
226228
}
227229

228230
func (c *Capture) FetchContent(targetURL string, options RequestOptions) (*ContentResponse, error) {
@@ -276,4 +278,28 @@ func (c *Capture) FetchMetadata(targetURL string, options RequestOptions) (*Meta
276278
}
277279

278280
return &metadataResp, nil
281+
}
282+
283+
func (c *Capture) FetchAnimated(targetURL string, options RequestOptions) ([]byte, error) {
284+
url, err := c.BuildAnimatedURL(targetURL, options)
285+
if err != nil {
286+
return nil, err
287+
}
288+
289+
resp, err := c.Client.Get(url)
290+
if err != nil {
291+
return nil, fmt.Errorf("failed to fetch animated: %w", err)
292+
}
293+
defer resp.Body.Close()
294+
295+
if resp.StatusCode != http.StatusOK {
296+
return nil, fmt.Errorf("HTTP error: %d", resp.StatusCode)
297+
}
298+
299+
buf, err := io.ReadAll(resp.Body)
300+
if err != nil {
301+
return nil, fmt.Errorf("failed to read response body: %w", err)
302+
}
303+
304+
return buf, nil
279305
}

capture_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,12 +78,12 @@ func TestToQueryString(t *testing.T) {
7878
expected: "height=1080&width=1920",
7979
},
8080
{
81-
name: "with format (should be ignored)",
81+
name: "with format",
8282
options: RequestOptions{
8383
"width": 1920,
8484
"format": "png",
8585
},
86-
expected: "width=1920",
86+
expected: "format=png&width=1920",
8787
},
8888
{
8989
name: "with empty values (should be ignored)",

0 commit comments

Comments
 (0)