@n8n/n8n-nodes-langchain
Version:

148 lines • 5.39 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.description = void 0;
exports.execute = execute;
const form_data_1 = __importDefault(require("form-data"));
const n8n_workflow_1 = require("n8n-workflow");
const binary_data_1 = require("../../../helpers/binary-data");
const polling_1 = require("../../../helpers/polling");
const transport_1 = require("../../../transport");
const descriptions_1 = require("../descriptions");
const properties = [
(0, descriptions_1.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'],
},
};
exports.description = (0, n8n_workflow_1.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 form_data_1.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, binary_data_1.getBinaryDataFile)(this, i, options.binaryPropertyNameReference);
const buffer = await this.helpers.binaryToBuffer(fileContent);
formData.append('input_reference', buffer, {
filename,
contentType,
});
}
const response = (await transport_1.apiRequest.call(this, 'POST', '/videos', {
option: { formData },
headers: formData.getHeaders(),
}));
const finalResponse = await (0, polling_1.pollUntilAvailable)(this, async () => {
return (await transport_1.apiRequest.call(this, 'GET', `/videos/${response.id}`));
}, (response) => {
if (response.error) {
throw new n8n_workflow_1.NodeOperationError(this.getNode(), 'Error generating video', {
description: response.error.message,
itemIndex: i,
});
}
return response.status === 'completed';
}, waitSeconds, 10);
const contentResponse = await transport_1.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: undefined,
}),
binary: {
data: binaryData,
},
pairedItem: { item: i },
},
];
}
//# sourceMappingURL=generate.operation.js.map