@n8n/n8n-nodes-langchain
Version:

199 lines • 6.38 kB
JavaScript
;
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
// If the importer is in node compatibility mode or this is not an ESM
// file that has been converted to a CommonJS file using a Babel-
// compatible transform (i.e. "__esModule" has not been set), then set
// "default" to the CommonJS "module.exports" for node compatibility.
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var generate_operation_exports = {};
__export(generate_operation_exports, {
description: () => description,
execute: () => execute
});
module.exports = __toCommonJS(generate_operation_exports);
var import_form_data = __toESM(require("form-data"));
var import_n8n_workflow = require("n8n-workflow");
var import_binary_data = require("../../../helpers/binary-data");
var import_polling = require("../../../helpers/polling");
var import_transport = require("../../../transport");
var import_descriptions = require("../descriptions");
const properties = [
(0, import_descriptions.modelRLC)("videoModelSearch"),
{
displayName: "Prompt",
name: "prompt",
type: "string",
default: "A video of a cat playing with a ball",
description: "The prompt to generate a video from",
required: true,
typeOptions: {
rows: 2
}
},
{
displayName: "Seconds",
name: "seconds",
type: "number",
default: 4,
description: "Clip duration in seconds",
required: true
},
{
displayName: "Size",
name: "size",
type: "options",
default: "1280x720",
description: "Output resolution formatted as width x height. 1024x1792 and 1792x1024 are only supported by Sora 2 Pro.",
options: [
{ name: "720x1280", value: "720x1280" },
{ name: "1280x720", value: "1280x720" },
{ name: "1024x1792", value: "1024x1792" },
{ name: "1792x1024", value: "1792x1024" }
]
},
{
displayName: "Options",
name: "options",
placeholder: "Add Option",
type: "collection",
default: {},
options: [
{
displayName: "Reference",
description: "Optional image reference that guides generation",
name: "binaryPropertyNameReference",
type: "string",
default: "data",
placeholder: "e.g. data"
},
{
displayName: "Wait Timeout",
name: "waitTime",
type: "number",
default: 300,
description: "Time to wait for the video to be generated in seconds",
typeOptions: {
minValue: 5,
maxValue: 7200
}
},
{
displayName: "Output Field Name",
name: "fileName",
type: "string",
default: "data",
hint: "The name of the output field to put the binary file data in"
}
]
}
];
const displayOptions = {
show: {
operation: ["generate"],
resource: ["video"]
}
};
const description = (0, import_n8n_workflow.updateDisplayOptions)(displayOptions, properties);
async function execute(i) {
const model = this.getNodeParameter("modelId", i, "", { extractValue: true });
const prompt = this.getNodeParameter("prompt", i);
const seconds = this.getNodeParameter("seconds", i);
const size = this.getNodeParameter("size", i);
const options = this.getNodeParameter("options", i, {});
const waitSeconds = options.waitTime || 300;
const formData = new import_form_data.default();
formData.append("model", model);
formData.append("prompt", prompt);
formData.append("seconds", seconds.toString());
formData.append("size", size);
if (options.binaryPropertyNameReference) {
const { fileContent, contentType, filename } = await (0, import_binary_data.getBinaryDataFile)(
this,
i,
options.binaryPropertyNameReference
);
const buffer = await this.helpers.binaryToBuffer(fileContent);
formData.append("input_reference", buffer, {
filename,
contentType
});
}
const response = await import_transport.apiRequest.call(this, "POST", "/videos", {
option: { formData },
headers: formData.getHeaders()
});
const finalResponse = await (0, import_polling.pollUntilAvailable)(
this,
async () => {
return await import_transport.apiRequest.call(this, "GET", `/videos/${response.id}`);
},
(response2) => {
if (response2.error) {
throw new import_n8n_workflow.NodeOperationError(this.getNode(), "Error generating video", {
description: response2.error.message,
itemIndex: i
});
}
return response2.status === "completed";
},
waitSeconds,
10
);
const contentResponse = await import_transport.apiRequest.call(
this,
"GET",
`/videos/${finalResponse.id}/content`,
{
option: {
useStream: true,
resolveWithFullResponse: true,
json: false,
encoding: null
}
}
);
const mimeType = contentResponse.headers["content-type"];
const binaryData = await this.helpers.prepareBinaryData(
contentResponse.body,
options.fileName || "data",
mimeType
);
return [
{
json: Object.assign({}, binaryData, {
data: void 0
}),
binary: {
data: binaryData
},
pairedItem: { item: i }
}
];
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
description,
execute
});
//# sourceMappingURL=generate.operation.js.map