Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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
24 changes: 24 additions & 0 deletions components/transloadit/actions/cancel-assembly/cancel-assembly.mjs
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 components/transloadit/actions/create-assembly/create-assembly.mjs
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

View workflow job for this annotation

GitHub Actions / Lint Code Base

Component prop info must have a label. See https://pipedream.com/docs/components/guidelines/#props

Check warning on line 13 in components/transloadit/actions/create-assembly/create-assembly.mjs

View workflow job for this annotation

GitHub Actions / Lint Code Base

Component prop info must have a description. See https://pipedream.com/docs/components/guidelines/#props
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);
}
},
};
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;
},
};
1 change: 1 addition & 0 deletions components/transloadit/common/constants.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const LIMIT = 5000;
24 changes: 24 additions & 0 deletions components/transloadit/common/utils.mjs
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;
};
8 changes: 6 additions & 2 deletions components/transloadit/package.json
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": [
Expand All @@ -11,5 +11,9 @@
"author": "Pipedream <[email protected]> (https://pipedream.com/)",
"publishConfig": {
"access": "public"
},
"dependencies": {
"@pipedream/platform": "^3.0.3",
"transloadit": "^3.0.2"
}
}
}
61 changes: 61 additions & 0 deletions components/transloadit/sources/common/base.mjs
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,
});
}
},
},
hooks: {
async deploy() {
await this.emitEvent(25);
},
},
async run() {
await this.emitEvent();
},
};
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,
};
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"
}
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 components/transloadit/sources/new-assembly-error/test-event.mjs
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": ""
}
Loading
Loading