Skip to content

Commit c9b7dfe

Browse files
authored
[ACTION] CloudConvert - Create Job (#19513)
1 parent 3087ec1 commit c9b7dfe

File tree

4 files changed

+211
-245
lines changed

4 files changed

+211
-245
lines changed
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
import app from "../../cloud_convert.app.mjs";
2+
import utils from "../../common/utils.mjs";
3+
4+
export default {
5+
key: "cloud_convert-create-job",
6+
name: "Create Job",
7+
description: "Creates a new job for one or more tasks. [See the documentation](https://cloudconvert.com/api/v2/jobs#jobs-create)",
8+
version: "0.0.1",
9+
type: "action",
10+
annotations: {
11+
readOnlyHint: false,
12+
destructiveHint: false,
13+
openWorldHint: true,
14+
},
15+
props: {
16+
app,
17+
tasks: {
18+
type: "object",
19+
label: "Tasks",
20+
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**.
21+
22+
**Each task object must include:**
23+
24+
- \`operation\` (string, **required**): The endpoint for creating the task (e.g., \`convert\`, \`import/url\`, \`import/s3\`, \`export/s3\`, etc.)
25+
- \`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.
26+
- \`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.
27+
- 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.
28+
29+
**Example:**
30+
\`\`\`json
31+
{
32+
"import-my-file": {
33+
"operation": "import/url",
34+
"url": "https://example.com/document.pdf"
35+
},
36+
"convert-my-file": {
37+
"operation": "convert",
38+
"input": "import-my-file",
39+
"output_format": "jpg",
40+
"pages": "1-3"
41+
},
42+
"export-my-file": {
43+
"operation": "export/url",
44+
"input": ["convert-my-file"]
45+
}
46+
}
47+
\`\`\`
48+
49+
[See the tasks documentation](https://cloudconvert.com/api/v2/tasks)`,
50+
},
51+
tag: {
52+
type: "string",
53+
label: "Tag",
54+
description: "An arbitrary string to identify the job. Does not have any effect and can be used to associate with your application",
55+
optional: true,
56+
},
57+
webhookUrl: {
58+
type: "string",
59+
label: "Webhook URL",
60+
description: "Single-job webhook URL receiving `job.finished` or `job.failed` events",
61+
optional: true,
62+
},
63+
},
64+
async run({ $ }) {
65+
const {
66+
app,
67+
tasks,
68+
tag,
69+
webhookUrl,
70+
} = this;
71+
72+
const response = await app.createJob({
73+
$,
74+
data: {
75+
tasks: utils.parseJson(tasks),
76+
tag,
77+
webhook_url: webhookUrl,
78+
},
79+
});
80+
81+
$.export("$summary", `Successfully created job with ID \`${response.data.id}\``);
82+
return response;
83+
},
84+
};
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
const parseJson = (input, maxDepth = 100) => {
2+
const seen = new WeakSet();
3+
const parse = (value) => {
4+
if (maxDepth <= 0) {
5+
return value;
6+
}
7+
if (typeof(value) === "string") {
8+
// Only parse if the string looks like a JSON object or array
9+
const trimmed = value.trim();
10+
if (
11+
(trimmed.startsWith("{") && trimmed.endsWith("}")) ||
12+
(trimmed.startsWith("[") && trimmed.endsWith("]"))
13+
) {
14+
try {
15+
return parseJson(JSON.parse(value), maxDepth - 1);
16+
} catch (e) {
17+
return value;
18+
}
19+
}
20+
return value;
21+
} else if (typeof(value) === "object" && value !== null && !Array.isArray(value)) {
22+
if (seen.has(value)) {
23+
return value;
24+
}
25+
seen.add(value);
26+
return Object.entries(value)
27+
.reduce((acc, [
28+
key,
29+
val,
30+
]) => Object.assign(acc, {
31+
[key]: parse(val),
32+
}), {});
33+
} else if (Array.isArray(value)) {
34+
return value.map((item) => parse(item));
35+
}
36+
return value;
37+
};
38+
39+
return parse(input);
40+
};
41+
42+
export default {
43+
parseJson,
44+
};
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pipedream/cloud_convert",
3-
"version": "0.1.1",
3+
"version": "0.2.0",
44
"description": "Pipedream Cloud Convert Components",
55
"main": "cloud_convert.app.mjs",
66
"keywords": [
@@ -9,10 +9,10 @@
99
],
1010
"homepage": "https://pipedream.com/apps/cloud_convert",
1111
"author": "Pipedream <support@pipedream.com> (https://pipedream.com/)",
12-
"dependencies": {
13-
"@pipedream/platform": "^1.6.8"
14-
},
1512
"publishConfig": {
1613
"access": "public"
14+
},
15+
"dependencies": {
16+
"@pipedream/platform": "^3.1.1"
1717
}
1818
}

0 commit comments

Comments
 (0)