Skip to content

Commit d9ed5f4

Browse files
committed
CustomJS: Add Run Puppoteer and HTML to PNG actions
1 parent 9bbe06a commit d9ed5f4

File tree

4 files changed

+109
-3
lines changed

4 files changed

+109
-3
lines changed

.wordlist.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ CSVs
153153
Ctrl
154154
Cuep
155155
customizable
156+
CustomJS
156157
customResponse
157158
cvIZPg
158159
DaData
@@ -687,6 +688,7 @@ PropType
687688
proto
688689
PRs
689690
Psw
691+
Puppoteer
690692
Pushbullet
691693
Pushsafer
692694
Pushshift
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import customjs from "../../customjs.app.mjs";
2+
import fs from "fs";
3+
import { normalizeFilepath } from "../common/utils.mjs";
4+
5+
export default {
6+
key: "customjs-convert-html-to-png",
7+
name: "Convert HTML to PNG",
8+
description: "Converts an HTML string to a PNG image. [See the documentation](https://www.customjs.space/api/docs#_4-html-to-png)",
9+
version: "0.0.1",
10+
type: "action",
11+
props: {
12+
customjs,
13+
html: {
14+
type: "string",
15+
label: "HTML",
16+
description: "The HTML string to be converted to a PNG",
17+
},
18+
filename: {
19+
propDefinition: [
20+
customjs,
21+
"filename",
22+
],
23+
},
24+
},
25+
async run({ $ }) {
26+
const fileContent = await this.customjs.convertHtmlToPng({
27+
$,
28+
data: {
29+
input: this.html,
30+
code: "const { HTML2PNG } = require('./utils'); return HTML2PNG(input);",
31+
returnBinary: "true",
32+
},
33+
});
34+
35+
const filepath = normalizeFilepath(this.filename);
36+
fs.writeFileSync(filepath, Buffer.from(fileContent));
37+
38+
$.export("$summary", "Successfully converted HTML to PNG");
39+
return {
40+
filename: this.filename,
41+
filepath,
42+
};
43+
},
44+
};
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import customjs from "../../customjs.app.mjs";
2+
import fs from "fs";
3+
import { normalizeFilepath } from "../common/utils.mjs";
4+
5+
export default {
6+
key: "customjs-run-puppoteer",
7+
name: "Run Puppoteer",
8+
description: "run-puppoteer. [See the documentation](https://www.customjs.space/api/docs#_5-run-puppoteer)",
9+
version: "0.0.1",
10+
type: "action",
11+
props: {
12+
customjs,
13+
code: {
14+
type: "string",
15+
label: "Code",
16+
description: "Enter code you want to run on puppeteer.",
17+
},
18+
filename: {
19+
propDefinition: [
20+
customjs,
21+
"filename",
22+
],
23+
},
24+
},
25+
async run({ $ }) {
26+
const fileContent = await this.customjs.runPuppoteer({
27+
$,
28+
data: {
29+
input: this.code,
30+
code: "const { PUPPETEER } = require('./utils'); return PUPPETEER(input);",
31+
returnBinary: "true",
32+
},
33+
});
34+
35+
const filepath = normalizeFilepath(this.filename);
36+
fs.writeFileSync(filepath, Buffer.from(fileContent));
37+
38+
$.export("$summary", "Successfully run the puppoteer code.");
39+
return {
40+
filename: this.filename,
41+
filepath,
42+
};
43+
},
44+
};

components/customjs/customjs.app.mjs

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,23 +31,39 @@ export default {
3131
convertHtmlToPdf(opts = {}) {
3232
return this._makeRequest({
3333
headers: {
34-
"customjs-origin": "zapier/generatePDF",
34+
"customjs-origin": "pipedream/generatePDF",
35+
},
36+
...opts,
37+
});
38+
},
39+
convertHtmlToPng(opts = {}) {
40+
return this._makeRequest({
41+
headers: {
42+
"customjs-origin": "pipedream/generatePNG",
3543
},
3644
...opts,
3745
});
3846
},
3947
createScreenshot(opts = {}) {
4048
return this._makeRequest({
4149
headers: {
42-
"customjs-origin": "zapier/screenshot",
50+
"customjs-origin": "pipedream/screenshot",
4351
},
4452
...opts,
4553
});
4654
},
4755
mergePdfs(opts = {}) {
4856
return this._makeRequest({
4957
headers: {
50-
"customjs-origin": "zapier/mergePDFs",
58+
"customjs-origin": "pipedream/mergePDFs",
59+
},
60+
...opts,
61+
});
62+
},
63+
runPuppoteer(opts = {}) {
64+
return this._makeRequest({
65+
headers: {
66+
"customjs-origin": "pipedream/puppeteer",
5167
},
5268
...opts,
5369
});

0 commit comments

Comments
 (0)