Skip to content

Commit 0f40dfb

Browse files
committed
Added actions
1 parent bdd5ea4 commit 0f40dfb

File tree

5 files changed

+282
-9
lines changed

5 files changed

+282
-9
lines changed
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
import app from "../../capturekit.app.mjs";
2+
import fs from "fs";
3+
import path from "path";
4+
5+
export default {
6+
key: "capturekit-capture-screenshot",
7+
name: "Capture Screenshot",
8+
description: "Capture a high-quality image of any webpage. [See the documentation](https://docs.capturekit.dev/api-reference/screenshot-api)",
9+
version: "0.0.1",
10+
type: "action",
11+
props: {
12+
app,
13+
url: {
14+
propDefinition: [
15+
app,
16+
"url",
17+
],
18+
},
19+
format: {
20+
propDefinition: [
21+
app,
22+
"format",
23+
],
24+
},
25+
device: {
26+
propDefinition: [
27+
app,
28+
"device",
29+
],
30+
},
31+
cache: {
32+
propDefinition: [
33+
app,
34+
"cache",
35+
],
36+
},
37+
fullPageScroll: {
38+
propDefinition: [
39+
app,
40+
"fullPageScroll",
41+
],
42+
},
43+
fileName: {
44+
propDefinition: [
45+
app,
46+
"fileName",
47+
],
48+
},
49+
},
50+
async run({ $ }) {
51+
const response = await this.app.captureScreenshot({
52+
$,
53+
params: {
54+
url: this.url,
55+
format: this.format,
56+
device: this.device,
57+
cache: this.cache,
58+
full_page_scroll: this.fullPageScroll,
59+
},
60+
responseType: "arraybuffer",
61+
});
62+
63+
const fileExtension = this.format || "png";
64+
const fileName = `${this.fileName}.${fileExtension}`;
65+
const filePath = path.join("/tmp", fileName);
66+
67+
await fs.promises.writeFile(filePath, response);
68+
69+
$.export("$summary", `Screenshot successfully saved to: ${filePath}`);
70+
71+
return filePath;
72+
},
73+
};
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
import app from "../../capturekit.app.mjs";
2+
3+
export default {
4+
key: "capturekit-scrape-content",
5+
name: "Scrape Content",
6+
description: "Extract structured data from any webpage, including metadata, links, and raw HTML. [See the documentation](https://docs.capturekit.dev/api-reference/content-api)",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
app,
11+
12+
url: {
13+
propDefinition: [
14+
app,
15+
"url",
16+
],
17+
},
18+
19+
includeHtml: {
20+
propDefinition: [
21+
app,
22+
"includeHtml",
23+
],
24+
},
25+
26+
useDefuddle: {
27+
propDefinition: [
28+
app,
29+
"useDefuddle",
30+
],
31+
},
32+
33+
selector: {
34+
propDefinition: [
35+
app,
36+
"selector",
37+
],
38+
},
39+
40+
removeSelectors: {
41+
propDefinition: [
42+
app,
43+
"removeSelectors",
44+
],
45+
},
46+
47+
blockUrls: {
48+
propDefinition: [
49+
app,
50+
"blockUrls",
51+
],
52+
},
53+
},
54+
async run({ $ }) {
55+
const response = await this.app.scrapeContent({
56+
$,
57+
params: {
58+
url: this.url,
59+
include_html: this.includeHtml,
60+
use_defuddle: this.useDefuddle,
61+
selector: this.selector,
62+
remove_selectors: (this.removeSelectors || []).join(","),
63+
block_urls: (this.blockUrls || []).join(","),
64+
},
65+
});
66+
$.export("$summary", "Successfully sent the Scrape Content request");
67+
return response;
68+
},
69+
};
Lines changed: 127 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,134 @@
1+
import { axios } from "@pipedream/platform";
2+
13
export default {
24
type: "app",
35
app: "capturekit",
4-
propDefinitions: {},
6+
propDefinitions: {
7+
url: {
8+
type: "string",
9+
label: "URL",
10+
description: "Target webpage to capture",
11+
},
12+
format: {
13+
type: "string",
14+
label: "Format",
15+
description: "The output format of the screenshot",
16+
optional: true,
17+
options: [
18+
"webp",
19+
"jpeg",
20+
"jpg",
21+
"png",
22+
"pdf",
23+
],
24+
},
25+
device: {
26+
type: "string",
27+
label: "Device",
28+
description: "Device type used for emulation (desktop or mobile)",
29+
optional: true,
30+
options: [
31+
"iphone_14_pro_max",
32+
"iphone_14_pro",
33+
"iphone_13_pro_max",
34+
"iphone_13_mini",
35+
"galaxy_s23_ultra",
36+
"galaxy_s23",
37+
"galaxy_fold4",
38+
"pixel_7_pro",
39+
"pixel_6a",
40+
"redmi_note_12_pro",
41+
"redmi_note_11",
42+
"huawei_p60_pro",
43+
"huawei_mate_50_pro",
44+
"iphone_x",
45+
"iphone_12",
46+
"pixel_5",
47+
"galaxy_s8",
48+
"ipad",
49+
],
50+
},
51+
cache: {
52+
type: "boolean",
53+
label: "Cache",
54+
description: "Enable or disable response caching",
55+
optional: true,
56+
},
57+
fullPageScroll: {
58+
type: "boolean",
59+
label: "Full Page Scroll",
60+
description: "Scroll through the entire page before capturing",
61+
optional: true,
62+
},
63+
includeHtml: {
64+
type: "boolean",
65+
label: "Include HTML",
66+
description: "Return the raw HTML content in the response",
67+
optional: true,
68+
},
69+
useDefuddle: {
70+
type: "boolean",
71+
label: "Use Defuddle",
72+
description: "Use Defuddle to clean and extract the main content from web pages",
73+
optional: true,
74+
},
75+
selector: {
76+
type: "string",
77+
label: "Selector",
78+
description: "Capture a specific element on the page instead of the full viewport",
79+
optional: true,
80+
},
81+
removeSelectors: {
82+
type: "string[]",
83+
label: "Remove Selectors",
84+
description: "A list of elements to hide before capturing",
85+
optional: true,
86+
},
87+
blockUrls: {
88+
type: "string[]",
89+
label: "Block URLs",
90+
description: "A ist of URL patterns to block. You can specify URLs, domains, or simple patterns, e.g.: `.example.com/`",
91+
optional: true,
92+
},
93+
fileName: {
94+
type: "string",
95+
label: "File Name",
96+
description: "Name of the screenshot file that will be saved on /tmp",
97+
},
98+
},
599
methods: {
6-
// this.$auth contains connected account data
7-
authKeys() {
8-
console.log(Object.keys(this.$auth));
100+
_baseUrl() {
101+
return "https://api.capturekit.dev";
102+
},
103+
async _makeRequest(opts = {}) {
104+
const {
105+
$ = this,
106+
path,
107+
headers,
108+
...otherOpts
109+
} = opts;
110+
return axios($, {
111+
...otherOpts,
112+
url: this._baseUrl() + path,
113+
headers: {
114+
"x-access-key": `${this.$auth.access_key}`,
115+
...headers,
116+
},
117+
});
118+
},
119+
120+
async captureScreenshot(args = {}) {
121+
return this._makeRequest({
122+
path: "/capture",
123+
...args,
124+
});
125+
},
126+
127+
async scrapeContent(args = {}) {
128+
return this._makeRequest({
129+
path: "/content",
130+
...args,
131+
});
9132
},
10133
},
11134
};

components/capturekit/package.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pipedream/capturekit",
3-
"version": "0.0.1",
3+
"version": "0.1.0",
44
"description": "Pipedream CaptureKit Components",
55
"main": "capturekit.app.mjs",
66
"keywords": [
@@ -11,5 +11,8 @@
1111
"author": "Pipedream <[email protected]> (https://pipedream.com/)",
1212
"publishConfig": {
1313
"access": "public"
14+
},
15+
"dependencies": {
16+
"@pipedream/platform": "^3.1.0"
1417
}
15-
}
18+
}

pnpm-lock.yaml

Lines changed: 8 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)