n8n-nodes-piapi
Version:
Community n8n nodes for PiAPI - integrate generative AI capabilities (image, video, audio, 3D) into your workflows
140 lines • 5.47 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.HailuoSubjectVideo = void 0;
const GenericFunctions_1 = require("../shared/GenericFunctions");
class HailuoSubjectVideo {
constructor() {
this.description = {
displayName: 'Hailuo Subject Reference Video',
name: 'hailuoSubjectVideo',
icon: 'file:../piapi.svg',
group: ['transform'],
version: 1,
description: 'Generate video from text and reference image of a person using Hailuo API',
defaults: {
name: 'Hailuo Subject Reference Video',
},
inputs: ["main"],
outputs: ["main"],
credentials: [
{
name: 'piAPIApi',
required: true,
},
],
properties: [
{
displayName: 'Text Prompt',
name: 'prompt',
type: 'string',
typeOptions: {
rows: 4,
},
default: '',
required: true,
description: 'Text prompt for video generation (max 2000 characters)',
},
{
displayName: 'Reference Image URL',
name: 'imageUrl',
type: 'string',
default: '',
required: true,
description: 'URL of reference image with a human face (JPG/PNG, 300-4096px, aspect ratio 2:5 to 5:2, max 10MB)',
},
{
displayName: 'Expand Prompt',
name: 'expandPrompt',
type: 'boolean',
default: false,
description: 'Whether to expand the input prompt to add details',
},
{
displayName: 'Wait for Completion',
name: 'waitForCompletion',
type: 'boolean',
default: false,
description: 'Whether to wait for the video generation to complete',
},
{
displayName: 'Maximum Retries',
name: 'maxRetries',
type: 'number',
displayOptions: {
show: {
waitForCompletion: [true],
},
},
default: 20,
description: 'Maximum number of times to check task status',
},
{
displayName: 'Retry Interval (ms)',
name: 'retryInterval',
type: 'number',
displayOptions: {
show: {
waitForCompletion: [true],
},
},
default: 3000,
description: 'Time to wait between status checks in milliseconds',
},
],
};
}
async execute() {
const items = this.getInputData();
const returnData = [];
for (let i = 0; i < items.length; i++) {
try {
const prompt = this.getNodeParameter('prompt', i);
const imageUrl = this.getNodeParameter('imageUrl', i);
const expandPrompt = this.getNodeParameter('expandPrompt', i, false);
const waitForCompletion = this.getNodeParameter('waitForCompletion', i, true);
const maxRetries = waitForCompletion ? this.getNodeParameter('maxRetries', i, 20) : 0;
const retryInterval = waitForCompletion ? this.getNodeParameter('retryInterval', i, 3000) : 0;
const parameters = {
prompt,
image_url: imageUrl,
model: 's2v-01',
expand_prompt: expandPrompt,
};
const response = await GenericFunctions_1.piApiRequest.call(this, 'POST', '/api/v1/task', {
model: 'hailuo',
task_type: 'video_generation',
input: parameters,
config: {
service_mode: 'public',
},
});
if (waitForCompletion) {
const taskId = response.data.task_id;
const taskData = await GenericFunctions_1.waitForTaskCompletion.call(this, taskId, maxRetries, retryInterval);
returnData.push({
json: taskData,
});
}
else {
returnData.push({
json: response.data,
});
}
}
catch (error) {
if (this.continueOnFail()) {
returnData.push({
json: {
error: error.message,
},
});
continue;
}
throw error;
}
}
return [returnData];
}
}
exports.HailuoSubjectVideo = HailuoSubjectVideo;
//# sourceMappingURL=HailuoSubjectVideo.node.js.map
;