n8n-nodes-sotoros-gotenberg 1.0.7 → 1.0.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -321,10 +321,11 @@ class Gotenberg {
|
|
|
321
321
|
// Вариант 3: если binary данные не найдены в элементе списка,
|
|
322
322
|
// ищем их в aggregatedItem.binary по индексу
|
|
323
323
|
// Для первого элемента (index 0) используем binaryPropertyName, для остальных - binaryPropertyName_${index}
|
|
324
|
+
let binaryKeyFromAggregated;
|
|
324
325
|
if (!binaryProperty && aggregatedItem.binary) {
|
|
325
|
-
|
|
326
|
-
if (
|
|
327
|
-
binaryProperty = aggregatedItem.binary[
|
|
326
|
+
binaryKeyFromAggregated = listIndex === 0 ? binaryPropertyName : `${binaryPropertyName}_${listIndex}`;
|
|
327
|
+
if (binaryKeyFromAggregated in aggregatedItem.binary) {
|
|
328
|
+
binaryProperty = aggregatedItem.binary[binaryKeyFromAggregated];
|
|
328
329
|
}
|
|
329
330
|
}
|
|
330
331
|
if (!binaryProperty) {
|
|
@@ -335,11 +336,31 @@ class Gotenberg {
|
|
|
335
336
|
// Добавляем все файлы из этого элемента списка
|
|
336
337
|
for (let i = 0; i < binaryItems.length; i++) {
|
|
337
338
|
const binaryItem = binaryItems[i];
|
|
338
|
-
if (!binaryItem
|
|
339
|
+
if (!binaryItem) {
|
|
339
340
|
continue; // Пропускаем файлы без данных
|
|
340
341
|
}
|
|
341
|
-
// Получаем buffer из binary данных
|
|
342
|
-
|
|
342
|
+
// Получаем buffer из binary данных через хелпер n8n
|
|
343
|
+
let dataBuffer;
|
|
344
|
+
try {
|
|
345
|
+
// Если binary данные из aggregatedItem.binary, используем имя свойства напрямую
|
|
346
|
+
if (binaryKeyFromAggregated) {
|
|
347
|
+
dataBuffer = await this.helpers.getBinaryDataBuffer(0, binaryKeyFromAggregated);
|
|
348
|
+
}
|
|
349
|
+
else {
|
|
350
|
+
// Используем хелпер getBinaryDataBuffer для правильной обработки binary данных
|
|
351
|
+
// Передаем itemIndex = 0 (aggregatedItem) и IBinaryData объект
|
|
352
|
+
dataBuffer = await this.helpers.getBinaryDataBuffer(0, binaryItem);
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
catch (error) {
|
|
356
|
+
// Если не получилось через хелпер, пробуем напрямую (для обратной совместимости)
|
|
357
|
+
if (binaryItem.data) {
|
|
358
|
+
dataBuffer = Buffer.from(binaryItem.data, 'base64');
|
|
359
|
+
}
|
|
360
|
+
else {
|
|
361
|
+
continue; // Пропускаем файлы без данных
|
|
362
|
+
}
|
|
363
|
+
}
|
|
343
364
|
// Используем fileName из метаданных элемента списка, если доступно
|
|
344
365
|
const fileName = binaryItem.fileName ||
|
|
345
366
|
(listItem && typeof listItem === 'object' && 'fileName' in listItem
|
|
@@ -494,13 +515,63 @@ class Gotenberg {
|
|
|
494
515
|
}
|
|
495
516
|
// Отправляем запрос в Gotenberg
|
|
496
517
|
const url = `${gotenbergUrl.replace(/\/$/, '')}${endpoint}`;
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
518
|
+
let response;
|
|
519
|
+
try {
|
|
520
|
+
response = await this.helpers.httpRequest({
|
|
521
|
+
method: 'POST',
|
|
522
|
+
url,
|
|
523
|
+
body: formData,
|
|
524
|
+
returnFullResponse: true,
|
|
525
|
+
headers: formData.getHeaders(),
|
|
526
|
+
});
|
|
527
|
+
}
|
|
528
|
+
catch (error) {
|
|
529
|
+
// Улучшенная обработка ошибок подключения
|
|
530
|
+
if (error.code === 'ECONNREFUSED') {
|
|
531
|
+
throw new n8n_workflow_1.NodeOperationError(this.getNode(), `Cannot connect to Gotenberg server at ${url}. ` +
|
|
532
|
+
`Connection refused. Please check:\n` +
|
|
533
|
+
`- Is Gotenberg server running?\n` +
|
|
534
|
+
`- Is the URL correct? (current: ${gotenbergUrl})\n` +
|
|
535
|
+
`- Is the port correct? (current endpoint: ${url})\n` +
|
|
536
|
+
`- If using IPv6 (::1), try using 127.0.0.1 or localhost instead`);
|
|
537
|
+
}
|
|
538
|
+
else if (error.code === 'ENOTFOUND' || error.code === 'EAI_AGAIN') {
|
|
539
|
+
throw new n8n_workflow_1.NodeOperationError(this.getNode(), `Cannot resolve Gotenberg server hostname. ` +
|
|
540
|
+
`Please check that the URL is correct: ${gotenbergUrl}`);
|
|
541
|
+
}
|
|
542
|
+
else if (error.code === 'ETIMEDOUT' || error.code === 'ECONNABORTED') {
|
|
543
|
+
throw new n8n_workflow_1.NodeOperationError(this.getNode(), `Connection to Gotenberg server timed out at ${url}. ` +
|
|
544
|
+
`Please check that the server is accessible and not overloaded.`);
|
|
545
|
+
}
|
|
546
|
+
else if (error.response) {
|
|
547
|
+
// Ошибка от сервера (HTTP ошибка)
|
|
548
|
+
const statusCode = error.response.status || error.response.statusCode;
|
|
549
|
+
let errorText;
|
|
550
|
+
if (error.response.data) {
|
|
551
|
+
if (Buffer.isBuffer(error.response.data)) {
|
|
552
|
+
errorText = error.response.data.toString('utf-8');
|
|
553
|
+
}
|
|
554
|
+
else if (typeof error.response.data === 'string') {
|
|
555
|
+
errorText = error.response.data;
|
|
556
|
+
}
|
|
557
|
+
else {
|
|
558
|
+
errorText = JSON.stringify(error.response.data);
|
|
559
|
+
}
|
|
560
|
+
}
|
|
561
|
+
else {
|
|
562
|
+
errorText = error.message || 'Unknown error';
|
|
563
|
+
}
|
|
564
|
+
throw new n8n_workflow_2.NodeApiError(this.getNode(), {
|
|
565
|
+
message: `Gotenberg API error: ${statusCode}`,
|
|
566
|
+
description: errorText,
|
|
567
|
+
});
|
|
568
|
+
}
|
|
569
|
+
else {
|
|
570
|
+
// Другие ошибки
|
|
571
|
+
throw new n8n_workflow_1.NodeOperationError(this.getNode(), `Error connecting to Gotenberg server: ${error.message || String(error)}. ` +
|
|
572
|
+
`URL: ${url}`);
|
|
573
|
+
}
|
|
574
|
+
}
|
|
504
575
|
// Проверяем статус ответа
|
|
505
576
|
if (response.statusCode && response.statusCode >= 400) {
|
|
506
577
|
let errorText;
|