@wiro-ai/n8n-nodes-wiroai
Version:
n8n community node for Wiro AI's Generative AI APIs.
147 lines • 5.92 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.ImageToVideoKling16 = void 0;
const n8n_workflow_1 = require("n8n-workflow");
const auth_1 = require("../utils/auth");
const polling_1 = require("../utils/polling");
class ImageToVideoKling16 {
constructor() {
this.description = {
displayName: 'Wiro - Image to Video (KlingAI 1.6)',
name: 'imageToVideoKling16',
icon: { light: 'file:wiro.svg', dark: 'file:wiro.svg' },
group: ['transform'],
version: 1,
description: 'Generates video with image using KlingAI 1.6',
defaults: {
name: 'Wiro - Image to Video (KlingAI 1.6)',
},
inputs: ["main"],
outputs: ["main"],
usableAsTool: true,
credentials: [
{
name: 'wiroApi',
required: true,
},
],
properties: [
{
displayName: 'Input Image (First Frame) URL',
name: 'inputImageFirstUrl',
type: 'string',
default: '',
required: true,
description: 'Public image URL to be used as the first frame of the animation',
},
{
displayName: 'Input Image (Last Frame) URL',
name: 'inputImageLastUrl',
type: 'string',
default: '',
description: 'This is optional and can be used with only Video Mode Pro., Public image URL to be used as the last frame of the animation',
},
{
displayName: 'Prompt',
name: 'prompt',
type: 'string',
default: 'a portrait photo of a woman underwater with flowing hair',
required: true,
description: 'Describe the overall animation or motion desired',
},
{
displayName: 'Negative Prompt',
name: 'negativePrompt',
type: 'string',
default: 'blurry, distorted, bad anatomy',
description: 'Describe what you do NOT want to appear in the video',
},
{
displayName: 'Video Duration (Seconds)',
name: 'videoSeconds',
type: 'string',
default: '5',
required: true,
description: 'Duration of the video to be generated',
},
{
displayName: 'Video Mode',
name: 'videoMode',
type: 'string',
default: 'std',
description: 'Video generation mode',
},
{
displayName: 'Scale',
name: 'scale',
type: 'string',
default: '0.5',
description: 'Classifier-free guidance scale',
},
],
};
}
async execute() {
const returnData = [];
const inputImageFirstUrl = this.getNodeParameter('inputImageFirstUrl', 0);
const inputImageLastUrl = this.getNodeParameter('inputImageLastUrl', 0);
const prompt = this.getNodeParameter('prompt', 0);
const negativePrompt = this.getNodeParameter('negativePrompt', 0, '');
const videoSeconds = this.getNodeParameter('videoSeconds', 0);
const videoMode = this.getNodeParameter('videoMode', 0, '');
const scale = this.getNodeParameter('scale', 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.request({
method: 'POST',
url: 'https://api.wiro.ai/v1/Run/klingai/image-to-video-klingai-v1++6',
headers: {
...headers,
'Content-Type': 'application/json',
},
body: {
inputImageFirstUrl,
inputImageLastUrl,
prompt,
negativePrompt,
videoSeconds,
videoMode,
scale,
},
json: true,
});
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.ImageToVideoKling16 = ImageToVideoKling16;
//# sourceMappingURL=ImageToVideoKling16.node.js.map