Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
84 changes: 84 additions & 0 deletions components/cloud_convert/actions/create-job/create-job.mjs
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;
},
};
44 changes: 44 additions & 0 deletions components/cloud_convert/common/utils.mjs
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;
}
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;
}
seen.add(value);
return Object.entries(value)
.reduce((acc, [
key,
val,
]) => Object.assign(acc, {
[key]: parse(val),
}), {});
} else if (Array.isArray(value)) {
return value.map((item) => parse(item));
}
return value;
};

return parse(input);
};

export default {
parseJson,
};
8 changes: 4 additions & 4 deletions components/cloud_convert/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@pipedream/cloud_convert",
"version": "0.1.1",
"version": "0.2.0",
"description": "Pipedream Cloud Convert Components",
"main": "cloud_convert.app.mjs",
"keywords": [
Expand All @@ -9,10 +9,10 @@
],
"homepage": "https://pipedream.com/apps/cloud_convert",
"author": "Pipedream <support@pipedream.com> (https://pipedream.com/)",
"dependencies": {
"@pipedream/platform": "^1.6.8"
},
"publishConfig": {
"access": "public"
},
"dependencies": {
"@pipedream/platform": "^3.1.1"
}
}
Loading
Loading