@wiro-ai/n8n-nodes-wiroai
Version:
n8n community node for Wiro AI — 290+ AI models: video, image, audio, LLM, 3D, and more.
130 lines • 5.3 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.ImageToVideoKlingai21Master = void 0;
const n8n_workflow_1 = require("n8n-workflow");
const auth_1 = require("../utils/auth");
const polling_1 = require("../utils/polling");
class ImageToVideoKlingai21Master {
constructor() {
this.description = {
displayName: 'Wiro - Image To Video Klingai V2 1 Master',
name: 'imageToVideoKlingai21Master',
icon: { light: 'file:wiro.svg', dark: 'file:wiro.svg' },
group: ['transform'],
version: 1,
description: 'KlingAI v2.1-master image to video generation tool. Generate 5s and 10s videos in 720p resoluti',
defaults: {
name: 'Wiro - Image To Video Klingai V2 1 Master',
},
inputs: [n8n_workflow_1.NodeConnectionTypes.Main],
outputs: [n8n_workflow_1.NodeConnectionTypes.Main],
usableAsTool: true,
credentials: [
{
name: 'wiroApi',
required: true,
},
],
properties: [
{
displayName: 'Image First URL',
name: 'inputImageFirstUrl',
type: 'string',
default: '',
description: 'First frame of the video',
},
{
displayName: 'Prompt',
name: 'prompt',
type: 'string',
default: '',
description: 'The prompt to generate the video',
},
{
displayName: 'Negative Prompt',
name: 'negativePrompt',
type: 'string',
default: '',
description: 'Things you do not want to see in the video',
},
{
displayName: 'Video Seconds',
name: 'videoSeconds',
type: 'options',
default: '10',
required: true,
description: 'Total duration of the generated video (in seconds)',
options: [
{ name: '10s', value: '10' },
{ name: '5s', value: '5' },
],
},
{
displayName: 'CFG Scale',
name: 'scale',
type: 'number',
default: 0,
description: 'Flexibility in video generation; The higher the value, the lower the model\'s degree of flexibility, and the stronger the relevance to the user\'s prompt',
},
],
};
}
async execute() {
const returnData = [];
const inputImageFirstUrl = this.getNodeParameter('inputImageFirstUrl', 0, '');
const prompt = this.getNodeParameter('prompt', 0, '');
const negativePrompt = this.getNodeParameter('negativePrompt', 0, '');
const videoSeconds = this.getNodeParameter('videoSeconds', 0);
const scale = this.getNodeParameter('scale', 0, 0);
const credentials = await this.getCredentials('wiroApi');
const apiKey = credentials.apiKey;
const apiSecret = credentials.apiSecret;
const headers = (0, auth_1.generateWiroAuthHeaders)(apiKey, apiSecret);
const response = await this.helpers.httpRequest({
method: 'POST',
url: 'https://api.wiro.ai/v1/Run/klingai/image-to-video-klingai-v2.1-master',
headers: {
...headers,
'Content-Type': 'application/json',
},
body: {
inputImageFirstUrl,
prompt,
negativePrompt,
videoSeconds,
scale,
},
});
if (!(response === null || response === void 0 ? void 0 : response.taskid) || !(response === null || response === void 0 ? void 0 : response.socketaccesstoken)) {
throw new n8n_workflow_1.NodeApiError(this.getNode(), {
message: 'Wiro API did not return a valid task ID or socket access token ' +
JSON.stringify(response),
});
}
const taskid = response.taskid;
const socketaccesstoken = response.socketaccesstoken;
const result = await polling_1.pollTaskUntilComplete.call(this, socketaccesstoken, headers);
const responseJSON = {
taskid: taskid,
url: '',
status: '',
};
switch (result) {
case '-1':
case '-2':
case '-3':
case '-4':
responseJSON.status = 'failed';
break;
default:
responseJSON.status = 'completed';
responseJSON.url = result !== null && result !== void 0 ? result : '';
}
returnData.push({
json: responseJSON,
});
return [returnData];
}
}
exports.ImageToVideoKlingai21Master = ImageToVideoKlingai21Master;
//# sourceMappingURL=ImageToVideoKlingai21Master.node.js.map