UNPKG

n8n-nodes-piapi

Version:

Community n8n nodes for PiAPI - integrate generative AI capabilities (image, video, audio, 3D) into your workflows

237 lines 9.04 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.DreamMachineExtendVideo = void 0; const GenericFunctions_1 = require("../shared/GenericFunctions"); class DreamMachineExtendVideo { constructor() { this.description = { displayName: 'PiAPI Dream Machine Extend Video', name: 'dreamMachineExtendVideo', icon: 'file:../piapi.svg', group: ['transform'], version: 1, description: 'Extend existing videos using PiAPI Dream Machine', defaults: { name: 'Dream Machine Extend Video', }, inputs: ["main"], outputs: ["main"], credentials: [ { name: 'piAPIApi', required: true, }, ], properties: [ { displayName: 'Prompt', name: 'prompt', type: 'string', typeOptions: { rows: 4, }, default: '', required: true, description: 'Descriptive prompt for video extension', }, { displayName: 'Video Source', name: 'videoSource', type: 'options', options: [ { name: 'URL', value: 'url', }, { name: 'Binary Data', value: 'binaryData', }, ], default: 'url', description: 'The source of the input video', }, { displayName: 'Video URL', name: 'videoUrl', type: 'string', default: '', required: true, displayOptions: { show: { videoSource: ['url'], }, }, description: 'URL of the video to extend', }, { displayName: 'Binary Property', name: 'binaryPropertyName', type: 'string', default: 'data', required: true, displayOptions: { show: { videoSource: ['binaryData'], }, }, description: 'Name of the binary property containing the video data', }, { displayName: 'Model Name', name: 'modelName', type: 'options', options: [ { name: 'Ray v1', value: 'ray-v1', }, { name: 'Ray v2', value: 'ray-v2', }, ], default: 'ray-v1', description: 'The model to use for video extension', }, { displayName: 'Aspect Ratio', name: 'aspectRatio', type: 'options', options: [ { name: 'Portrait (9:16)', value: '9:16', }, { name: 'Portrait (3:4)', value: '3:4', }, { name: 'Square (1:1)', value: '1:1', }, { name: 'Landscape (4:3)', value: '4:3', }, { name: 'Landscape (16:9)', value: '16:9', }, { name: 'Cinematic (21:9)', value: '21:9', }, ], default: '16:9', description: 'Aspect ratio of the generated video', }, { displayName: 'Service Mode', name: 'serviceMode', type: 'options', options: [ { name: 'Default (User Workspace Setting)', value: '', }, { name: 'Pay-as-you-go (PAYG)', value: 'public', }, { name: 'Host-your-account (HYA)', value: 'private', }, ], default: '', description: 'The service mode for processing the task', }, { displayName: 'Wait for Completion', name: 'waitForCompletion', type: 'boolean', default: false, description: 'Wait for task to complete and return results', }, ], }; } async execute() { var _a; const items = this.getInputData(); const returnData = []; for (let i = 0; i < items.length; i++) { const prompt = this.getNodeParameter('prompt', i); const modelName = this.getNodeParameter('modelName', i); const aspectRatio = this.getNodeParameter('aspectRatio', i); const serviceMode = this.getNodeParameter('serviceMode', i); const waitForCompletion = this.getNodeParameter('waitForCompletion', i, true); const videoSource = this.getNodeParameter('videoSource', i); let videoUrl = ''; if (videoSource === 'url') { videoUrl = this.getNodeParameter('videoUrl', i); } else { const binaryPropertyName = this.getNodeParameter('binaryPropertyName', i); const binaryData = this.helpers.assertBinaryData(i, binaryPropertyName); if (binaryData.mimeType && !binaryData.mimeType.includes('video/')) { throw new Error('The provided binary data is not a video'); } if (binaryData.data) { const dataBuffer = Buffer.from(binaryData.data, 'base64'); videoUrl = `data:${binaryData.mimeType};base64,${dataBuffer.toString('base64')}`; } else if (binaryData.url) { videoUrl = binaryData.url; } else { throw new Error('No usable video data found in the provided binary property'); } } const body = { model: 'luma', task_type: 'extend_video', input: { prompt, key_frames: { frame0: { type: 'video', url: videoUrl, }, }, model_name: modelName, aspect_ratio: aspectRatio, }, config: { service_mode: serviceMode, }, }; try { const response = await GenericFunctions_1.piApiRequest.call(this, 'POST', '/api/v1/task', body); let taskResult = response; if (waitForCompletion && ((_a = response.data) === null || _a === void 0 ? void 0 : _a.task_id)) { taskResult = await GenericFunctions_1.waitForTaskCompletion.call(this, response.data.task_id); } returnData.push({ json: taskResult, }); } catch (error) { if (this.continueOnFail()) { returnData.push({ json: { error: error.message, }, }); continue; } throw error; } } return [returnData]; } } exports.DreamMachineExtendVideo = DreamMachineExtendVideo; //# sourceMappingURL=DreamMachineExtendVideo.node.js.map