-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New Components - transloadit #16579
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 - transloadit #16579
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
bde6e0d
transloadit init
luancazarine 9c211ba
[Components] transloadit #16556
luancazarine da937be
pnpm update
luancazarine 6296ed0
some adjusts
luancazarine 77086a9
Update components/transloadit/transloadit.app.mjs
luancazarine 6530978
Update components/transloadit/transloadit.app.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
24 changes: 24 additions & 0 deletions
24
components/transloadit/actions/cancel-assembly/cancel-assembly.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,24 @@ | ||
| import transloadit from "../../transloadit.app.mjs"; | ||
|
|
||
| export default { | ||
| key: "transloadit-cancel-assembly", | ||
| name: "Cancel Assembly", | ||
| description: "Cancel a running assembly by its assembly ID. Useful for aborting processing jobs that are no longer needed. [See the documentation](https://transloadit.com/docs/api/assemblies-assembly-id-delete/)", | ||
| version: "0.0.1", | ||
| type: "action", | ||
| props: { | ||
| transloadit, | ||
| assemblyId: { | ||
| propDefinition: [ | ||
| transloadit, | ||
| "assemblyId", | ||
| ], | ||
| }, | ||
| }, | ||
| async run({ $ }) { | ||
| const response = await this.transloadit.cancelAssembly(this.assemblyId); | ||
|
|
||
| $.export("$summary", `Successfully canceled assembly with ID ${this.assemblyId}`); | ||
| return response; | ||
| }, | ||
| }; |
84 changes: 84 additions & 0 deletions
84
components/transloadit/actions/create-assembly/create-assembly.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,84 @@ | ||
| import { ConfigurationError } from "@pipedream/platform"; | ||
| import { parseObject } from "../../common/utils.mjs"; | ||
| import transloadit from "../../transloadit.app.mjs"; | ||
|
|
||
| export default { | ||
| key: "transloadit-create-assembly", | ||
| name: "Create Assembly", | ||
| description: "Create a new assembly to process files using a specified template and steps. [See the documentation](https://transloadit.com/docs/api/assemblies-post/)", | ||
| version: "0.0.1", | ||
| type: "action", | ||
| props: { | ||
| transloadit, | ||
| info: { | ||
|
Check warning on line 13 in components/transloadit/actions/create-assembly/create-assembly.mjs
|
||
| type: "alert", | ||
| alertType: "info", | ||
| content: "Note: By default, the `steps` parameter allows you to override Template Steps at runtime. However, if `Allow Steps Override` is set to `false`, then steps and `Template Id` become mutually exclusive. In this case, you can only supply one of these parameters. See [Overruling Templates at Runtime](https://transloadit.com/docs/topics/templates/#overruling-templates-at-runtime).", | ||
| }, | ||
| allowStepsOverride: { | ||
| type: "boolean", | ||
| label: "Allow Steps Override", | ||
| description: "Set this to `false` to disallow [Overruling Templates at Runtime](https://transloadit.com/docs/topics/templates/#overruling-templates-at-runtime). If you set this to `false` then `Template Id` and `Steps` will be mutually exclusive and you may only supply one of those parameters. Recommended when deploying Transloadit in untrusted environments. This makes sense to set as part of a Template, rather than on the Assembly itself when creating it.", | ||
| default: true, | ||
| }, | ||
| templateId: { | ||
| propDefinition: [ | ||
| transloadit, | ||
| "templateId", | ||
| ], | ||
| optional: true, | ||
| }, | ||
| steps: { | ||
| type: "object", | ||
| label: "Steps", | ||
| description: "Assembly Instructions comprise all the Steps executed on uploaded/imported files by the Transloadit back-end during file conversion or encoding. [See the documentation](https://transloadit.com/docs/topics/assembly-instructions/) for more information.", | ||
| optional: true, | ||
| }, | ||
| notifyUrl: { | ||
| type: "string", | ||
| label: "Notify URL", | ||
| description: "Transloadit can send a Pingback to your server when the Assembly is completed. We'll send the Assembly status in a form url-encoded JSON string inside of a `transloadit` field in a multipart POST request to the URL supplied here.", | ||
| optional: true, | ||
| }, | ||
| quiet: { | ||
| type: "boolean", | ||
| label: "Quiet", | ||
| description: "Set this to `true` to reduce the response from an Assembly POST request to only the necessary fields. This prevents any potentially confidential information being leaked to the end user who is making the Assembly request. A successful Assembly will only include the `ok` and `assembly_id` fields. An erroneous Assembly will only include the `error`, `http_code`, `message` and `assembly_id` fields. The full Assembly Status will then still be sent to the `Notify URL` if one was specified.", | ||
| optional: true, | ||
| }, | ||
| }, | ||
| async run({ $ }) { | ||
| if (!this.allowStepsOverride && this.templateId && this.steps) { | ||
| throw new ConfigurationError("Either 'templateId' or 'steps' must be provided, not both."); | ||
| } | ||
| if (!this.templateId && !this.steps) { | ||
| throw new ConfigurationError("Either 'templateId' or 'steps' must be provided."); | ||
| } | ||
|
|
||
| try { | ||
| const response = await this.transloadit.createAssembly({ | ||
| params: { | ||
| template_id: this.templateId, | ||
| steps: parseObject(this.steps), | ||
| notify_url: this.notifyUrl, | ||
| allow_steps_override: this.allowStepsOverride, | ||
| quiet: this.quiet, | ||
| }, | ||
| }); | ||
|
|
||
| if (response.results.resize) { | ||
| $.export("$summary", `Assembly created successfully with ID ${response.assembly_id}`); | ||
| } else { | ||
| $.export("$summary", "The Assembly didn't produce any output. Make sure you used a valid image file"); | ||
| } | ||
|
|
||
| return response; | ||
| } catch (err) { | ||
| let message = `Unable to process Assembly. ${err}`; | ||
| if (err.assemblyId) { | ||
| message += `More info: https://transloadit.com/assemblies/${err.assemblyId}`; | ||
| } | ||
| throw new ConfigurationError(message); | ||
| } | ||
| }, | ||
| }; | ||
23 changes: 23 additions & 0 deletions
23
components/transloadit/actions/get-assembly-status/get-assembly-status.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,23 @@ | ||
| import transloadit from "../../transloadit.app.mjs"; | ||
|
|
||
| export default { | ||
| key: "transloadit-get-assembly-status", | ||
| name: "Get Assembly Status", | ||
| description: "Retrieve the current status and results of an existing assembly. [See the documentation](https://transloadit.com/docs/api/assemblies-assembly-id-get/)", | ||
| version: "0.0.1", | ||
| type: "action", | ||
| props: { | ||
| transloadit, | ||
| assemblyId: { | ||
| propDefinition: [ | ||
| transloadit, | ||
| "assemblyId", | ||
| ], | ||
| }, | ||
| }, | ||
| async run({ $ }) { | ||
| const response = await this.transloadit.getAssemblyStatus(this.assemblyId); | ||
| $.export("$summary", `Successfully retrieved assembly status for ${this.assemblyId}`); | ||
| 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| export const LIMIT = 5000; |
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,24 @@ | ||
| export const parseObject = (obj) => { | ||
| if (!obj) return undefined; | ||
|
|
||
| if (Array.isArray(obj)) { | ||
| return obj.map((item) => { | ||
| if (typeof item === "string") { | ||
| try { | ||
| return JSON.parse(item); | ||
| } catch (e) { | ||
| return item; | ||
| } | ||
| } | ||
| return item; | ||
| }); | ||
| } | ||
| if (typeof obj === "string") { | ||
| try { | ||
| return JSON.parse(obj); | ||
| } catch (e) { | ||
| return obj; | ||
| } | ||
| } | ||
| return obj; | ||
| }; | ||
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/transloadit", | ||
| "version": "0.0.1", | ||
| "version": "0.1.0", | ||
| "description": "Pipedream Transloadit Components", | ||
| "main": "transloadit.app.mjs", | ||
| "keywords": [ | ||
|
|
@@ -11,5 +11,9 @@ | |
| "author": "Pipedream <[email protected]> (https://pipedream.com/)", | ||
| "publishConfig": { | ||
| "access": "public" | ||
| }, | ||
| "dependencies": { | ||
| "@pipedream/platform": "^3.0.3", | ||
| "transloadit": "^3.0.2" | ||
| } | ||
| } | ||
| } | ||
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,61 @@ | ||
| import { DEFAULT_POLLING_SOURCE_TIMER_INTERVAL } from "@pipedream/platform"; | ||
| import transloadit from "../../transloadit.app.mjs"; | ||
|
|
||
| export default { | ||
| props: { | ||
| transloadit, | ||
| db: "$.service.db", | ||
| timer: { | ||
| type: "$.interface.timer", | ||
| default: { | ||
| intervalSeconds: DEFAULT_POLLING_SOURCE_TIMER_INTERVAL, | ||
| }, | ||
| }, | ||
| }, | ||
| methods: { | ||
| _getLastDate() { | ||
| return this.db.get("lastDate") || "1970-01-01 00:00:00"; | ||
| }, | ||
| _setLastDate(lastDate) { | ||
| this.db.set("lastDate", lastDate); | ||
| }, | ||
| async emitEvent(maxResults = false) { | ||
| const lastDate = this._getLastDate(); | ||
|
|
||
| const response = this.transloadit.paginate({ | ||
| fn: this.transloadit.listAssemblies, | ||
| params: { | ||
| fromdate: lastDate, | ||
| type: this.getType(), | ||
| }, | ||
| maxResults, | ||
| }); | ||
|
|
||
| let responseArray = []; | ||
| for await (const item of response) { | ||
| if (Date.parse(item.created) <= Date.parse(lastDate)) break; | ||
| responseArray.push(item); | ||
| } | ||
|
|
||
| if (responseArray.length) { | ||
| this._setLastDate(responseArray[0].created); | ||
| } | ||
|
|
||
| for (const item of responseArray.reverse()) { | ||
| this.$emit(item, { | ||
| id: item.id, | ||
| summary: this.getSummary(item), | ||
| ts: item.created_ts, | ||
| }); | ||
| } | ||
| }, | ||
michelle0927 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| }, | ||
| hooks: { | ||
| async deploy() { | ||
| await this.emitEvent(25); | ||
| }, | ||
| }, | ||
| async run() { | ||
| await this.emitEvent(); | ||
| }, | ||
| }; | ||
22 changes: 22 additions & 0 deletions
22
components/transloadit/sources/new-assembly-completed/new-assembly-completed.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,22 @@ | ||
| import common from "../common/base.mjs"; | ||
| import sampleEmit from "./test-event.mjs"; | ||
|
|
||
| export default { | ||
| ...common, | ||
| key: "transloadit-new-assembly-completed", | ||
| name: "New Assembly Completed", | ||
| description: "Emit new event when a Transloadit assembly finishes processing. [See the documentation](https://transloadit.com/docs/api/assemblies-get/)", | ||
| version: "0.0.1", | ||
| type: "source", | ||
| dedupe: "unique", | ||
| methods: { | ||
| ...common.methods, | ||
| getType() { | ||
| return "completed"; | ||
| }, | ||
| getSummary(item) { | ||
| return `New assembly completed with ID: ${item.id}`; | ||
| }, | ||
| }, | ||
| sampleEmit, | ||
| }; |
19 changes: 19 additions & 0 deletions
19
components/transloadit/sources/new-assembly-completed/test-event.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,19 @@ | ||
| export default { | ||
| "id": "195c60855fda4fb9a3b2f848374ca4e1", | ||
| "parent_id": null, | ||
| "account_id": "7c91e50845204dea9ed4791f7d8440f1", | ||
| "template_id": "40b0efc6b37f432dbe9485017b52a7b7", | ||
| "instance": "tam.transloadit.com", | ||
| "notify_url": null, | ||
| "redirect_url": null, | ||
| "files": "[\"Saturn as seen from the Cas....jpg\"]", | ||
| "region": "eu-west-1", | ||
| "warning_count": 0, | ||
| "execution_duration": 2.337, | ||
| "execution_start": "2023-02-11T16:04:24.000Z", | ||
| "ok": "ASSEMBLY_COMPLETED", | ||
| "error": null, | ||
| "created": "2023-02-11T16:04:22.000Z", | ||
| "created_ts": 1676131462, | ||
| "template_name": "my-template-1676131432311" | ||
| } |
22 changes: 22 additions & 0 deletions
22
components/transloadit/sources/new-assembly-error/new-assembly-error.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,22 @@ | ||
| import common from "../common/base.mjs"; | ||
| import sampleEmit from "./test-event.mjs"; | ||
|
|
||
| export default { | ||
| ...common, | ||
| key: "transloadit-new-assembly-error", | ||
| name: "New Assembly Failed", | ||
| description: "Emit new event when a failed occurs during assembly processing. [See the documentation](https://transloadit.com/docs/api/assemblies-get/)", | ||
| version: "0.0.1", | ||
| type: "source", | ||
| dedupe: "unique", | ||
| methods: { | ||
| ...common.methods, | ||
| getType() { | ||
| return "failed"; | ||
| }, | ||
| getSummary(item) { | ||
| return `New assembly failed with ID: ${item.id}`; | ||
| }, | ||
| }, | ||
| sampleEmit, | ||
| }; |
21 changes: 21 additions & 0 deletions
21
components/transloadit/sources/new-assembly-error/test-event.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,21 @@ | ||
| export default { | ||
| "id": "195c60855fda4fb9a3b2f848374ca4e1", | ||
| "parent_id": null, | ||
| "account_id": "7c91e50845204dea9ed4791f7d8440f1", | ||
| "template_id": "40b0efc6b37f432dbe9485017b52a7b7", | ||
| "instance": "tam.transloadit.com", | ||
| "notify_url": null, | ||
| "redirect_url": null, | ||
| "files": "[]", | ||
| "region": "eu-west-1", | ||
| "warning_count": 0, | ||
| "num_input_files": 0, | ||
| "bytes_usage": 0, | ||
| "execution_duration": 2.337, | ||
| "execution_start": "2023-02-11T16:04:24.000Z", | ||
| "ok": null, | ||
| "error": "ASSEMBLY_NO_STEPS", | ||
| "created": "2023-02-11T16:04:22.000Z", | ||
| "created_ts": 1676131462, | ||
| "template_name": "" | ||
| } |
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.