Skip to content

Commit bde6e0d

Browse files
committed
transloadit init
1 parent b9f6a17 commit bde6e0d

File tree

8 files changed

+484
-3
lines changed

8 files changed

+484
-3
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import transloadit from "../../transloadit.app.mjs";
2+
3+
export default {
4+
key: "transloadit-cancel-assembly",
5+
name: "Cancel Assembly",
6+
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/)",
7+
version: "0.0.{{ts}}",
8+
type: "action",
9+
props: {
10+
transloadit,
11+
assemblyId: {
12+
propDefinition: [
13+
transloadit,
14+
"assemblyId",
15+
],
16+
},
17+
},
18+
async run({ $ }) {
19+
const response = await this.transloadit.cancelAssembly({
20+
assemblyId: this.assemblyId,
21+
});
22+
23+
$.export("$summary", `Successfully canceled assembly with ID ${response.assembly_id}`);
24+
return response;
25+
},
26+
};
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
import transloadit from "../../transloadit.app.mjs";
2+
import { axios } from "@pipedream/platform";
3+
4+
export default {
5+
key: "transloadit-create-assembly",
6+
name: "Create Assembly",
7+
description: "Create a new assembly to process files using a specified template and steps. [See the documentation](https://transloadit.com/docs/api/assemblies-post/)",
8+
version: "0.0.{{ts}}",
9+
type: "action",
10+
props: {
11+
transloadit,
12+
templateId: {
13+
propDefinition: [
14+
transloadit,
15+
"templateId",
16+
],
17+
optional: true,
18+
},
19+
steps: {
20+
propDefinition: [
21+
transloadit,
22+
"steps",
23+
],
24+
optional: true,
25+
},
26+
files: {
27+
propDefinition: [
28+
transloadit,
29+
"files",
30+
],
31+
},
32+
notifyUrl: {
33+
propDefinition: [
34+
transloadit,
35+
"notifyUrl",
36+
],
37+
optional: true,
38+
},
39+
},
40+
async run({ $ }) {
41+
if (!this.templateId && !this.steps) {
42+
throw new Error("Either 'templateId' or 'steps' must be provided.");
43+
}
44+
45+
const response = await this.transloadit.createAssembly({
46+
templateId: this.templateId,
47+
steps: this.steps
48+
? JSON.parse(this.steps)
49+
: undefined,
50+
files: this.files,
51+
notifyUrl: this.notifyUrl,
52+
});
53+
54+
$.export("$summary", `Assembly created successfully with ID ${response.assembly_id}`);
55+
return response;
56+
},
57+
};
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import transloadit from "../../transloadit.app.mjs";
2+
3+
export default {
4+
key: "transloadit-get-assembly-status",
5+
name: "Get Assembly Status",
6+
description: "Retrieve the current status and results of an existing assembly. [See the documentation](https://transloadit.com/docs/api/assemblies-assembly-id-get/)",
7+
version: "0.0.{{ts}}",
8+
type: "action",
9+
props: {
10+
transloadit,
11+
assemblyId: {
12+
propDefinition: [
13+
transloadit,
14+
"assemblyId",
15+
],
16+
},
17+
},
18+
async run({ $ }) {
19+
const response = await this.transloadit.getAssemblyStatus({
20+
assemblyId: this.assemblyId,
21+
});
22+
$.export("$summary", `Successfully retrieved assembly status for ${this.assemblyId}`);
23+
return response;
24+
},
25+
};

components/transloadit/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@
1212
"publishConfig": {
1313
"access": "public"
1414
}
15-
}
15+
}
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
import transloadit from "../../transloadit.app.mjs";
2+
import { axios } from "@pipedream/platform";
3+
4+
export default {
5+
key: "transloadit-new-assembly-completed-instant",
6+
name: "New Assembly Completed (Instant)",
7+
description: "Emit new event when a Transloadit assembly finishes processing. Requires the assembly template or notification URL to be configured in Transloadit to call the webhook. [See the documentation](https://transloadit.com/docs/api)",
8+
version: "0.0.1",
9+
type: "source",
10+
dedupe: "unique",
11+
props: {
12+
transloadit: {
13+
type: "app",
14+
app: "transloadit",
15+
},
16+
http: {
17+
type: "$.interface.http",
18+
customResponse: true,
19+
},
20+
db: "$.service.db",
21+
},
22+
hooks: {
23+
async deploy() {
24+
try {
25+
const assemblies = await this.transloadit._makeRequest({
26+
method: "GET",
27+
path: "/assemblies",
28+
params: {
29+
auth: {
30+
key: this.transloadit.$auth.api_key,
31+
},
32+
sort: "created",
33+
order: "desc",
34+
limit: 50,
35+
},
36+
});
37+
for (const assembly of assemblies) {
38+
this.$emit(assembly, {
39+
id: assembly.id,
40+
summary: `New assembly completed with ID: ${assembly.id}`,
41+
ts: Date.parse(assembly.finished),
42+
});
43+
}
44+
} catch (error) {
45+
console.error("Error fetching assemblies:", error);
46+
}
47+
},
48+
async activate() {
49+
// Webhook setup is expected to be configured within Transloadit; no action necessary
50+
},
51+
async deactivate() {
52+
// Webhook cleanup is expected to be configured within Transloadit; no action necessary
53+
},
54+
},
55+
async run(event) {
56+
const {
57+
httpRequest, body,
58+
} = event;
59+
const computedSignature = this.transloadit.computeSignature(httpRequest.body);
60+
const receivedSignature = httpRequest.headers["transloadit-signature"];
61+
62+
if (computedSignature !== receivedSignature) {
63+
await this.http.respond({
64+
status: 401,
65+
body: "Unauthorized",
66+
});
67+
return;
68+
}
69+
70+
await this.http.respond({
71+
status: 200,
72+
body: "OK",
73+
});
74+
75+
if (body.ok === "ASSEMBLY_COMPLETED") {
76+
this.$emit(body, {
77+
id: body.assembly_id,
78+
summary: `Assembly completed with ID: ${body.assembly_id}`,
79+
ts: Date.now(),
80+
});
81+
}
82+
},
83+
};
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
import transloadit from "../../transloadit.app.mjs";
2+
import { axios } from "@pipedream/platform";
3+
import crypto from "crypto";
4+
5+
export default {
6+
key: "transloadit-new-assembly-error-instant",
7+
name: "New Assembly Error",
8+
description: "Emit new event when an error occurs during assembly processing. Requires webhook support to be enabled through assembly options in Transloadit. [See the documentation](https://transloadit.com/docs/api/)",
9+
version: "0.0.{{ts}}",
10+
type: "source",
11+
dedupe: "unique",
12+
props: {
13+
transloadit: {
14+
type: "app",
15+
app: "transloadit",
16+
},
17+
http: {
18+
type: "$.interface.http",
19+
customResponse: true,
20+
},
21+
db: "$.service.db",
22+
templateId: {
23+
propDefinition: [
24+
transloadit,
25+
"templateId",
26+
],
27+
},
28+
notifyUrl: {
29+
propDefinition: [
30+
transloadit,
31+
"notifyUrl",
32+
],
33+
},
34+
steps: {
35+
propDefinition: [
36+
transloadit,
37+
"steps",
38+
],
39+
},
40+
},
41+
methods: {
42+
_generateSignature(secretKey, rawBody) {
43+
return crypto.createHmac("sha256", secretKey).update(rawBody)
44+
.digest("hex");
45+
},
46+
},
47+
hooks: {
48+
async deploy() {
49+
const assemblies = await this.transloadit._makeRequest({
50+
path: "/assemblies",
51+
params: {
52+
limit: 50,
53+
sort: "desc",
54+
},
55+
});
56+
for (const assembly of assemblies.items) {
57+
if (assembly.error) {
58+
this.$emit(assembly, {
59+
id: assembly.id,
60+
summary: `Assembly Error: ${assembly.id}`,
61+
ts: new Date(assembly.created).getTime(),
62+
});
63+
}
64+
}
65+
},
66+
async activate() {
67+
const response = await this.transloadit.createAssembly({
68+
templateId: this.templateId,
69+
steps: this.steps,
70+
notifyUrl: this.notifyUrl,
71+
});
72+
this.db.set("assemblyId", response.assembly_id);
73+
},
74+
async deactivate() {
75+
const assemblyId = this.db.get("assemblyId");
76+
if (assemblyId) {
77+
await this.transloadit.cancelAssembly({
78+
assemblyId,
79+
});
80+
}
81+
},
82+
},
83+
async run(event) {
84+
const rawBody = event.body_raw;
85+
const providedSignature = event.headers["transloadit-signature"];
86+
const computedSignature = this._generateSignature(this.transloadit.$auth.secret, rawBody);
87+
88+
if (computedSignature !== providedSignature) {
89+
this.http.respond({
90+
status: 401,
91+
body: "Unauthorized",
92+
});
93+
return;
94+
}
95+
96+
if (event.body.ok === "ASSEMBLY_ERROR") {
97+
this.$emit(event.body, {
98+
id: event.body.assembly_id,
99+
summary: `Assembly error: ${event.body.error}`,
100+
ts: new Date(event.body.assembly_creation_date).getTime(),
101+
});
102+
}
103+
104+
this.http.respond({
105+
status: 200,
106+
body: "OK",
107+
});
108+
},
109+
};
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
import transloadit from "../../transloadit.app.mjs";
2+
import { axios } from "@pipedream/platform";
3+
4+
export default {
5+
key: "transloadit-new-upload-instant",
6+
name: "New Upload Instant",
7+
description: "Emit new event when a new file is uploaded to trigger an assembly. [See the documentation](https://transloadit.com/docs/api/)",
8+
version: "0.0.{{ts}}",
9+
type: "source",
10+
dedupe: "unique",
11+
props: {
12+
transloadit,
13+
http: {
14+
type: "$.interface.http",
15+
customResponse: false,
16+
},
17+
db: "$.service.db",
18+
templateId: {
19+
propDefinition: [
20+
transloadit,
21+
"templateId",
22+
],
23+
},
24+
notifyUrl: {
25+
propDefinition: [
26+
transloadit,
27+
"notifyUrl",
28+
],
29+
},
30+
files: {
31+
propDefinition: [
32+
transloadit,
33+
"files",
34+
],
35+
},
36+
steps: {
37+
propDefinition: [
38+
transloadit,
39+
"steps",
40+
],
41+
optional: true,
42+
},
43+
},
44+
hooks: {
45+
async deploy() {
46+
// Logic for emitting historical data, if applicable
47+
},
48+
async activate() {
49+
// Logic to create a webhook subscription, if applicable
50+
},
51+
async deactivate() {
52+
// Logic to remove the webhook subscription, if applicable
53+
},
54+
},
55+
methods: {
56+
async triggerAssembly() {
57+
return await this.transloadit.createAssembly({
58+
templateId: this.templateId,
59+
steps: this.steps,
60+
files: this.files,
61+
notifyUrl: this.notifyUrl,
62+
});
63+
},
64+
},
65+
async run(event) {
66+
const { data: body } = event;
67+
this.$emit(body, {
68+
id: body.assembly_id,
69+
summary: `New upload: ${body.assembly_id}`,
70+
ts: Date.parse(body.uploaded_at) || Date.now(),
71+
});
72+
},
73+
};

0 commit comments

Comments
 (0)