Skip to content

Commit 4feefb4

Browse files
authored
Spider new components (#14288)
* Initial AI-generated code * Package and app file updates * Action adjustments * pnpm * fix
1 parent 1c4a740 commit 4feefb4

File tree

4 files changed

+79
-6
lines changed

4 files changed

+79
-6
lines changed
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import spider from "../../spider.app.mjs";
2+
3+
export default {
4+
key: "spider-scrape-new-page",
5+
name: "Scrape New Page",
6+
description: "Initiates a new page scrape (crawl). [See the documentation](https://spider.cloud/docs/api#crawl-website)",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
spider,
11+
infoBox: {
12+
type: "alert",
13+
alertType: "info",
14+
content: "See [the Spider documentation](https://spider.cloud/docs/api#crawl-website) for information on limits and best practices.",
15+
},
16+
url: {
17+
type: "string",
18+
label: "URL",
19+
description: "The URI resource to crawl, e.g. `https://spider.cloud`. This can be a comma split list for multiple urls.",
20+
},
21+
limit: {
22+
type: "integer",
23+
label: "Limit",
24+
description: "The maximum amount of pages allowed to crawl per website. Default is 0, which crawls all pages.",
25+
optional: true,
26+
},
27+
storeData: {
28+
type: "boolean",
29+
label: "Store Data",
30+
description: "Decide whether to store data. Default is `false`.",
31+
optional: true,
32+
},
33+
},
34+
async run({ $ }) {
35+
const content = await this.spider.initiateCrawl({
36+
$,
37+
data: {
38+
url: this.url,
39+
limit: this.limit,
40+
store_data: this.storeData,
41+
},
42+
});
43+
$.export("$summary", `Successfully scraped URL ${this.url}`);
44+
return content;
45+
},
46+
};

components/spider/package.json

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

components/spider/spider.app.mjs

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,32 @@
1+
import { axios } from "@pipedream/platform";
2+
13
export default {
24
type: "app",
35
app: "spider",
46
propDefinitions: {},
57
methods: {
6-
// this.$auth contains connected account data
7-
authKeys() {
8-
console.log(Object.keys(this.$auth));
8+
_baseUrl() {
9+
return "https://api.spider.cloud";
10+
},
11+
async _makeRequest({
12+
$ = this, path = "/", headers, ...otherOpts
13+
} = {}) {
14+
return axios($, {
15+
...otherOpts,
16+
url: this._baseUrl() + path,
17+
headers: {
18+
...headers,
19+
"Authorization": `Bearer ${this.$auth.api_key}`,
20+
"Content-Type": "application/json",
21+
},
22+
});
23+
},
24+
async initiateCrawl(args) {
25+
return this._makeRequest({
26+
method: "POST",
27+
path: "/crawl",
28+
...args,
29+
});
930
},
1031
},
1132
};

pnpm-lock.yaml

Lines changed: 4 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)