|
| 1 | +import { axios } from "@pipedream/platform"; |
| 2 | + |
1 | 3 | export default { |
2 | 4 | type: "app", |
3 | 5 | 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 | + }, |
5 | 99 | 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 | + }); |
9 | 132 | }, |
10 | 133 | }, |
11 | 134 | }; |
0 commit comments