From 82e2584977fc3125ccf3f6645ce1b72082a1fb88 Mon Sep 17 00:00:00 2001 From: Luan Cazarine Date: Thu, 24 Apr 2025 16:08:36 -0300 Subject: [PATCH 1/5] convertapi init --- .../convert-base64-encoded-file.mjs | 45 ++++ .../actions/convert-file/convert-file.mjs | 39 +++ .../convert-web-url/convert-web-url.mjs | 153 +++++++++++ components/convertapi/app/convertapi.app.ts | 2 +- components/convertapi/convertapi.app.mjs | 249 ++++++++++++++++++ 5 files changed, 487 insertions(+), 1 deletion(-) create mode 100644 components/convertapi/actions/convert-base64-encoded-file/convert-base64-encoded-file.mjs create mode 100644 components/convertapi/actions/convert-file/convert-file.mjs create mode 100644 components/convertapi/actions/convert-web-url/convert-web-url.mjs create mode 100644 components/convertapi/convertapi.app.mjs diff --git a/components/convertapi/actions/convert-base64-encoded-file/convert-base64-encoded-file.mjs b/components/convertapi/actions/convert-base64-encoded-file/convert-base64-encoded-file.mjs new file mode 100644 index 0000000000000..1da60df8f7420 --- /dev/null +++ b/components/convertapi/actions/convert-base64-encoded-file/convert-base64-encoded-file.mjs @@ -0,0 +1,45 @@ +import convertapi from "../../convertapi.app.mjs"; +import { axios } from "@pipedream/platform"; + +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.{{ts}}", + type: "action", + props: { + convertapi, + base64String: { + propDefinition: [ + convertapi, + "base64String", + ], + }, + format: { + propDefinition: [ + convertapi, + "format", + ], + optional: true, + }, + }, + async run({ $ }) { + const response = await this.convertapi.convertBase64ToFormat({ + base64String: this.base64String, + format: this.format, + }); + + const files = response.Files || []; + for (const file of files) { + const filePath = `/tmp/${file.FileName}`; + await axios($, { + method: "GET", + url: file.Url, + responseType: "arraybuffer", + }).then((buffer) => require("fs").promises.writeFile(filePath, buffer)); + } + + $.export("$summary", `Successfully converted base64 encoded file to ${this.format || "default format"}`); + return response; + }, +}; diff --git a/components/convertapi/actions/convert-file/convert-file.mjs b/components/convertapi/actions/convert-file/convert-file.mjs new file mode 100644 index 0000000000000..e9151bdf97d79 --- /dev/null +++ b/components/convertapi/actions/convert-file/convert-file.mjs @@ -0,0 +1,39 @@ +import convertapi from "../../convertapi.app.mjs"; +import { axios } from "@pipedream/platform"; + +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.{{ts}}", + type: "action", + props: { + convertapi, + file: { + propDefinition: [ + convertapi, + "file", + ], + }, + format: { + propDefinition: [ + convertapi, + "format", + ], + optional: true, + }, + }, + async run({ $ }) { + try { + const response = await this.convertapi.convertFileToFormat({ + file: this.file, + format: this.format, + }); + + $.export("$summary", `Successfully converted file to ${this.format || "default"} format.`); + return response; + } catch (error) { + throw new Error(`Failed to convert file: ${error.message}`); + } + }, +}; diff --git a/components/convertapi/actions/convert-web-url/convert-web-url.mjs b/components/convertapi/actions/convert-web-url/convert-web-url.mjs new file mode 100644 index 0000000000000..53e684b4f1865 --- /dev/null +++ b/components/convertapi/actions/convert-web-url/convert-web-url.mjs @@ -0,0 +1,153 @@ +import convertapi from "../../convertapi.app.mjs"; +import { axios } from "@pipedream/platform"; + +export default { + key: "convertapi-convert-web-url", + name: "Convert Web URL to Specified Format", + description: "Converts a website page to a specified format. [See the documentation](https://v2.convertapi.com/info/openapi)", + version: "0.0.{{ts}}", + type: "action", + props: { + convertapi, + url: { + propDefinition: [ + convertapi, + "url", + ], + }, + format: { + propDefinition: [ + convertapi, + "format", + ], + }, + userJs: { + propDefinition: [ + convertapi, + "userJs", + ], + }, + userCss: { + propDefinition: [ + convertapi, + "userCss", + ], + }, + hideElements: { + propDefinition: [ + convertapi, + "hideElements", + ], + }, + cssMediaType: { + propDefinition: [ + convertapi, + "cssMediaType", + ], + }, + headers: { + propDefinition: [ + convertapi, + "headers", + ], + }, + loadLazyContent: { + propDefinition: [ + convertapi, + "loadLazyContent", + ], + }, + viewportWidth: { + propDefinition: [ + convertapi, + "viewportWidth", + ], + }, + viewportHeight: { + propDefinition: [ + convertapi, + "viewportHeight", + ], + }, + respectViewport: { + propDefinition: [ + convertapi, + "respectViewport", + ], + }, + scale: { + propDefinition: [ + convertapi, + "scale", + ], + }, + pageOrientation: { + propDefinition: [ + convertapi, + "pageOrientation", + ], + }, + pageSize: { + propDefinition: [ + convertapi, + "pageSize", + ], + }, + marginTop: { + propDefinition: [ + convertapi, + "marginTop", + ], + }, + marginRight: { + propDefinition: [ + convertapi, + "marginRight", + ], + }, + marginBottom: { + propDefinition: [ + convertapi, + "marginBottom", + ], + }, + marginLeft: { + propDefinition: [ + convertapi, + "marginLeft", + ], + }, + pageRange: { + propDefinition: [ + convertapi, + "pageRange", + ], + }, + }, + async run({ $ }) { + const response = await this.convertapi.convertUrlToFormat({ + url: this.url, + format: this.format, + userJs: this.userJs, + userCss: this.userCss, + hideElements: this.hideElements, + cssMediaType: this.cssMediaType, + headers: this.headers, + loadLazyContent: this.loadLazyContent, + viewportWidth: this.viewportWidth, + viewportHeight: this.viewportHeight, + respectViewport: this.respectViewport, + scale: this.scale, + pageOrientation: this.pageOrientation, + pageSize: this.pageSize, + marginTop: this.marginTop, + marginRight: this.marginRight, + marginBottom: this.marginBottom, + marginLeft: this.marginLeft, + pageRange: this.pageRange, + }); + + $.export("$summary", `Successfully converted URL to ${this.format || "default format"}`); + return response; + }, +}; diff --git a/components/convertapi/app/convertapi.app.ts b/components/convertapi/app/convertapi.app.ts index 7014e74d92b29..93cd7f684140b 100644 --- a/components/convertapi/app/convertapi.app.ts +++ b/components/convertapi/app/convertapi.app.ts @@ -10,4 +10,4 @@ export default defineApp({ console.log(Object.keys(this.$auth)); }, }, -}); \ No newline at end of file +}); diff --git a/components/convertapi/convertapi.app.mjs b/components/convertapi/convertapi.app.mjs new file mode 100644 index 0000000000000..c2d8cc19100ca --- /dev/null +++ b/components/convertapi/convertapi.app.mjs @@ -0,0 +1,249 @@ +import { axios } from "@pipedream/platform"; + +export default { + type: "app", + app: "convertapi", + propDefinitions: { + base64String: { + type: "string", + label: "Base64 String", + description: "The base64 string of the file to convert", + }, + format: { + type: "string", + label: "Output Format", + description: "The desired output format for the converted file.", + optional: true, + }, + file: { + type: "string", + label: "File", + description: "The file to be converted. Provide a URL or file content.", + }, + url: { + type: "string", + label: "URL", + description: "The website URL to be converted to a specified format.", + }, + userJs: { + type: "string", + label: "User JavaScript", + description: "Execute provided JavaScript before conversion begins.", + optional: true, + }, + userCss: { + type: "string", + label: "User CSS", + description: "Apply additional CSS before conversion begins.", + optional: true, + }, + hideElements: { + type: "string", + label: "Hide Elements", + description: "Element selector string of the DOM elements that need to be hidden during conversion.", + optional: true, + }, + cssMediaType: { + type: "string", + label: "CSS Media Type", + description: "Use CSS media type in conversion process.", + optional: true, + default: "screen", + }, + headers: { + type: "string", + label: "Headers", + description: "Headers to include in the conversion request.", + optional: true, + }, + loadLazyContent: { + type: "boolean", + label: "Load Lazy Content", + description: "Load page images that load only when they are visible.", + optional: true, + default: false, + }, + viewportWidth: { + type: "integer", + label: "Viewport Width", + description: "Sets browser viewport width.", + optional: true, + min: 200, + max: 4000, + default: 1366, + }, + viewportHeight: { + type: "integer", + label: "Viewport Height", + description: "Sets browser viewport height.", + optional: true, + min: 200, + max: 4000, + default: 1024, + }, + respectViewport: { + type: "boolean", + label: "Respect Viewport", + description: "If true, the converter will generate PDF as the content looks like in the browser.", + optional: true, + default: true, + }, + scale: { + type: "integer", + label: "Scale", + description: "Set web page scale value in percentage.", + optional: true, + min: 10, + max: 200, + default: 100, + }, + pageOrientation: { + type: "string", + label: "Page Orientation", + description: "PDF page orientation.", + optional: true, + default: "portrait", + enum: [ + "portrait", + "landscape", + ], + }, + pageSize: { + type: "string", + label: "Page Size", + description: "PDF page size.", + optional: true, + default: "letter", + enum: [ + "a0", + "a1", + "a2", + "a3", + "a4", + "a5", + "a6", + "a7", + "a8", + "a9", + "b0", + "b1", + "b2", + "b3", + "b4", + "b5", + "letter", + "legal", + "ledger", + ], + }, + marginTop: { + type: "integer", + label: "Margin Top", + description: "Set the page top margin in mm.", + optional: true, + min: 0, + max: 500, + default: 10, + }, + marginRight: { + type: "integer", + label: "Margin Right", + description: "Set the page right margin in mm.", + optional: true, + min: 0, + max: 500, + default: 10, + }, + marginBottom: { + type: "integer", + label: "Margin Bottom", + description: "Set the page bottom margin in mm.", + optional: true, + min: 0, + max: 500, + default: 10, + }, + marginLeft: { + type: "integer", + label: "Margin Left", + description: "Set the page left margin in mm.", + optional: true, + min: 0, + max: 500, + default: 10, + }, + pageRange: { + type: "string", + label: "Page Range", + description: "Set page range. Example 1-10 or 1,2,5.", + optional: true, + default: "1-100", + }, + }, + methods: { + _baseUrl() { + return "https://v2.convertapi.com"; + }, + async _makeRequest(opts = {}) { + const { + $ = this, + method = "POST", + path = "/", + headers, + ...otherOpts + } = opts; + return axios($, { + ...otherOpts, + method, + url: this._baseUrl() + path, + headers: { + ...headers, + Authorization: `Bearer ${this.$auth.api_key}`, + }, + }); + }, + async convertBase64ToFormat(opts = {}) { + const { + base64String, format, ...rest + } = opts; + return this._makeRequest({ + path: format + ? `/convert/base64/to/${format}` + : "/convert/base64/to", + data: { + base64_string: base64String, + ...rest, + }, + }); + }, + async convertFileToFormat(opts = {}) { + const { + file, format, ...rest + } = opts; + return this._makeRequest({ + path: format + ? `/convert/file/to/${format}` + : "/convert/file/to", + data: { + file, + ...rest, + }, + }); + }, + async convertUrlToFormat(opts = {}) { + const { + url, format, ...rest + } = opts; + return this._makeRequest({ + path: format + ? `/convert/url/to/${format}` + : "/convert/url/to", + data: { + url, + ...rest, + }, + }); + }, + }, + version: "0.0.{{ts}}", +}; From 551703333de77989575083d6d08adb0ed994a4db Mon Sep 17 00:00:00 2001 From: Luan Cazarine Date: Mon, 28 Apr 2025 13:58:09 -0300 Subject: [PATCH 2/5] [Components] convertapi #13324 Actions - Convert Base64 Encoded File - Convert File - Convert Web URL --- components/convertapi/.gitignore | 3 - .../convert-base64-encoded-file.mjs | 69 ++- .../actions/convert-file/convert-file.mjs | 66 ++- .../convert-web-url/convert-web-url.mjs | 488 ++++++++++++++---- components/convertapi/app/convertapi.app.ts | 13 - components/convertapi/common/constants.mjs | 186 +++++++ components/convertapi/common/utils.mjs | 14 + components/convertapi/convertapi.app.mjs | 246 ++------- components/convertapi/package.json | 10 +- 9 files changed, 725 insertions(+), 370 deletions(-) delete mode 100644 components/convertapi/.gitignore delete mode 100644 components/convertapi/app/convertapi.app.ts create mode 100644 components/convertapi/common/constants.mjs create mode 100644 components/convertapi/common/utils.mjs diff --git a/components/convertapi/.gitignore b/components/convertapi/.gitignore deleted file mode 100644 index ec761ccab7595..0000000000000 --- a/components/convertapi/.gitignore +++ /dev/null @@ -1,3 +0,0 @@ -*.js -*.mjs -dist \ No newline at end of file diff --git a/components/convertapi/actions/convert-base64-encoded-file/convert-base64-encoded-file.mjs b/components/convertapi/actions/convert-base64-encoded-file/convert-base64-encoded-file.mjs index 1da60df8f7420..f38b76a1631a3 100644 --- a/components/convertapi/actions/convert-base64-encoded-file/convert-base64-encoded-file.mjs +++ b/components/convertapi/actions/convert-base64-encoded-file/convert-base64-encoded-file.mjs @@ -1,11 +1,12 @@ +import FormData from "form-data"; +import { saveFile } from "../../common/utils.mjs"; import convertapi from "../../convertapi.app.mjs"; -import { axios } from "@pipedream/platform"; 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.{{ts}}", + version: "0.0.1", type: "action", props: { convertapi, @@ -15,31 +16,61 @@ export default { "base64String", ], }, - format: { + filename: { + type: "string", + label: "Filename", + description: "Converted output file name without extension. The extension will be added automatically.", + }, + formatFrom: { propDefinition: [ convertapi, - "format", + "formatFrom", ], - optional: true, + 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 response = await this.convertapi.convertBase64ToFormat({ - base64String: this.base64String, - format: this.format, + 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, }); - const files = response.Files || []; - for (const file of files) { - const filePath = `/tmp/${file.FileName}`; - await axios($, { - method: "GET", - url: file.Url, - responseType: "arraybuffer", - }).then((buffer) => require("fs").promises.writeFile(filePath, buffer)); - } + await saveFile(Files); - $.export("$summary", `Successfully converted base64 encoded file to ${this.format || "default format"}`); - return response; + $.export("$summary", `Successfully converted base64 encoded file to ${this.formatTo} and saved in /tmp directory as **${Files[0].FileName}**.`); + return; }, }; diff --git a/components/convertapi/actions/convert-file/convert-file.mjs b/components/convertapi/actions/convert-file/convert-file.mjs index e9151bdf97d79..a93a315de3645 100644 --- a/components/convertapi/actions/convert-file/convert-file.mjs +++ b/components/convertapi/actions/convert-file/convert-file.mjs @@ -1,37 +1,75 @@ +import FormData from "form-data"; +import fs from "fs"; +import { + checkTmp, saveFile, +} from "../../common/utils.mjs"; import convertapi from "../../convertapi.app.mjs"; -import { axios } from "@pipedream/platform"; 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.{{ts}}", + version: "0.0.1", type: "action", props: { convertapi, file: { - propDefinition: [ - 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)", }, - format: { + formatFrom: { propDefinition: [ convertapi, - "format", + "formatFrom", ], - optional: true, + 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 response = await this.convertapi.convertFileToFormat({ - file: this.file, - format: this.format, + const file = fs.createReadStream(checkTmp(this.file)); + const data = new FormData(); + data.append("File", file); + + const { Files } = await this.convertapi.convertFileToFormat({ + $, + data, + maxBodyLength: Infinity, + headers: data.getHeaders(), + formatFrom: this.formatFrom, + formatTo: this.formatTo, }); - $.export("$summary", `Successfully converted file to ${this.format || "default"} format.`); - return response; + await saveFile(Files); + + $.export("$summary", `Successfully converted file to ${this.formatTo} format and saved in /tmp directory as **${Files[0].FileName}**.`); + return; } catch (error) { throw new Error(`Failed to convert file: ${error.message}`); } diff --git a/components/convertapi/actions/convert-web-url/convert-web-url.mjs b/components/convertapi/actions/convert-web-url/convert-web-url.mjs index 53e684b4f1865..2390bdd43b57c 100644 --- a/components/convertapi/actions/convert-web-url/convert-web-url.mjs +++ b/components/convertapi/actions/convert-web-url/convert-web-url.mjs @@ -1,153 +1,437 @@ +import FormData from "form-data"; +import { + CSS_MEDIA_TYTPE_OPTIONS, + FIXED_ELEMENTS_OPTIONS, + FORMAT_TO_OPTIONS, + PAGE_ORIENTATION_OPTIONS, + PAGE_SIZE_OPTIONS, +} from "../../common/constants.mjs"; +import { saveFile } from "../../common/utils.mjs"; import convertapi from "../../convertapi.app.mjs"; -import { axios } from "@pipedream/platform"; export default { key: "convertapi-convert-web-url", name: "Convert Web URL to Specified Format", description: "Converts a website page to a specified format. [See the documentation](https://v2.convertapi.com/info/openapi)", - version: "0.0.{{ts}}", + version: "0.0.1", type: "action", props: { convertapi, url: { - propDefinition: [ - convertapi, - "url", - ], + type: "string", + label: "URL", + description: "The website URL to be converted to a specified format.", }, - format: { - propDefinition: [ - convertapi, - "format", - ], + formatTo: { + type: "string", + label: "Format To", + description: "The format you want to convert the URL to.", + options: FORMAT_TO_OPTIONS, + }, + fileName: { + type: "string", + label: "File Name", + description: "Converted output file name without extension. The extension will be added automatically.", + optional: true, + }, + timeout: { + type: "string", + label: "Timeout", + description: "Conversion timeout in seconds.", + optional: true, + }, + conversionDelay: { + type: "integer", + label: "Conversion Delay", + description: "Delay in seconds before page load and file creation. Sometimes useful to let web page fully load.", + optional: true, + }, + authUsername: { + type: "string", + label: "Auth Username", + description: "HTTP authentication username. Could be used if conversion web page is protected with HTTP authentication.", + optional: true, + }, + authPassword: { + type: "string", + label: "Auth Password", + description: "HTTP authentication password. Could be used if conversion web page is protected with HTTP authentication.", + optional: true, + }, + adBlock: { + type: "boolean", + label: "Ad Block", + description: "Block ads in converting page.", + optional: true, + }, + cookieConsentBlock: { + type: "boolean", + label: "Cookie Consent Block", + description: "Tries to remove EU regulation required cookie warnings from web pages.", + optional: true, + }, + cookies: { + type: "string", + label: "Cookies", + description: "Set additional cookies for the page request. Exaple: cookiename1=cookievalue1; cookiename2=cookievalue2; cookiename3=cookievalue3", + optional: true, + }, + javaScript: { + type: "boolean", + label: "JavaScript", + description: "Allow web pages to run JavaScript.", + optional: true, + }, + waitElement: { + type: "string", + label: "Wait Element", + description: "Element selector string of the DOM element. Converter will wait for this element to appear in DOM before conversion begins.", + optional: true, }, userJs: { - propDefinition: [ - convertapi, - "userJs", - ], + type: "string", + label: "User JS", + description: "Execute provided JavaScript before conversion begins.", + optional: true, }, userCss: { - propDefinition: [ - convertapi, - "userCss", - ], + type: "string", + label: "User CSS", + description: "Apply additional CSS before conversion begins.", + optional: true, }, hideElements: { - propDefinition: [ - convertapi, - "hideElements", - ], + type: "string", + label: "Hide Elements", + description: "Element selector string of the DOM elements that need to be hidden during conversion.", + optional: true, }, cssMediaType: { - propDefinition: [ - convertapi, - "cssMediaType", - ], + type: "string", + label: "CSS Media Type", + description: "Use CSS media type in conversion process.", + options: CSS_MEDIA_TYTPE_OPTIONS, + optional: true, + default: "screen", + }, + imageWidth: { + type: "integer", + label: "Image Width", + description: "Image width in pixels.", + hidden: true, + optional: true, + }, + imageHeight: { + type: "integer", + label: "Image Height", + description: "Image height in pixels.", + hidden: true, + optional: true, + }, + imageQuality: { + type: "integer", + label: "Image Quality", + description: "Set output image quality.", + default: 75, + hidden: true, + optional: true, + }, + cropElement: { + type: "string", + label: "Crop Element", + description: "Element selector string of the DOM element that should be converted. Element will be cropped from the document.", + hidden: true, + optional: true, + }, + cropX: { + type: "integer", + label: "Crop X", + description: "Screenshot crop X offset.", + hidden: true, + optional: true, + }, + cropY: { + type: "integer", + label: "Crop Y", + description: "Screenshot crop Y offset.", + hidden: true, + optional: true, + }, + cropWidth: { + type: "integer", + label: "Crop Width", + description: "Screenshot crop width.", + hidden: true, + optional: true, + }, + cropHeight: { + type: "integer", + label: "Crop Height", + description: "Screenshot crop height.", + hidden: true, + optional: true, }, - headers: { - propDefinition: [ - convertapi, - "headers", - ], + zoom: { + type: "integer", + label: "Zoom", + description: "Set the default zoom level of webpages.", + hidden: true, + optional: true, }, loadLazyContent: { - propDefinition: [ - convertapi, - "loadLazyContent", - ], + type: "boolean", + label: "Load Lazy Content", + description: "Load page images that loads only when they are visible.", + hidden: true, + optional: true, }, viewportWidth: { - propDefinition: [ - convertapi, - "viewportWidth", - ], + type: "integer", + label: "Viewport Width", + description: "Sets browser viewport width.", + hidden: true, + default: 1366, + optional: true, }, viewportHeight: { - propDefinition: [ - convertapi, - "viewportHeight", - ], + type: "integer", + label: "Viewport Height", + description: "Sets browser viewport height.", + hidden: true, + default: 1024, + optional: true, }, respectViewport: { - propDefinition: [ - convertapi, - "respectViewport", - ], + type: "boolean", + label: "Respect Viewport", + description: "If true, the converter will generate PDF as the content looks like in the browser. If is set to false, the converter acts like Chrome print to PDF function.", + hidden: true, + optional: true, }, scale: { - propDefinition: [ - convertapi, - "scale", - ], + type: "integer", + label: "Scale", + description: "Set web page scale value in percentage.", + hidden: true, + default: 100, + optional: true, }, pageOrientation: { - propDefinition: [ - convertapi, - "pageOrientation", - ], + type: "string", + label: "Page Orientation", + description: "PDF page orientation", + hidden: true, + options: PAGE_ORIENTATION_OPTIONS, + optional: true, }, pageSize: { - propDefinition: [ - convertapi, - "pageSize", - ], + type: "string", + label: "Page Size", + description: "PDF Page Size", + hidden: true, + options: PAGE_SIZE_OPTIONS, + optional: true, + }, + pageWidth: { + type: "integer", + label: "Page Width", + description: "Custom page width in millimeters (mm). This option override PageSize option.", + hidden: true, + optional: true, + }, + pageHeight: { + type: "integer", + label: "Page Height", + description: "Custom page height in millimeters (mm). This option override PageSize option.", + hidden: true, + optional: true, }, marginTop: { - propDefinition: [ - convertapi, - "marginTop", - ], + type: "integer", + label: "Margin Top", + description: "Set the page top margin in millimeters (mm).", + hidden: true, + optional: true, }, marginRight: { - propDefinition: [ - convertapi, - "marginRight", - ], + type: "integer", + label: "Margin Right", + description: "Set the page right margin in millimeters (mm).", + hidden: true, + optional: true, }, marginBottom: { - propDefinition: [ - convertapi, - "marginBottom", - ], + type: "integer", + label: "Margin Bottom", + description: "Set the page bottom margin in millimeters (mm).", + hidden: true, + optional: true, }, marginLeft: { - propDefinition: [ - convertapi, - "marginLeft", - ], + type: "integer", + label: "Margin Left", + description: "Set the page left margin in millimeters (mm).", + hidden: true, + optional: true, }, pageRange: { - propDefinition: [ - convertapi, - "pageRange", - ], + type: "string", + label: "Page Range", + description: "Set page range. Example 1-10 or 1,2,5.", + hidden: true, + optional: true, + }, + background: { + type: "boolean", + label: "Background", + description: "Convert web page background.", + hidden: true, + optional: true, + }, + fixedElements: { + type: "string", + label: "Fixed Elements", + description: "Change fixed elements CSS 'position' property to adapt page for conversion", + options: FIXED_ELEMENTS_OPTIONS, + hidden: true, + optional: true, + }, + showElements: { + type: "string", + label: "ShowElements", + description: "Element selector string of the DOM elements that should be visible during conversion. Other elements will be hidden.", + hidden: true, + optional: true, + }, + avoidBreakElements: { + type: "string", + label: "Avoid Break Elements", + description: "CSS selector for the elements that pages should not break.", + hidden: true, + optional: true, + }, + breakBeforeElements: { + type: "string", + label: "Break Before Elements", + description: "CSS selector for the elements that should apply page break before it.", + hidden: true, + optional: true, + }, + breakAfterElements: { + type: "string", + label: "Break After Elements", + description: "CSS selector for the elements that should apply page break after it.", + hidden: true, + optional: true, + }, + compressPDF: { + type: "boolean", + label: "Compress PDF", + description: "It tries to produce smaller output files but requires Adobe Reader 6, released in 2003 or newer, to view created PDF files.", + hidden: true, + optional: true, }, }, + async additionalProps(props) { + const isJpg = this.formatTo === "jpg"; + + props.imageWidth.hidden = !isJpg; + props.imageHeight.hidden = !isJpg; + props.type.hidden = !isJpg; + props.cropElement.hidden = !isJpg; + props.cropX.hidden = !isJpg; + props.cropY.hidden = !isJpg; + props.cropWidth.hidden = !isJpg; + props.cropHeight.hidden = !isJpg; + props.zoom.hidden = !isJpg; + + props.loadLazyContent.hidden = isJpg; + props.viewportWidth.hidden = isJpg; + props.viewportHeight.hidden = isJpg; + props.respectViewport.hidden = isJpg; + props.scale.hidden = isJpg; + props.pageOrientation.hidden = isJpg; + props.pageSize.hidden = isJpg; + props.pageWidth.hidden = isJpg; + props.pageHeight.hidden = isJpg; + props.marginTop.hidden = isJpg; + props.marginRight.hidden = isJpg; + props.marginBottom.hidden = isJpg; + props.marginLeft.hidden = isJpg; + props.pageRange.hidden = isJpg; + props.background.hidden = isJpg; + props.fixedElements.hidden = isJpg; + props.showElements.hidden = isJpg; + props.avoidBreakElements.hidden = isJpg; + props.breakBeforeElements.hidden = isJpg; + props.breakAfterElements.hidden = isJpg; + props.compressPDF.hidden = isJpg; + + return {}; + }, async run({ $ }) { - const response = await this.convertapi.convertUrlToFormat({ - url: this.url, - format: this.format, - userJs: this.userJs, - userCss: this.userCss, - hideElements: this.hideElements, - cssMediaType: this.cssMediaType, - headers: this.headers, - loadLazyContent: this.loadLazyContent, - viewportWidth: this.viewportWidth, - viewportHeight: this.viewportHeight, - respectViewport: this.respectViewport, - scale: this.scale, - pageOrientation: this.pageOrientation, - pageSize: this.pageSize, - marginTop: this.marginTop, - marginRight: this.marginRight, - marginBottom: this.marginBottom, - marginLeft: this.marginLeft, - pageRange: this.pageRange, + const data = new FormData(); + + data.append("Url", this.url); + if (this.fileName) data.append("FileName", this.fileName); + if (this.timeout) data.append("Timeout", this.timeout); + if (this.conversionDelay) data.append("ConversionDelay", this.conversionDelay); + if (this.authUsername) data.append("AuthUsername", this.authUsername); + if (this.authPassword) data.append("AuthPassword", this.authPassword); + if (this.adBlock) data.append("AdBlock", this.adBlock); + if (this.cookieConsentBlock) data.append("CookieConsentBlock", this.cookieConsentBlock); + if (this.cookies) data.append("Cookies", this.cookies); + if (this.javaScript) data.append("JavaScript", this.javaScript); + if (this.waitElement) data.append("WaitElement", this.waitElement); + if (this.userJs) data.append("UserJs", this.userJs); + if (this.userCss) data.append("UserCss", this.userCss); + if (this.hideElements) data.append("HideElements", this.hideElements); + if (this.cssMediaType) data.append("CssMediaType", this.cssMediaType); + + if (this.formatTo === "jpg") { + if (this.imageWidth) data.append("ImageWidth", this.imageWidth); + if (this.imageHeight) data.append("ImageHeight", this.imageHeight); + if (this.type) data.append("Type", this.type); + if (this.cropElement) data.append("CropElement", this.cropElement); + if (this.cropX) data.append("CropX", this.cropX); + if (this.cropY) data.append("CropY", this.cropY); + if (this.cropWidth) data.append("CropWidth", this.cropWidth); + if (this.cropHeight) data.append("CropHeight", this.cropHeight); + if (this.zoom) data.append("Zoom", this.zoom); + } else { + if (this.loadLazyContent) data.append("LoadLazyContent", this.loadLazyContent); + if (this.viewportWidth) data.append("ViewportWidth", this.viewportWidth); + if (this.viewportHeight) data.append("ViewportHeight", this.viewportHeight); + if (this.respectViewport) data.append("RespectViewport", this.respectViewport); + if (this.scale) data.append("Scale", this.scale); + if (this.pageOrientation) data.append("PageOrientation", this.pageOrientation); + if (this.pageSize) data.append("PageSize", this.pageSize); + if (this.pageWidth) data.append("PageWidth", this.pageWidth); + if (this.pageHeight) data.append("PageHeight", this.pageHeight); + if (this.marginTop) data.append("MarginTop", this.marginTop); + if (this.marginRight) data.append("MarginRight", this.marginRight); + if (this.marginBottom) data.append("MarginBottom", this.marginBottom); + if (this.marginLeft) data.append("MarginLeft", this.marginLeft); + if (this.pageRange) data.append("PageRange", this.pageRange); + if (this.background) data.append("Background", this.background); + if (this.fixedElements) data.append("FixedElements", this.fixedElements); + if (this.showElements) data.append("ShowElements", this.showElements); + if (this.avoidBreakElements) data.append("AvoidBreakElements", this.avoidBreakElements); + if (this.breakBeforeElements) data.append("BreakBeforeElements", this.breakBeforeElements); + if (this.breakAfterElements) data.append("BreakAfterElements", this.breakAfterElements); + if (this.compressPDF) data.append("CompressPDF", this.compressPDF); + } + + const { Files } = await this.convertapi.convertWebToFormat({ + $, + formatTo: this.formatTo, + data, + headers: data.getHeaders(), }); - $.export("$summary", `Successfully converted URL to ${this.format || "default format"}`); - return response; + await saveFile(Files); + + $.export("$summary", `Successfully converted URL to ${this.formatTo} and saved in /tmp directory as **${Files[0].FileName}**.`); + return; }, }; diff --git a/components/convertapi/app/convertapi.app.ts b/components/convertapi/app/convertapi.app.ts deleted file mode 100644 index 93cd7f684140b..0000000000000 --- a/components/convertapi/app/convertapi.app.ts +++ /dev/null @@ -1,13 +0,0 @@ -import { defineApp } from "@pipedream/types"; - -export default defineApp({ - type: "app", - app: "convertapi", - propDefinitions: {}, - methods: { - // this.$auth contains connected account data - authKeys() { - console.log(Object.keys(this.$auth)); - }, - }, -}); diff --git a/components/convertapi/common/constants.mjs b/components/convertapi/common/constants.mjs new file mode 100644 index 0000000000000..8b723233acc97 --- /dev/null +++ b/components/convertapi/common/constants.mjs @@ -0,0 +1,186 @@ +export const FORMAT_OPTIONS = [ + "ai", + "any", + "bmp", + "csv", + "djvu", + "doc", + "docx", + "dot", + "dotx", + "dwf", + "dwfx", + "dwg", + "dwgx", + "dxf", + "email", + "eml", + "eps", + "epub", + "gif", + "heic", + "htm", + "html", + "ico", + "images", + "jpeg", + "jpg", + "key", + "log", + "md", + "mdi", + "mhtml", + "mobi", + "msg", + "numbers", + "odc", + "odf", + "odp", + "ods", + "odt", + "office", + "oxps", + "pages", + "pdf", + "png", + "potx", + "pps", + "ppsx", + "ppt", + "pptx", + "prn", + "ps", + "psd", + "pub", + "rtf", + "svg", + "template", + "tif", + "tiff", + "txt", + "vsd", + "vsdx", + "web", + "webp", + "wpd", + "xls", + "xlsx", + "xlt", + "xltx", + "xml", + "xps", + "zip", +]; + +export const CSS_MEDIA_TYTPE_OPTIONS = [ + "print", + "screen", +]; + +export const PAGE_ORIENTATION_OPTIONS = [ + "portrait", + "landscape", +]; + +export const PAGE_SIZE_OPTIONS = [ + { + label: "A0 (841 x 1189 mm, 8.26 x 11.69 inches)", + value: "a0", + }, + { + label: "A1 (594 x 841 mm, 23.4 x 33.1 inches)", + value: "a1", + }, + { + label: "A2 (420 x 594 mm, 16.5 x 23.4 inches)", + value: "a2", + }, + { + label: "A3 (298 x 420 mm, 11.7 x 16.5 inches)", + value: "a3", + }, + { + label: "A4 (210 x 298 mm, 8.3 x 11.7 inches)", + value: "a4", + }, + { + label: "A5 (148 x 210 mm, 5.8 x 8.3 inches)", + value: "a5", + }, + { + label: "A6 (105 x 148 mm, 4.1 x 5.8 inches)", + value: "a6", + }, + { + label: "A7 (74 x 105 mm, 2.9 x 4.1 inches)", + value: "a7", + }, + { + label: "A8 (52 x 74 mm, 2.0 x 2.9 inches)", + value: "a8", + }, + { + label: "A9 (37 x 52 mm, 1.5 x 2.0 inches)", + value: "a9", + }, + { + label: "B0 (1000 x 1414 mm, 39.4 x 55.7 inches)", + value: "b0", + }, + { + label: "B1 (707 x 1000 mm, 27.8 x 39.4 inches)", + value: "b1", + }, + { + label: "B2 (500 x 707 mm, 19.7 x 27.8 inches)", + value: "b2", + }, + { + label: "B3 (353 x 500 mm, 13.9 x 19.7 inches)", + value: "b3", + }, + { + label: "B4 (250 x 353 mm, 9.8 x 13.9 inches)", + value: "b4", + }, + { + label: "B5 (176 x 250 mm, 6.9 x 9.8 inches)", + value: "b5", + }, + { + label: "Letter (216 x 279 mm, 8.5 x 11 inches)", + value: "letter", + }, + { + label: "Legal (216 x 356 mm, 8.5 x 14 inches)", + value: "legal", + }, + { + label: "Ledger (432 x 279 mm, 17 x 11 inches)", + value: "ledger", + }, +]; + +export const FIXED_ELEMENTS_OPTIONS = [ + { + label: "Leave unchanged", + value: "fixed", + }, + { + label: "Absolute", + value: "absolute", + }, + { + label: "Relative", + value: "relative", + }, + { + label: "Hide", + value: "hide", + }, +]; + +export const FORMAT_TO_OPTIONS = [ + "jpg", + "pdf", +]; diff --git a/components/convertapi/common/utils.mjs b/components/convertapi/common/utils.mjs new file mode 100644 index 0000000000000..9e74d32afe875 --- /dev/null +++ b/components/convertapi/common/utils.mjs @@ -0,0 +1,14 @@ +import fs from "fs"; + +export const checkTmp = (filename) => { + if (!filename.startsWith("/tmp")) { + return `/tmp/${filename}`; + } + return filename; +}; + +export const saveFile = async (Files) => { + const FileInfo = Files[0]; + const tmpFilePath = `/tmp/${FileInfo.FileName}`; + return fs.writeFileSync(tmpFilePath, FileInfo.FileData, "base64"); +}; diff --git a/components/convertapi/convertapi.app.mjs b/components/convertapi/convertapi.app.mjs index c2d8cc19100ca..06c55dea24d75 100644 --- a/components/convertapi/convertapi.app.mjs +++ b/components/convertapi/convertapi.app.mjs @@ -1,4 +1,5 @@ import { axios } from "@pipedream/platform"; +import { FORMAT_OPTIONS } from "./common/constants.mjs"; export default { type: "app", @@ -9,241 +10,54 @@ export default { label: "Base64 String", description: "The base64 string of the file to convert", }, - format: { + formatFrom: { type: "string", - label: "Output Format", - description: "The desired output format for the converted file.", - optional: true, - }, - file: { - type: "string", - label: "File", - description: "The file to be converted. Provide a URL or file content.", - }, - url: { - type: "string", - label: "URL", - description: "The website URL to be converted to a specified format.", - }, - userJs: { - type: "string", - label: "User JavaScript", - description: "Execute provided JavaScript before conversion begins.", - optional: true, - }, - userCss: { - type: "string", - label: "User CSS", - description: "Apply additional CSS before conversion begins.", - optional: true, - }, - hideElements: { - type: "string", - label: "Hide Elements", - description: "Element selector string of the DOM elements that need to be hidden during conversion.", - optional: true, - }, - cssMediaType: { - type: "string", - label: "CSS Media Type", - description: "Use CSS media type in conversion process.", - optional: true, - default: "screen", - }, - headers: { - type: "string", - label: "Headers", - description: "Headers to include in the conversion request.", - optional: true, - }, - loadLazyContent: { - type: "boolean", - label: "Load Lazy Content", - description: "Load page images that load only when they are visible.", - optional: true, - default: false, - }, - viewportWidth: { - type: "integer", - label: "Viewport Width", - description: "Sets browser viewport width.", - optional: true, - min: 200, - max: 4000, - default: 1366, - }, - viewportHeight: { - type: "integer", - label: "Viewport Height", - description: "Sets browser viewport height.", - optional: true, - min: 200, - max: 4000, - default: 1024, - }, - respectViewport: { - type: "boolean", - label: "Respect Viewport", - description: "If true, the converter will generate PDF as the content looks like in the browser.", - optional: true, - default: true, - }, - scale: { - type: "integer", - label: "Scale", - description: "Set web page scale value in percentage.", - optional: true, - min: 10, - max: 200, - default: 100, - }, - pageOrientation: { - type: "string", - label: "Page Orientation", - description: "PDF page orientation.", - optional: true, - default: "portrait", - enum: [ - "portrait", - "landscape", - ], - }, - pageSize: { - type: "string", - label: "Page Size", - description: "PDF page size.", - optional: true, - default: "letter", - enum: [ - "a0", - "a1", - "a2", - "a3", - "a4", - "a5", - "a6", - "a7", - "a8", - "a9", - "b0", - "b1", - "b2", - "b3", - "b4", - "b5", - "letter", - "legal", - "ledger", - ], - }, - marginTop: { - type: "integer", - label: "Margin Top", - description: "Set the page top margin in mm.", - optional: true, - min: 0, - max: 500, - default: 10, - }, - marginRight: { - type: "integer", - label: "Margin Right", - description: "Set the page right margin in mm.", - optional: true, - min: 0, - max: 500, - default: 10, - }, - marginBottom: { - type: "integer", - label: "Margin Bottom", - description: "Set the page bottom margin in mm.", - optional: true, - min: 0, - max: 500, - default: 10, - }, - marginLeft: { - type: "integer", - label: "Margin Left", - description: "Set the page left margin in mm.", - optional: true, - min: 0, - max: 500, - default: 10, - }, - pageRange: { - type: "string", - label: "Page Range", - description: "Set page range. Example 1-10 or 1,2,5.", - optional: true, - default: "1-100", + label: "Input Format", + description: "The format of the input file.", + options: FORMAT_OPTIONS, }, }, methods: { _baseUrl() { return "https://v2.convertapi.com"; }, - async _makeRequest(opts = {}) { - const { - $ = this, - method = "POST", - path = "/", - headers, - ...otherOpts - } = opts; + _params(params = {}) { + return { + Secret: `${this.$auth.api_secret}`, + ...params, + }; + }, + _makeRequest({ + $ = this, params, path, ...opts + }) { return axios($, { - ...otherOpts, - method, url: this._baseUrl() + path, - headers: { - ...headers, - Authorization: `Bearer ${this.$auth.api_key}`, - }, + params: this._params(params), + ...opts, }); }, - async convertBase64ToFormat(opts = {}) { - const { - base64String, format, ...rest - } = opts; + getAllowedFormats({ formatFrom }) { return this._makeRequest({ - path: format - ? `/convert/base64/to/${format}` - : "/convert/base64/to", - data: { - base64_string: base64String, - ...rest, - }, + path: `/info/openapi/${formatFrom}/to/*`, }); }, - async convertFileToFormat(opts = {}) { - const { - file, format, ...rest - } = opts; + convertFileToFormat({ + formatFrom, formatTo, ...opts + }) { return this._makeRequest({ - path: format - ? `/convert/file/to/${format}` - : "/convert/file/to", - data: { - file, - ...rest, - }, + method: "POST", + path: `/convert/${formatFrom}/to/${formatTo}`, + ...opts, }); }, - async convertUrlToFormat(opts = {}) { - const { - url, format, ...rest - } = opts; + convertWebToFormat({ + formatTo, ...opts + }) { return this._makeRequest({ - path: format - ? `/convert/url/to/${format}` - : "/convert/url/to", - data: { - url, - ...rest, - }, + method: "POST", + path: `/convert/web/to/${formatTo}`, + ...opts, }); }, }, - version: "0.0.{{ts}}", }; diff --git a/components/convertapi/package.json b/components/convertapi/package.json index c9abb3b6802ea..336a1040856e5 100644 --- a/components/convertapi/package.json +++ b/components/convertapi/package.json @@ -1,16 +1,20 @@ { "name": "@pipedream/convertapi", - "version": "0.0.2", + "version": "0.1.0", "description": "Pipedream ConvertAPI Components", - "main": "dist/app/convertapi.app.mjs", + "main": "convertapi.app.mjs", "keywords": [ "pipedream", "convertapi" ], - "files": ["dist"], "homepage": "https://pipedream.com/apps/convertapi", "author": "Pipedream (https://pipedream.com/)", "publishConfig": { "access": "public" + }, + "dependencies": { + "@pipedream/platform": "^3.0.3", + "form-data": "^4.0.2", + "fs": "^0.0.1-security" } } From d8be3d92c5d824393e6370e9d5c5c4030b77e386 Mon Sep 17 00:00:00 2001 From: Luan Cazarine Date: Mon, 28 Apr 2025 16:19:37 -0300 Subject: [PATCH 3/5] pnpm update --- pnpm-lock.yaml | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 7917c4e2f33a9..117f28e17e33e 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -2930,7 +2930,17 @@ importers: components/conversion_tools: {} - components/convertapi: {} + components/convertapi: + dependencies: + '@pipedream/platform': + specifier: ^3.0.3 + version: 3.0.3 + form-data: + specifier: ^4.0.2 + version: 4.0.2 + fs: + specifier: ^0.0.1-security + version: 0.0.1-security components/convertkit: dependencies: @@ -33522,7 +33532,7 @@ snapshots: axios: 1.8.4(debug@3.2.7) body-parser: 1.20.3 file-type: 16.5.4 - form-data: 4.0.1 + form-data: 4.0.2 transitivePeerDependencies: - debug - supports-color @@ -34140,7 +34150,7 @@ snapshots: dependencies: '@pipedream/platform': 1.6.6 axios: 1.8.4(debug@3.2.7) - form-data: 4.0.1 + form-data: 4.0.2 transitivePeerDependencies: - debug @@ -36631,7 +36641,7 @@ snapshots: '@types/node-fetch@2.6.12': dependencies: '@types/node': 20.17.6 - form-data: 4.0.1 + form-data: 4.0.2 '@types/node@14.18.63': {} @@ -37404,7 +37414,7 @@ snapshots: axios@0.27.2: dependencies: follow-redirects: 1.15.9(debug@3.2.7) - form-data: 4.0.1 + form-data: 4.0.2 transitivePeerDependencies: - debug @@ -38143,7 +38153,7 @@ snapshots: '@aws-sdk/credential-providers': 3.696.0(@aws-sdk/client-sso-oidc@3.696.0(@aws-sdk/client-sts@3.696.0(aws-crt@1.25.0))(aws-crt@1.25.0))(aws-crt@1.25.0) '@aws-sdk/protocol-http': 3.374.0 '@aws-sdk/signature-v4': 3.374.0 - form-data: 4.0.1 + form-data: 4.0.2 form-data-encoder: 4.0.2 formdata-node: 6.0.3 js-base64: 3.7.2 @@ -42649,7 +42659,7 @@ snapshots: dependencies: axios: 1.8.4(debug@3.2.7) exponential-backoff: 3.1.1 - form-data: 4.0.1 + form-data: 4.0.2 transitivePeerDependencies: - debug From 74f4664cf7f1c782ab4518bafd5a1a05145fdf51 Mon Sep 17 00:00:00 2001 From: Luan Cazarine Date: Tue, 29 Apr 2025 11:54:04 -0300 Subject: [PATCH 4/5] some adjusts --- .../convert-base64-encoded-file.mjs | 7 +- .../actions/convert-file/convert-file.mjs | 7 +- .../convert-web-url/convert-web-url.mjs | 124 ++++++++++-------- 3 files changed, 76 insertions(+), 62 deletions(-) diff --git a/components/convertapi/actions/convert-base64-encoded-file/convert-base64-encoded-file.mjs b/components/convertapi/actions/convert-base64-encoded-file/convert-base64-encoded-file.mjs index f38b76a1631a3..2c4feced9385e 100644 --- a/components/convertapi/actions/convert-base64-encoded-file/convert-base64-encoded-file.mjs +++ b/components/convertapi/actions/convert-base64-encoded-file/convert-base64-encoded-file.mjs @@ -69,8 +69,11 @@ export default { }); await saveFile(Files); + const filename = Files[0].FileName; - $.export("$summary", `Successfully converted base64 encoded file to ${this.formatTo} and saved in /tmp directory as **${Files[0].FileName}**.`); - return; + $.export("$summary", `Successfully converted base64 encoded file to ${this.formatTo} and saved in /tmp directory as **${filename}**.`); + return { + filepath: `/tmp/${filename}`, + }; }, }; diff --git a/components/convertapi/actions/convert-file/convert-file.mjs b/components/convertapi/actions/convert-file/convert-file.mjs index a93a315de3645..c04afdf7250a1 100644 --- a/components/convertapi/actions/convert-file/convert-file.mjs +++ b/components/convertapi/actions/convert-file/convert-file.mjs @@ -67,9 +67,12 @@ export default { }); await saveFile(Files); + const filename = Files[0].FileName; - $.export("$summary", `Successfully converted file to ${this.formatTo} format and saved in /tmp directory as **${Files[0].FileName}**.`); - return; + $.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}`); } diff --git a/components/convertapi/actions/convert-web-url/convert-web-url.mjs b/components/convertapi/actions/convert-web-url/convert-web-url.mjs index 2390bdd43b57c..e3a3c50e53cb0 100644 --- a/components/convertapi/actions/convert-web-url/convert-web-url.mjs +++ b/components/convertapi/actions/convert-web-url/convert-web-url.mjs @@ -370,68 +370,76 @@ export default { return {}; }, async run({ $ }) { - const data = new FormData(); + try { + const data = new FormData(); - data.append("Url", this.url); - if (this.fileName) data.append("FileName", this.fileName); - if (this.timeout) data.append("Timeout", this.timeout); - if (this.conversionDelay) data.append("ConversionDelay", this.conversionDelay); - if (this.authUsername) data.append("AuthUsername", this.authUsername); - if (this.authPassword) data.append("AuthPassword", this.authPassword); - if (this.adBlock) data.append("AdBlock", this.adBlock); - if (this.cookieConsentBlock) data.append("CookieConsentBlock", this.cookieConsentBlock); - if (this.cookies) data.append("Cookies", this.cookies); - if (this.javaScript) data.append("JavaScript", this.javaScript); - if (this.waitElement) data.append("WaitElement", this.waitElement); - if (this.userJs) data.append("UserJs", this.userJs); - if (this.userCss) data.append("UserCss", this.userCss); - if (this.hideElements) data.append("HideElements", this.hideElements); - if (this.cssMediaType) data.append("CssMediaType", this.cssMediaType); + data.append("Url", this.url); + if (this.fileName) data.append("FileName", this.fileName); + if (this.timeout) data.append("Timeout", this.timeout); + if (this.conversionDelay) data.append("ConversionDelay", this.conversionDelay); + if (this.authUsername) data.append("AuthUsername", this.authUsername); + if (this.authPassword) data.append("AuthPassword", this.authPassword); + if (this.adBlock) data.append("AdBlock", `${this.adBlock}`); + if (this.cookieConsentBlock) data.append("CookieConsentBlock", `${this.cookieConsentBlock}`); + if (this.cookies) data.append("Cookies", this.cookies); + if (this.javaScript) data.append("JavaScript", `${this.javaScript}`); + if (this.waitElement) data.append("WaitElement", this.waitElement); + if (this.userJs) data.append("UserJs", this.userJs); + if (this.userCss) data.append("UserCss", this.userCss); + if (this.hideElements) data.append("HideElements", this.hideElements); + if (this.cssMediaType) data.append("CssMediaType", this.cssMediaType); - if (this.formatTo === "jpg") { - if (this.imageWidth) data.append("ImageWidth", this.imageWidth); - if (this.imageHeight) data.append("ImageHeight", this.imageHeight); - if (this.type) data.append("Type", this.type); - if (this.cropElement) data.append("CropElement", this.cropElement); - if (this.cropX) data.append("CropX", this.cropX); - if (this.cropY) data.append("CropY", this.cropY); - if (this.cropWidth) data.append("CropWidth", this.cropWidth); - if (this.cropHeight) data.append("CropHeight", this.cropHeight); - if (this.zoom) data.append("Zoom", this.zoom); - } else { - if (this.loadLazyContent) data.append("LoadLazyContent", this.loadLazyContent); - if (this.viewportWidth) data.append("ViewportWidth", this.viewportWidth); - if (this.viewportHeight) data.append("ViewportHeight", this.viewportHeight); - if (this.respectViewport) data.append("RespectViewport", this.respectViewport); - if (this.scale) data.append("Scale", this.scale); - if (this.pageOrientation) data.append("PageOrientation", this.pageOrientation); - if (this.pageSize) data.append("PageSize", this.pageSize); - if (this.pageWidth) data.append("PageWidth", this.pageWidth); - if (this.pageHeight) data.append("PageHeight", this.pageHeight); - if (this.marginTop) data.append("MarginTop", this.marginTop); - if (this.marginRight) data.append("MarginRight", this.marginRight); - if (this.marginBottom) data.append("MarginBottom", this.marginBottom); - if (this.marginLeft) data.append("MarginLeft", this.marginLeft); - if (this.pageRange) data.append("PageRange", this.pageRange); - if (this.background) data.append("Background", this.background); - if (this.fixedElements) data.append("FixedElements", this.fixedElements); - if (this.showElements) data.append("ShowElements", this.showElements); - if (this.avoidBreakElements) data.append("AvoidBreakElements", this.avoidBreakElements); - if (this.breakBeforeElements) data.append("BreakBeforeElements", this.breakBeforeElements); - if (this.breakAfterElements) data.append("BreakAfterElements", this.breakAfterElements); - if (this.compressPDF) data.append("CompressPDF", this.compressPDF); - } + if (this.formatTo === "jpg") { + if (this.imageWidth) data.append("ImageWidth", this.imageWidth); + if (this.imageHeight) data.append("ImageHeight", this.imageHeight); + if (this.type) data.append("Type", this.type); + if (this.cropElement) data.append("CropElement", this.cropElement); + if (this.cropX) data.append("CropX", this.cropX); + if (this.cropY) data.append("CropY", this.cropY); + if (this.cropWidth) data.append("CropWidth", this.cropWidth); + if (this.cropHeight) data.append("CropHeight", this.cropHeight); + if (this.zoom) data.append("Zoom", this.zoom); + } else { + if (this.loadLazyContent) data.append("LoadLazyContent", `${this.loadLazyContent}`); + if (this.viewportWidth) data.append("ViewportWidth", this.viewportWidth); + if (this.viewportHeight) data.append("ViewportHeight", this.viewportHeight); + if (this.respectViewport) data.append("RespectViewport", `${this.respectViewport}`); + if (this.scale) data.append("Scale", this.scale); + if (this.pageOrientation) data.append("PageOrientation", this.pageOrientation); + if (this.pageSize) data.append("PageSize", this.pageSize); + if (this.pageWidth) data.append("PageWidth", this.pageWidth); + if (this.pageHeight) data.append("PageHeight", this.pageHeight); + if (this.marginTop) data.append("MarginTop", this.marginTop); + if (this.marginRight) data.append("MarginRight", this.marginRight); + if (this.marginBottom) data.append("MarginBottom", this.marginBottom); + if (this.marginLeft) data.append("MarginLeft", this.marginLeft); + if (this.pageRange) data.append("PageRange", this.pageRange); + if (this.background) data.append("Background", `${this.background}`); + if (this.fixedElements) data.append("FixedElements", this.fixedElements); + if (this.showElements) data.append("ShowElements", this.showElements); + if (this.avoidBreakElements) data.append("AvoidBreakElements", this.avoidBreakElements); + if (this.breakBeforeElements) data.append("BreakBeforeElements", this.breakBeforeElements); + if (this.breakAfterElements) data.append("BreakAfterElements", this.breakAfterElements); + if (this.compressPDF) data.append("CompressPDF", `${this.compressPDF}`); + } - const { Files } = await this.convertapi.convertWebToFormat({ - $, - formatTo: this.formatTo, - data, - headers: data.getHeaders(), - }); + const { Files } = await this.convertapi.convertWebToFormat({ + $, + formatTo: this.formatTo, + data, + headers: data.getHeaders(), + timeout: 2000 * this.timeout, + }); - await saveFile(Files); + await saveFile(Files); + const filename = Files[0].FileName; - $.export("$summary", `Successfully converted URL to ${this.formatTo} and saved in /tmp directory as **${Files[0].FileName}**.`); - return; + $.export("$summary", `Successfully converted URL to ${this.formatTo} and saved in /tmp directory as **${filename}**.`); + return { + filepath: `/tmp/${filename}`, + }; + } catch (e) { + throw new Error(e); + } }, }; From f62e4a5ca6964fe53287516c2aeb5d1af9cdf365 Mon Sep 17 00:00:00 2001 From: Luan Cazarine Date: Wed, 30 Apr 2025 12:22:57 -0300 Subject: [PATCH 5/5] Update components/convertapi/actions/convert-web-url/convert-web-url.mjs Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> --- .../convertapi/actions/convert-web-url/convert-web-url.mjs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/convertapi/actions/convert-web-url/convert-web-url.mjs b/components/convertapi/actions/convert-web-url/convert-web-url.mjs index e3a3c50e53cb0..9e2a69a995d23 100644 --- a/components/convertapi/actions/convert-web-url/convert-web-url.mjs +++ b/components/convertapi/actions/convert-web-url/convert-web-url.mjs @@ -428,7 +428,7 @@ export default { formatTo: this.formatTo, data, headers: data.getHeaders(), - timeout: 2000 * this.timeout, + timeout: this.timeout ? 2000 * Number(this.timeout) : undefined, }); await saveFile(Files);