-
Notifications
You must be signed in to change notification settings - Fork 5.6k
New Components - _2markdown #15471
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
New Components - _2markdown #15471
Changes from all commits
Commits
Show all changes
2 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
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: "_2markdown", | ||
| propDefinitions: {}, | ||
| propDefinitions: { | ||
| filePath: { | ||
| type: "string", | ||
| label: "File Path", | ||
| description: "The path to an HTML file in the `/tmp` directory. [See the documentation on working with files](https://pipedream.com/docs/code/nodejs/working-with-files/#writing-a-file-to-tmp)", | ||
| }, | ||
| }, | ||
| methods: { | ||
| // this.$auth contains connected account data | ||
| authKeys() { | ||
| console.log(Object.keys(this.$auth)); | ||
| _baseUrl() { | ||
| return "https://api.2markdown.com/v1"; | ||
| }, | ||
| _makeRequest({ | ||
| $ = this, | ||
| path, | ||
| headers, | ||
| ...opts | ||
| }) { | ||
| return axios($, { | ||
| url: `${this._baseUrl()}${path}`, | ||
| headers: { | ||
| ...headers, | ||
| "X-Api-Key": this.$auth.api_key, | ||
| }, | ||
| ...opts, | ||
| }); | ||
| }, | ||
| getJobStatus({ | ||
| jobId, ...opts | ||
| }) { | ||
| return this._makeRequest({ | ||
| path: `/pdf2md/${jobId}`, | ||
| ...opts, | ||
| }); | ||
| }, | ||
michelle0927 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| pdfToMarkdown(opts = {}) { | ||
| return this._makeRequest({ | ||
| method: "POST", | ||
| path: "/pdf2md", | ||
| ...opts, | ||
| }); | ||
| }, | ||
| urlToMarkdown(opts = {}) { | ||
| return this._makeRequest({ | ||
| method: "POST", | ||
| path: "/url2md", | ||
| ...opts, | ||
| }); | ||
| }, | ||
| urlToMarkdownWithJs(opts = {}) { | ||
| return this._makeRequest({ | ||
| method: "POST", | ||
| path: "/url2mdjs", | ||
| ...opts, | ||
| }); | ||
| }, | ||
| htmlFileToMarkdown(opts = {}) { | ||
| return this._makeRequest({ | ||
| method: "POST", | ||
| path: "/file2md", | ||
| ...opts, | ||
| }); | ||
| }, | ||
| htmlToMarkdown(opts = {}) { | ||
| return this._makeRequest({ | ||
| method: "POST", | ||
| path: "/html2md", | ||
| ...opts, | ||
| }); | ||
michelle0927 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| }, | ||
| }, | ||
| }; | ||
37 changes: 37 additions & 0 deletions
37
components/_2markdown/actions/html-file-to-markdown/html-file-to-markdown.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,37 @@ | ||
| import _2markdown from "../../_2markdown.app.mjs"; | ||
| import fs from "fs"; | ||
| import FormData from "form-data"; | ||
|
|
||
| export default { | ||
| key: "_2markdown-html-file-to-markdown", | ||
| name: "HTML File to Markdown", | ||
| description: "Convert an HTML file to Markdown format. [See the documentation](https://2markdown.com/docs#file2md)", | ||
| version: "0.0.1", | ||
| type: "action", | ||
| props: { | ||
| _2markdown, | ||
| filePath: { | ||
| propDefinition: [ | ||
| _2markdown, | ||
| "filePath", | ||
| ], | ||
| }, | ||
| }, | ||
| async run({ $ }) { | ||
| const form = new FormData(); | ||
|
|
||
| form.append("document", fs.createReadStream(this.filePath.includes("tmp/") | ||
| ? this.filePath | ||
| : `/tmp/${this.filePath}`)); | ||
michelle0927 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| const response = await this._2markdown.htmlFileToMarkdown({ | ||
| $, | ||
| headers: form.getHeaders(), | ||
| data: form, | ||
| }); | ||
|
|
||
| $.export("$summary", "Successfully converted HTML file to markdown."); | ||
|
|
||
| return response; | ||
| }, | ||
michelle0927 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| }; | ||
29 changes: 29 additions & 0 deletions
29
components/_2markdown/actions/html-to-markdown/html-to-markdown.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,29 @@ | ||
| import _2markdown from "../../_2markdown.app.mjs"; | ||
|
|
||
| export default { | ||
| key: "_2markdown-html-to-markdown", | ||
| name: "HTML to Markdown", | ||
| description: "Convert raw HTML content to Markdown format. [See the documentation](https://2markdown.com/docs#html2md)", | ||
| version: "0.0.1", | ||
| type: "action", | ||
| props: { | ||
| _2markdown, | ||
| html: { | ||
| type: "string", | ||
| label: "HTML", | ||
| description: "The HTML content to be converted to Markdown", | ||
| }, | ||
| }, | ||
| async run({ $ }) { | ||
| const response = await this._2markdown.htmlToMarkdown({ | ||
| $, | ||
| data: { | ||
| html: this.html, | ||
| }, | ||
| }); | ||
|
|
||
| $.export("$summary", "Successfully converted HTML to markdown."); | ||
|
|
||
| return response; | ||
| }, | ||
michelle0927 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| }; | ||
58 changes: 58 additions & 0 deletions
58
components/_2markdown/actions/pdf-to-markdown/pdf-to-markdown.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,58 @@ | ||
| import _2markdown from "../../_2markdown.app.mjs"; | ||
| import fs from "fs"; | ||
| import FormData from "form-data"; | ||
|
|
||
| export default { | ||
| key: "_2markdown-pdf-to-markdown", | ||
| name: "PDF to Markdown", | ||
| description: "Convert a PDF document to Markdown format. [See the documentation](https://2markdown.com/docs#pdf2md)", | ||
| version: "0.0.1", | ||
| type: "action", | ||
| props: { | ||
| _2markdown, | ||
| filePath: { | ||
| propDefinition: [ | ||
| _2markdown, | ||
| "filePath", | ||
| ], | ||
| description: "The path to a PDF file in the `/tmp` directory. [See the documentation on working with files](https://pipedream.com/docs/code/nodejs/working-with-files/#writing-a-file-to-tmp)", | ||
| }, | ||
| waitForCompletion: { | ||
| type: "boolean", | ||
| label: "Wait for Completion", | ||
| description: "Set to `true` to poll the API in 3-second intervals until the job is complete", | ||
| optional: true, | ||
| }, | ||
| }, | ||
| async run({ $ }) { | ||
| const form = new FormData(); | ||
|
|
||
| form.append("document", fs.createReadStream(this.filePath.includes("tmp/") | ||
| ? this.filePath | ||
| : `/tmp/${this.filePath}`)); | ||
michelle0927 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| let response = await this._2markdown.pdfToMarkdown({ | ||
| $, | ||
| headers: form.getHeaders(), | ||
| data: form, | ||
| }); | ||
|
|
||
| if (this.waitForCompletion) { | ||
| const timer = (ms) => new Promise((res) => setTimeout(res, ms)); | ||
| const jobId = response.jobId; | ||
| while (response.status === "processing" || response.status === "pending") { | ||
| response = await this._2markdown.getJobStatus({ | ||
| $, | ||
| jobId, | ||
| }); | ||
| await timer(3000); | ||
| } | ||
| } | ||
michelle0927 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| $.export("$summary", `${this.waitForCompletion | ||
| ? "Finished" | ||
| : "Started"} converting PDF file to markdown.`); | ||
|
|
||
| return response; | ||
| }, | ||
| }; | ||
39 changes: 39 additions & 0 deletions
39
components/_2markdown/actions/url-to-markdown/url-to-markdown.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,39 @@ | ||
| import _2markdown from "../../_2markdown.app.mjs"; | ||
|
|
||
| export default { | ||
| key: "_2markdown-url-to-markdown", | ||
| name: "URL to Markdown", | ||
| description: "Extract the essential content of a website as plaintext. [See the documentation](https://2markdown.com/docs#url2md)", | ||
| version: "0.0.1", | ||
| type: "action", | ||
| props: { | ||
| _2markdown, | ||
| url: { | ||
| type: "string", | ||
| label: "URL", | ||
| description: "The URL to be processed. Costs 1 credit per request.", | ||
| }, | ||
| js: { | ||
| type: "boolean", | ||
| label: "Include Javascript Support", | ||
| description: "Set to `true` to extract content as plaintext including any javascript-rendered resources. Costs an additional credit per request.", | ||
| optional: true, | ||
| }, | ||
| }, | ||
| async run({ $ }) { | ||
| const fn = this.js | ||
| ? this._2markdown.urlToMarkdownWithJs | ||
| : this._2markdown.urlToMarkdown; | ||
|
|
||
| const response = await fn({ | ||
| $, | ||
| data: { | ||
| url: this.url, | ||
| }, | ||
| }); | ||
michelle0927 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| $.export("$summary", "Successfully extracted website content."); | ||
|
|
||
| return response; | ||
| }, | ||
| }; | ||
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
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.