-
Notifications
You must be signed in to change notification settings - Fork 5.5k
Screenshotbase - New Action #18752
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Screenshotbase - New Action #18752
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
100 changes: 100 additions & 0 deletions
100
components/screenshotbase/actions/take-screenshot/take-screenshot.mjs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,100 @@ | ||
| import screenshotbase from "../../screenshotbase.app.mjs"; | ||
| import { ConfigurationError } from "@pipedream/platform"; | ||
| import fs from "fs"; | ||
|
|
||
| export default { | ||
| key: "screenshotbase-take-screenshot", | ||
| name: "Take a Screenshot", | ||
| description: "Take a screenshot with ScreenshotBase. [See the documentation](https://screenshotbase.com/docs/take)", | ||
| version: "0.0.1", | ||
| type: "action", | ||
| annotations: { | ||
| destructiveHint: false, | ||
| openWorldHint: true, | ||
| readOnlyHint: false, | ||
| }, | ||
| props: { | ||
| screenshotbase, | ||
| url: { | ||
| propDefinition: [ | ||
| screenshotbase, | ||
| "url", | ||
| ], | ||
| }, | ||
| format: { | ||
| propDefinition: [ | ||
| screenshotbase, | ||
| "format", | ||
| ], | ||
| }, | ||
| filename: { | ||
| propDefinition: [ | ||
| screenshotbase, | ||
| "filename", | ||
| ], | ||
| }, | ||
| quality: { | ||
| propDefinition: [ | ||
| screenshotbase, | ||
| "quality", | ||
| ], | ||
| }, | ||
| fullPage: { | ||
| propDefinition: [ | ||
| screenshotbase, | ||
| "fullPage", | ||
| ], | ||
| }, | ||
| viewportWidth: { | ||
| propDefinition: [ | ||
| screenshotbase, | ||
| "viewportWidth", | ||
| ], | ||
| }, | ||
| viewportHeight: { | ||
| propDefinition: [ | ||
| screenshotbase, | ||
| "viewportHeight", | ||
| ], | ||
| }, | ||
| syncDir: { | ||
| type: "dir", | ||
| accessMode: "write", | ||
| sync: true, | ||
| }, | ||
| }, | ||
| async run({ $ }) { | ||
| if (this.quality && this.format !== "jpg" && this.format !== "jpeg") { | ||
| throw new ConfigurationError("**Quality** is only supported when the format is `jpg` or `jpeg`"); | ||
| } | ||
|
|
||
| try { | ||
| const response = await this.screenshotbase.takeScreenshot({ | ||
| $, | ||
| params: { | ||
| url: this.url, | ||
| format: this.format, | ||
| quality: this.quality, | ||
| full_page: this.fullPage, | ||
| viewport_width: this.viewportWidth, | ||
| viewport_height: this.viewportHeight, | ||
| }, | ||
| }); | ||
|
|
||
| const rawcontent = response.toString("base64"); | ||
| const buffer = Buffer.from(rawcontent, "base64"); | ||
| const downloadedFilepath = `/tmp/${this.filename}`; | ||
| fs.writeFileSync(downloadedFilepath, buffer); | ||
michelle0927 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| const filedata = [ | ||
| this.filename, | ||
| downloadedFilepath, | ||
| ]; | ||
|
|
||
| $.export("$summary", `Successfully took the screenshot from ${this.url}`); | ||
| return filedata; | ||
| } catch (error) { | ||
| throw new Error(`Unable to take screenshot from ${this.url}: ${error.message}`); | ||
| } | ||
| }, | ||
| }; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,6 @@ | ||
| { | ||
| "name": "@pipedream/screenshotbase", | ||
| "version": "0.0.1", | ||
| "version": "0.1.0", | ||
| "description": "Pipedream screenshotbase Components", | ||
| "main": "screenshotbase.app.mjs", | ||
| "keywords": [ | ||
|
|
@@ -11,5 +11,8 @@ | |
| "author": "Pipedream <[email protected]> (https://pipedream.com/)", | ||
| "publishConfig": { | ||
| "access": "public" | ||
| }, | ||
| "dependencies": { | ||
| "@pipedream/platform": "^3.1.0" | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,11 +1,76 @@ | ||
| import { axios } from "@pipedream/platform"; | ||
|
|
||
| export default { | ||
| type: "app", | ||
| app: "screenshotbase", | ||
| propDefinitions: {}, | ||
| propDefinitions: { | ||
| url: { | ||
| label: "URL", | ||
| type: "string", | ||
| description: "Website to render", | ||
| }, | ||
| filename: { | ||
| type: "string", | ||
| label: "Target Filename", | ||
| description: "The filename (including extension) that will be used to save the file in /tmp", | ||
| }, | ||
| format: { | ||
| type: "string", | ||
| label: "Format", | ||
| description: "The format of the image returned", | ||
| options: [ | ||
| "jpg", | ||
| "jpeg", | ||
| "png", | ||
| "webp", | ||
| ], | ||
| }, | ||
| quality: { | ||
| type: "integer", | ||
| label: "Quality", | ||
| description: "The quality of the image returned. Only supported when the format is `jpg` or `jpeg`", | ||
| optional: true, | ||
| }, | ||
| fullPage: { | ||
| type: "boolean", | ||
| label: "Full Page", | ||
| description: "Whether to take a screenshot of the full page", | ||
| optional: true, | ||
| }, | ||
| viewportWidth: { | ||
| type: "integer", | ||
| label: "Viewport Width", | ||
| description: "The width of the browser viewport in pixels. The browser's viewport is the window area where you can see the website. Default value is 1280.", | ||
| optional: true, | ||
| }, | ||
| viewportHeight: { | ||
| type: "integer", | ||
| label: "Viewport Height", | ||
| description: "The height of the browser viewport in pixels. The browser's viewport is the window area where you can see the website. Default value is 800.", | ||
| optional: true, | ||
| }, | ||
| }, | ||
| methods: { | ||
| // this.$auth contains connected account data | ||
| authKeys() { | ||
| console.log(Object.keys(this.$auth)); | ||
| _baseUrl() { | ||
| return "https://api.screenshotbase.com/v1"; | ||
| }, | ||
| _makeRequest({ | ||
| $ = this, path, ...opts | ||
| }) { | ||
| return axios($, { | ||
| url: `${this._baseUrl()}${path}`, | ||
| headers: { | ||
| "apikey": `${this.$auth.api_key}`, | ||
| }, | ||
| ...opts, | ||
| }); | ||
| }, | ||
| takeScreenshot(opts = {}) { | ||
| return this._makeRequest({ | ||
| path: "/take", | ||
| responseType: "arraybuffer", | ||
| ...opts, | ||
| }); | ||
| }, | ||
| }, | ||
| }; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.