@wiro-ai/n8n-nodes-wiroai
Version:
n8n community node for Wiro AI — 290+ AI models: video, image, audio, LLM, 3D, and more.
141 lines • 5.55 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.Sora2Pro = void 0;
const n8n_workflow_1 = require("n8n-workflow");
const auth_1 = require("../utils/auth");
const polling_1 = require("../utils/polling");
class Sora2Pro {
constructor() {
this.description = {
displayName: 'Wiro - Sora 2 Pro',
name: 'sora2Pro',
icon: { light: 'file:wiro.svg', dark: 'file:wiro.svg' },
group: ['transform'],
version: 1,
description: 'Explore the Sora 2 Pro API with clear pricing and simple integration. Create high quality video',
defaults: {
name: 'Wiro - Sora 2 Pro',
},
inputs: [n8n_workflow_1.NodeConnectionTypes.Main],
outputs: [n8n_workflow_1.NodeConnectionTypes.Main],
usableAsTool: true,
credentials: [
{
name: 'wiroApi',
required: true,
},
],
properties: [
{
displayName: 'Input Image URL',
name: 'inputImageUrl',
type: 'string',
default: '',
description: 'Optional. Provide an image file or an image URL.',
},
{
displayName: 'Prompt',
name: 'prompt',
type: 'string',
default: '',
required: true,
description: 'The prompt to generate the image',
},
{
displayName: 'Seconds',
name: 'seconds',
type: 'options',
default: '12',
required: true,
description: 'Duration of the video',
options: [
{ name: '12', value: '12' },
{ name: '4', value: '4' },
{ name: '8', value: '8' },
],
},
{
displayName: 'Resolution',
name: 'resolution',
type: 'options',
default: '1080p',
description: 'Select option for resolution',
options: [
{ name: '1080p', value: '1080p' },
{ name: '720p', value: '720p' },
],
},
{
displayName: 'Ratio',
name: 'ratio',
type: 'options',
default: '16:9',
description: 'When set to auto, the system will detect the image\'s aspect ratio and choose the closest option, either 16:9 (horizontal) or 9:16 (vertical). If there is no image it will be 16:9 by default.',
options: [
{ name: '16:9', value: '16:9' },
{ name: '9:16', value: '9:16' },
{ name: 'Auto', value: 'auto' },
],
},
],
};
}
async execute() {
const returnData = [];
const inputImageUrl = this.getNodeParameter('inputImageUrl', 0, '');
const prompt = this.getNodeParameter('prompt', 0);
const seconds = this.getNodeParameter('seconds', 0);
const resolution = this.getNodeParameter('resolution', 0, '');
const ratio = this.getNodeParameter('ratio', 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/openai/sora-2-pro',
headers: {
...headers,
'Content-Type': 'application/json',
},
body: {
inputImageUrl,
prompt,
seconds,
resolution,
ratio,
},
});
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.Sora2Pro = Sora2Pro;
//# sourceMappingURL=Sora2Pro.node.js.map