-
Notifications
You must be signed in to change notification settings - Fork 5.6k
[ACTION] CloudConvert - Create Job #19513
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
Open
jcortes
wants to merge
1
commit into
master
Choose a base branch
from
cloudconvert-create-job
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+212
−247
Open
Changes from all commits
Commits
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
84 changes: 84 additions & 0 deletions
84
components/cloud_convert/actions/create-job/create-job.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 app from "../../cloud_convert.app.mjs"; | ||
| import utils from "../../common/utils.mjs"; | ||
|
|
||
| export default { | ||
| key: "cloud_convert-create-job", | ||
| name: "Create Job", | ||
| description: "Creates a new job for one or more tasks. [See the documentation](https://cloudconvert.com/api/v2/jobs#jobs-create)", | ||
| version: "0.0.1", | ||
| type: "action", | ||
| annotations: { | ||
| readOnlyHint: false, | ||
| destructiveHint: false, | ||
| openWorldHint: true, | ||
| }, | ||
| props: { | ||
| app, | ||
| tasks: { | ||
| type: "object", | ||
| label: "Tasks", | ||
| description: `An object containing named tasks that form the job workflow. You can name tasks however you want, but **only alphanumeric characters, hyphens (-), and underscores (_) are allowed**. | ||
|
|
||
| **Each task object must include:** | ||
|
|
||
| - \`operation\` (string, **required**): The endpoint for creating the task (e.g., \`convert\`, \`import/url\`, \`import/s3\`, \`export/s3\`, etc.) | ||
| - \`input\` (string or array, optional): The name(s) of the input task(s). Use this to reference other tasks within the same job. Multiple task names can be provided as an array. | ||
| - \`ignore_error\` (boolean, optional): By default, the job fails if one task fails. Set to \`true\` to continue the job even if this specific task fails. | ||
| - Task-specific options (optional): Additional parameters that depend on the \`operation\` type. These are the same parameters used when creating the task via its direct endpoint. | ||
|
|
||
| **Example:** | ||
| \`\`\`json | ||
| { | ||
| "import-my-file": { | ||
| "operation": "import/url", | ||
| "url": "https://example.com/document.pdf" | ||
| }, | ||
| "convert-my-file": { | ||
| "operation": "convert", | ||
| "input": "import-my-file", | ||
| "output_format": "jpg", | ||
| "pages": "1-3" | ||
| }, | ||
| "export-my-file": { | ||
| "operation": "export/url", | ||
| "input": ["convert-my-file"] | ||
| } | ||
| } | ||
| \`\`\` | ||
|
|
||
| [See the tasks documentation](https://cloudconvert.com/api/v2/tasks)`, | ||
| }, | ||
| tag: { | ||
| type: "string", | ||
| label: "Tag", | ||
| description: "An arbitrary string to identify the job. Does not have any effect and can be used to associate with your application", | ||
| optional: true, | ||
| }, | ||
| webhookUrl: { | ||
| type: "string", | ||
| label: "Webhook URL", | ||
| description: "Single-job webhook URL receiving `job.finished` or `job.failed` events", | ||
| optional: true, | ||
| }, | ||
| }, | ||
| async run({ $ }) { | ||
| const { | ||
| app, | ||
| tasks, | ||
| tag, | ||
| webhookUrl, | ||
| } = this; | ||
|
|
||
| const response = await app.createJob({ | ||
| $, | ||
| data: { | ||
| tasks: utils.parseJson(tasks), | ||
| tag, | ||
| webhook_url: webhookUrl, | ||
| }, | ||
| }); | ||
|
|
||
| $.export("$summary", `Successfully created job with ID \`${response.data.id}\``); | ||
| return response; | ||
| }, | ||
| }; | ||
jcortes marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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,44 @@ | ||
| const parseJson = (input, maxDepth = 100) => { | ||
| const seen = new WeakSet(); | ||
| const parse = (value) => { | ||
| if (maxDepth <= 0) { | ||
| return value; | ||
| } | ||
jcortes marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| if (typeof(value) === "string") { | ||
| // Only parse if the string looks like a JSON object or array | ||
| const trimmed = value.trim(); | ||
| if ( | ||
| (trimmed.startsWith("{") && trimmed.endsWith("}")) || | ||
| (trimmed.startsWith("[") && trimmed.endsWith("]")) | ||
| ) { | ||
| try { | ||
| return parseJson(JSON.parse(value), maxDepth - 1); | ||
| } catch (e) { | ||
| return value; | ||
| } | ||
| } | ||
| return value; | ||
| } else if (typeof(value) === "object" && value !== null && !Array.isArray(value)) { | ||
| if (seen.has(value)) { | ||
| return value; | ||
| } | ||
jcortes marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| seen.add(value); | ||
| return Object.entries(value) | ||
| .reduce((acc, [ | ||
| key, | ||
| val, | ||
| ]) => Object.assign(acc, { | ||
| [key]: parse(val), | ||
| }), {}); | ||
jcortes marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } else if (Array.isArray(value)) { | ||
| return value.map((item) => parse(item)); | ||
jcortes marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
| return value; | ||
| }; | ||
|
|
||
| return parse(input); | ||
| }; | ||
|
|
||
| export default { | ||
| parseJson, | ||
| }; | ||
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
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.