@wiro-ai/n8n-nodes-wiroai
Version:
n8n community node for Wiro AI — 290+ AI models: video, image, audio, LLM, 3D, and more.
57 lines • 2.52 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.pollTaskUntilComplete = pollTaskUntilComplete;
const promises_1 = require("node:timers/promises");
async function pollTaskUntilComplete(socketaccesstoken, headers, options) {
var _a, _b, _c, _d, _e, _f;
const pollingIntervalMs = (_a = options === null || options === void 0 ? void 0 : options.pollingIntervalMs) !== null && _a !== void 0 ? _a : 20000;
const maxAttempts = (_b = options === null || options === void 0 ? void 0 : options.maxAttempts) !== null && _b !== void 0 ? _b : 30;
for (let attempt = 1; attempt <= maxAttempts; attempt++) {
const taskRequest = {
tasktoken: socketaccesstoken,
};
try {
const response = await this.helpers.httpRequest({
method: 'POST',
url: 'https://api.wiro.ai/v1/Task/Detail',
headers: {
...headers,
'Content-Type': 'application/json',
},
body: taskRequest,
});
const task = (_c = response.tasklist) === null || _c === void 0 ? void 0 : _c[0];
const status = task === null || task === void 0 ? void 0 : task.status;
if (status === 'task_cancel') {
return '-4';
}
if (status === 'task_postprocess_end') {
const outputs = task.outputs;
if (Array.isArray(outputs) && outputs.length > 0) {
if (outputs.length === 1) {
if ((_d = outputs[0]) === null || _d === void 0 ? void 0 : _d.url) {
return outputs[0].url;
}
}
else {
const urls = outputs.map((o) => o.url).filter(Boolean);
if (urls.length > 0) {
return urls.join(' | ');
}
}
const firstMessage = (_f = (_e = outputs[0]) === null || _e === void 0 ? void 0 : _e.content) === null || _f === void 0 ? void 0 : _f.message;
if (firstMessage) {
return firstMessage;
}
}
return '-3';
}
}
catch {
return '-2';
}
await (0, promises_1.setTimeout)(pollingIntervalMs);
}
return '-1';
}
//# sourceMappingURL=polling.js.map