-
Notifications
You must be signed in to change notification settings - Fork 5.4k
New Components - convertapi #16425
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 - convertapi #16425
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
82e2584
convertapi init
luancazarine 5517033
[Components] convertapi #13324
luancazarine d8be3d9
pnpm update
luancazarine 74f4664
some adjusts
luancazarine f62e4a5
Update components/convertapi/actions/convert-web-url/convert-web-url.mjs
luancazarine 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 was deleted.
Oops, something went wrong.
79 changes: 79 additions & 0 deletions
79
components/convertapi/actions/convert-base64-encoded-file/convert-base64-encoded-file.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,79 @@ | ||
import FormData from "form-data"; | ||
import { saveFile } from "../../common/utils.mjs"; | ||
import convertapi from "../../convertapi.app.mjs"; | ||
|
||
export default { | ||
key: "convertapi-convert-base64-encoded-file", | ||
name: "Convert Base64 Encoded File", | ||
description: "This action converts a base64-string-encoded file into the user-specified format. [See the documentation](https://v2.convertapi.com/info/openapi)", | ||
version: "0.0.1", | ||
type: "action", | ||
props: { | ||
convertapi, | ||
base64String: { | ||
propDefinition: [ | ||
convertapi, | ||
"base64String", | ||
], | ||
}, | ||
filename: { | ||
type: "string", | ||
label: "Filename", | ||
description: "Converted output file name without extension. The extension will be added automatically.", | ||
}, | ||
formatFrom: { | ||
propDefinition: [ | ||
convertapi, | ||
"formatFrom", | ||
], | ||
reloadProps: true, | ||
}, | ||
}, | ||
async additionalProps() { | ||
const props = {}; | ||
if (this.formatFrom) { | ||
const { paths } = await this.convertapi.getAllowedFormats({ | ||
formatFrom: this.formatFrom, | ||
}); | ||
|
||
const str = `/convert/${this.formatFrom}/to/`; | ||
|
||
const allowedFormats = Object.keys(paths).filter((format) => { | ||
if (format.startsWith(str)) { | ||
return true; | ||
} | ||
}) | ||
.map((format) => format.slice(str.length)); | ||
|
||
props.formatTo = { | ||
type: "string", | ||
label: "Format To", | ||
description: "The format to convert the file to.", | ||
options: allowedFormats, | ||
}; | ||
} | ||
return props; | ||
}, | ||
async run({ $ }) { | ||
const buffer = Buffer.from(this.base64String, "base64"); | ||
const data = new FormData(); | ||
data.append("File", buffer, `${this.filename}.${this.formatFrom}`); | ||
|
||
const { Files } = await this.convertapi.convertFileToFormat({ | ||
$, | ||
data, | ||
maxBodyLength: Infinity, | ||
headers: data.getHeaders(), | ||
formatFrom: this.formatFrom, | ||
formatTo: this.formatTo, | ||
}); | ||
|
||
await saveFile(Files); | ||
const filename = Files[0].FileName; | ||
|
||
$.export("$summary", `Successfully converted base64 encoded file to ${this.formatTo} and saved in /tmp directory as **${filename}**.`); | ||
return { | ||
filepath: `/tmp/${filename}`, | ||
}; | ||
}, | ||
}; |
80 changes: 80 additions & 0 deletions
80
components/convertapi/actions/convert-file/convert-file.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,80 @@ | ||
import FormData from "form-data"; | ||
import fs from "fs"; | ||
import { | ||
checkTmp, saveFile, | ||
} from "../../common/utils.mjs"; | ||
import convertapi from "../../convertapi.app.mjs"; | ||
|
||
export default { | ||
key: "convertapi-convert-file", | ||
name: "Convert File", | ||
description: "Use this action to convert files to the chosen format. [See the documentation](https://v2.convertapi.com/info/openapi)", | ||
version: "0.0.1", | ||
type: "action", | ||
props: { | ||
convertapi, | ||
file: { | ||
type: "string", | ||
label: "File", | ||
description: "The path to the 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)", | ||
}, | ||
formatFrom: { | ||
propDefinition: [ | ||
convertapi, | ||
"formatFrom", | ||
], | ||
reloadProps: true, | ||
}, | ||
}, | ||
async additionalProps() { | ||
const props = {}; | ||
if (this.formatFrom) { | ||
const { paths } = await this.convertapi.getAllowedFormats({ | ||
formatFrom: this.formatFrom, | ||
}); | ||
|
||
const str = `/convert/${this.formatFrom}/to/`; | ||
|
||
const allowedFormats = Object.keys(paths).filter((format) => { | ||
if (format.startsWith(str)) { | ||
return true; | ||
} | ||
}) | ||
.map((format) => format.slice(str.length)); | ||
|
||
props.formatTo = { | ||
type: "string", | ||
label: "Format To", | ||
description: "The format to convert the file to.", | ||
options: allowedFormats, | ||
}; | ||
} | ||
return props; | ||
}, | ||
async run({ $ }) { | ||
try { | ||
const file = fs.createReadStream(checkTmp(this.file)); | ||
const data = new FormData(); | ||
data.append("File", file); | ||
|
||
luancazarine marked this conversation as resolved.
Show resolved
Hide resolved
|
||
const { Files } = await this.convertapi.convertFileToFormat({ | ||
$, | ||
data, | ||
maxBodyLength: Infinity, | ||
headers: data.getHeaders(), | ||
formatFrom: this.formatFrom, | ||
formatTo: this.formatTo, | ||
}); | ||
|
||
await saveFile(Files); | ||
const filename = Files[0].FileName; | ||
|
||
$.export("$summary", `Successfully converted file to ${this.formatTo} format and saved in /tmp directory as **${filename}**.`); | ||
return { | ||
filepath: `/tmp/${filename}`, | ||
}; | ||
} catch (error) { | ||
throw new Error(`Failed to convert file: ${error.message}`); | ||
} | ||
}, | ||
}; |
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.