Skip to content

New Components - rendi #16713

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
wants to merge 4 commits into
base: master
Choose a base branch
from
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import rendi from "../../rendi.app.mjs";

export default {
key: "rendi-get-ffmpeg-command-status",
name: "Get FFmpeg Command Status",
description: "Get the status of a previously submitted FFmpeg command. [See the documentation](https://docs.rendi.dev/api-reference/endpoint/poll-command)",
version: "0.0.1",
type: "action",
props: {
rendi,
commandId: {
type: "string",
label: "Command ID",
description: "ID of the FFmpeg command to check",
},
},
async run({ $ }) {
const response = await this.rendi.getFfmpegCommand({
$,
commandId: this.commandId,
});
$.export("$summary", `Successfully retrieved status of FFmpeg command with ID: ${this.commandId}`);
return response;
},
};
21 changes: 21 additions & 0 deletions components/rendi/actions/list-stored-files/list-stored-files.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import rendi from "../../rendi.app.mjs";

export default {
key: "rendi-list-stored-files",
name: "List Stored Files",
description: "Get the list of all stored files for an account. [See the documentation](https://docs.rendi.dev/api-reference/endpoint/list-files)",
version: "0.0.1",
type: "action",
props: {
rendi,
},
async run({ $ }) {
const response = await this.rendi.listFiles({
$,
});
$.export("$summary", `Successfully retrieved ${response.length} file${response.length === 1
? ""
: "s"}`);
return response;
},
};
116 changes: 116 additions & 0 deletions components/rendi/actions/run-ffmpeg-command/run-ffmpeg-command.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
import rendi from "../../rendi.app.mjs";
import { ConfigurationError } from "@pipedream/platform";
import { parseObject } from "../../common/utils.mjs";
import { axios } from "@pipedream/platform";
import fs from "fs";

export default {
key: "rendi-run-ffmpeg-command",
name: "Run FFmpeg Command",
description: "Submit an FFmpeg command for processing with input and output file specifications. [See the documentation](https://docs.rendi.dev/api-reference/endpoint/run-ffmpeg-command)",
version: "0.0.1",
type: "action",
props: {
rendi,
inputFiles: {
type: "object",
label: "Input File URL(s)",
description: "Dictionary mapping file aliases to their publicly accessible paths, file name should appear in the end of the url, keys must start with 'in_'. You can use public file urls, google drive, dropbox, rendi stored files, s3 stored files, etc. as long as they are publicly accessible. [See the documentation](https://docs.rendi.dev/api-reference/endpoint/run-ffmpeg-command) for more information",
},
outputFiles: {
type: "object",
label: "Output File Name(s)",
description: "Dictionary mapping file aliases to their desired output file names, keys must start with 'out_'. [See the documentation](https://docs.rendi.dev/api-reference/endpoint/run-ffmpeg-command) for more information",
},
command: {
type: "string",
label: "FFmpeg Command",
description: "FFmpeg command string using {{alias}} placeholders for input and output files. `{{}}` is a reserved string, instead you can use `\\{\\{\\}\\}` , so for example `{{in_1}}` should be `\\{\\{in_1\\}\\}`. Example: `-i \\{\\{in_1\\}\\} \\{\\{out_1\\}\\}`",
},
maxCommandRunSeconds: {
type: "string",
label: "Max Command Run Seconds",
description: "Maximum allowed runtime in seconds for a single FFmpeg command, the default is 300 seconds",
optional: true,
},
waitForCompletion: {
type: "boolean",
label: "Wait for Completion",
description: "Set to `true` to poll the API in 3-second intervals until the command is completed",
optional: true,
reloadProps: true,
},
},
additionalProps() {
if (this.waitForCompletion) {
return {
downloadFilesToTmp: {
type: "boolean",
label: "Download Files to /tmp",
description: "Set to `true` to download the output files to the workflow's /tmp directory",
optional: true,
},
};
}
return {};
},
async run({ $ }) {
const inputFiles = parseObject(this.inputFiles);
const outputFiles = parseObject(this.outputFiles);

if (Object.keys(inputFiles).some((key) => !key.startsWith("in_"))) {
throw new ConfigurationError("Input file keys must start with 'in_'");
}
if (Object.keys(outputFiles).some((key) => !key.startsWith("out_"))) {
throw new ConfigurationError("Output file keys must start with 'out_'");
}

let response = await this.rendi.runFfmpegCommand({
$,
data: {
input_files: inputFiles,
output_files: outputFiles,
ffmpeg_command: this.command,
max_command_run_seconds: this.maxCommandRunSeconds,
},
});

if (this.waitForCompletion) {
const commandId = response.command_id;
const timer = (ms) => new Promise((res) => setTimeout(res, ms));
while (response?.status !== "SUCCESS" && response?.status !== "FAILED") {
response = await this.rendi.getFfmpegCommand({
$,
commandId,
});
await timer(3000);
}
if (response?.status === "SUCCESS" && this.downloadFilesToTmp) {
response.tmpFiles = [];
for (const value of Object.values(response.output_files)) {
const resp = await axios($, {
url: value.storage_url,
responseType: "arraybuffer",
});
const filename = value.storage_url.split("/").pop();
const downloadedFilepath = `/tmp/${filename}`;
fs.writeFileSync(downloadedFilepath, resp);

response.tmpFiles.push({
filename,
downloadedFilepath,
});
}
}

if (response?.error_message) {
throw new ConfigurationError(response.error_message);
}
}

$.export("$summary", `FFmpeg command ${this.waitForCompletion
? "submitted and completed"
: "submitted"} successfully`);
return response;
},
};
9 changes: 9 additions & 0 deletions components/rendi/common/utils.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export function parseObject(obj) {
if (!obj) return undefined;

if (typeof obj === "string") {
return JSON.parse(obj);
}

return obj;
}
7 changes: 5 additions & 2 deletions components/rendi/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@pipedream/rendi",
"version": "0.0.1",
"version": "0.1.0",
"description": "Pipedream Rendi Components",
"main": "rendi.app.mjs",
"keywords": [
Expand All @@ -11,5 +11,8 @@
"author": "Pipedream <[email protected]> (https://pipedream.com/)",
"publishConfig": {
"access": "public"
},
"dependencies": {
"@pipedream/platform": "^3.0.3"
}
}
}
47 changes: 44 additions & 3 deletions components/rendi/rendi.app.mjs
Original file line number Diff line number Diff line change
@@ -1,11 +1,52 @@
import { axios } from "@pipedream/platform";

export default {
type: "app",
app: "rendi",
propDefinitions: {},
methods: {
// this.$auth contains connected account data
authKeys() {
console.log(Object.keys(this.$auth));
_baseUrl() {
return "https://api.rendi.dev/v1";
},
_makeRequest({
$ = this,
path,
...otherOpts
}) {
return axios($, {
url: `${this._baseUrl()}${path}`,
headers: {
"x-api-key": `${this.$auth.api_key}`,
},
...otherOpts,
});
},
listFiles(opts = {}) {
return this._makeRequest({
path: "/files",
...opts,
});
},
listCommands(opts = {}) {
return this._makeRequest({
path: "/commands",
...opts,
});
},
getFfmpegCommand({
commandId, ...opts
}) {
return this._makeRequest({
path: `/commands/${commandId}`,
...opts,
});
},
runFfmpegCommand(opts = {}) {
return this._makeRequest({
method: "POST",
path: "/run-ffmpeg-command",
...opts,
});
},
},
};
73 changes: 73 additions & 0 deletions components/rendi/sources/new-ffmpeg-command/new-ffmpeg-command.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
import rendi from "../../rendi.app.mjs";
import { DEFAULT_POLLING_SOURCE_TIMER_INTERVAL } from "@pipedream/platform";
import sampleEmit from "./test-event.mjs";

export default {
key: "rendi-new-ffmpeg-command",
name: "New FFmpeg Command",
description: "Emit new event when a new FFmpeg command is submitted. [See the documentation](https://docs.rendi.dev/api-reference/endpoint/list-commands)",
version: "0.0.1",
type: "source",
dedupe: "unique",
props: {
rendi,
db: "$.service.db",
timer: {
label: "Polling interval",
description: "Pipedream will poll the Trello API on this schedule",
type: "$.interface.timer",
default: {
intervalSeconds: DEFAULT_POLLING_SOURCE_TIMER_INTERVAL,
},
},
},
methods: {
_getLastTs() {
return this.db.get("lastTs") || 0;
},
_setLastTs(ts) {
this.db.set("lastTs", ts);
},
generateMeta(command) {
return {
id: command.command_id,
summary: `New FFmpeg command: ${command.command_id}`,
ts: Date.parse(command.created_at),
};
},
async processEvent(max) {
const lastTs = this._getLastTs();
let maxTs = lastTs;

let commands = [];
const results = await this.rendi.listCommands();
for (const command of results) {
const ts = Date.parse(command.created_at);
if (ts > lastTs) {
commands.push(command);
maxTs = Math.max(maxTs, ts);
}
}

if (max && commands.length > max) {
commands = commands.slice(-1 * max);
}

commands.forEach((command) => {
const meta = this.generateMeta(command);
this.$emit(command, meta);
});

this._setLastTs(maxTs);
},
},
hooks: {
async deploy() {
await this.processEvent(25);
},
},
async run() {
await this.processEvent();
},
sampleEmit,
};
5 changes: 5 additions & 0 deletions components/rendi/sources/new-ffmpeg-command/test-event.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export default {
"command_id": "5eda862d-b5d5-41f5-ac92-e6872b054",
"status": "SUCCESS",
"created_at": "2025-05-19T18:15:20.349538Z"
}
38 changes: 38 additions & 0 deletions components/rendi/sources/new-stored-file/new-stored-file.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import rendi from "../../rendi.app.mjs";
import { DEFAULT_POLLING_SOURCE_TIMER_INTERVAL } from "@pipedream/platform";
import sampleEmit from "./test-event.mjs";

export default {
key: "rendi-new-stored-file",
name: "New Stored File",
description: "Emit new event when a new file is uploaded to an account. [See the documentation](https://docs.rendi.dev/api-reference/endpoint/list-files)",
version: "0.0.1",
type: "source",
dedupe: "unique",
props: {
rendi,
timer: {
type: "$.interface.timer",
default: {
intervalSeconds: DEFAULT_POLLING_SOURCE_TIMER_INTERVAL,
},
},
},
methods: {
generateMeta(file) {
return {
id: file.file_id,
summary: `New Stored File with ID: ${file.file_id}`,
ts: Date.now(),
};
},
},
async run() {
const files = await this.rendi.listFiles();
for (const file of files) {
const meta = this.generateMeta(file);
this.$emit(file, meta);
}
},
sampleEmit,
};
5 changes: 5 additions & 0 deletions components/rendi/sources/new-stored-file/test-event.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export default {
"file_id": "8e30e8fb-a037-48e0-aca2-eaa6df7ec",
"size_mbytes": 34.04952430725098,
"storage_url": "https://storage.rendi.dev/trial_files/86f043b9-dc30-465b-995c-371382ee1c74/5eda862d-b5d5-41f5-ac92-e6872b054/output_one.avi"
}
6 changes: 5 additions & 1 deletion pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading