UNPKG

n8n-nodes-placid

Version:

n8n node to interact with Placid API for creative generation

88 lines 3.45 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.execute = execute; const get_operation_1 = require("./get.operation"); const layerUtils_1 = require("../../utils/layerUtils"); async function execute(i) { var _a; const configurationMode = this.getNodeParameter('configurationMode', i); const body = { clips: [], }; const additionalFields = this.getNodeParameter('additionalFields', i, {}); if (additionalFields.webhook_success) { body.webhook_success = additionalFields.webhook_success; } if (additionalFields.passthrough) { body.passthrough = additionalFields.passthrough; } if (configurationMode === 'advanced') { const clipsJson = this.getNodeParameter('clipsJson', i); try { const clips = JSON.parse(clipsJson); if (!Array.isArray(clips)) { throw new Error('Clips JSON must be an array'); } body.clips = clips; } catch (error) { throw new Error(`Invalid JSON in clips configuration: ${error.message}`); } } else { const clips = this.getNodeParameter('clips.clipItems', i, []); if (!clips || clips.length === 0) { throw new Error('At least one clip is required for video generation'); } for (const clip of clips) { const templateId = typeof clip.template_id === 'string' ? clip.template_id : clip.template_id.value; if (!templateId) { throw new Error('Template ID is required for each clip'); } const clipData = { template_uuid: templateId, layers: {}, }; if (clip.audioSettings) { Object.assign(clipData, clip.audioSettings); } const layers = ((_a = clip.layerData) === null || _a === void 0 ? void 0 : _a.layerItems) || []; clipData.layers = await (0, layerUtils_1.processUnifiedLayers)(layers, this, i); body.clips.push(clipData); } } const createOptions = { method: 'POST', url: 'https://api.placid.app/api/rest/videos', headers: { 'Accept': 'application/json', 'Content-Type': 'application/json', }, body, }; const createResponse = await this.helpers.httpRequestWithAuthentication.call(this, 'placidApi', createOptions); if (createResponse.id) { const videoId = createResponse.id; const maxAttempts = 60; const pollInterval = 5000; for (let attempt = 0; attempt < maxAttempts; attempt++) { if (attempt > 0) { await new Promise(resolve => setTimeout(resolve, pollInterval)); } const pollResponse = await (0, get_operation_1.getVideoById)(this, videoId); if (pollResponse.status === 'finished') { return { json: pollResponse, }; } else if (pollResponse.status === 'error') { throw new Error(`Video generation failed: ${pollResponse.error || 'Unknown error'}`); } } throw new Error(`Video generation timed out after ${maxAttempts} attempts. Last status: ${createResponse.status}`); } return { json: createResponse, }; } //# sourceMappingURL=create.operation.js.map