n8n-nodes-sotoros-gotenberg 1.0.9 → 1.0.10

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.
@@ -298,7 +298,8 @@ class Gotenberg {
298
298
  listPropertyName: listPropertyName || '(root array)',
299
299
  processingSteps: [],
300
300
  };
301
- // Собираем все binary данные из всех элементов списка
301
+ // Собираем все binary данные из aggregatedItem.binary
302
+ // Используем только getBinaryDataBuffer(0, key) для получения файлов
302
303
  for (let listIndex = 0; listIndex < listData.length; listIndex++) {
303
304
  const listItem = listData[listIndex];
304
305
  const stepInfo = {
@@ -307,171 +308,99 @@ class Gotenberg {
307
308
  isObject: typeof listItem === 'object' && listItem !== null,
308
309
  itemKeys: listItem && typeof listItem === 'object' ? Object.keys(listItem) : [],
309
310
  foundBinary: false,
310
- source: 'none',
311
311
  binaryKey: undefined,
312
+ processedFiles: 0,
312
313
  };
313
314
  if (!listItem || typeof listItem !== 'object') {
314
315
  stepInfo.error = 'Item is not an object or is null';
315
316
  debugInfo.processingSteps.push(stepInfo);
316
317
  continue; // Пропускаем некорректные элементы
317
318
  }
318
- // Элемент списка может быть INodeExecutionData полями json и binary)
319
- // или обычным объектом с binary данными в разных местах
320
- let itemBinary;
321
- let binaryProperty;
322
- let binaryKeyFromAggregated;
323
- let source = 'unknown';
324
- // Вариант 1: элемент имеет структуру INodeExecutionData (json и binary)
325
- if ('binary' in listItem && listItem.binary && typeof listItem.binary === 'object') {
326
- itemBinary = listItem.binary;
327
- if (binaryPropertyName in itemBinary) {
328
- binaryProperty = itemBinary[binaryPropertyName];
329
- source = 'listItem.binary';
330
- stepInfo.source = source;
331
- stepInfo.binaryKey = binaryPropertyName;
332
- stepInfo.foundBinary = true;
333
- }
334
- }
335
- // Вариант 2: binary данные находятся в свойстве элемента напрямую
336
- if (!binaryProperty && binaryPropertyName in listItem) {
337
- const binaryProp = listItem[binaryPropertyName];
338
- if (binaryProp && typeof binaryProp === 'object') {
339
- // Может быть одиночным объектом или массивом
340
- if (binaryProp.data || binaryProp.fileName || binaryProp.mimeType) {
341
- // Это одиночный binary объект
342
- binaryProperty = binaryProp;
343
- source = 'listItem[binaryPropertyName]';
344
- stepInfo.source = source;
345
- stepInfo.binaryKey = binaryPropertyName;
346
- stepInfo.foundBinary = true;
347
- }
348
- else if (Array.isArray(binaryProp)) {
349
- // Это массив binary объектов
350
- binaryProperty = binaryProp;
351
- source = 'listItem[binaryPropertyName] (array)';
352
- stepInfo.source = source;
353
- stepInfo.binaryKey = binaryPropertyName;
354
- stepInfo.foundBinary = true;
355
- }
356
- }
357
- }
358
- // Вариант 3: если binary данные не найдены в элементе списка,
359
- // ищем их в aggregatedItem.binary по индексу
319
+ // Определяем ключ для binary данных в aggregatedItem.binary
360
320
  // Для первого элемента (index 0) используем binaryPropertyName, для остальных - binaryPropertyName_${index}
361
- if (!binaryProperty && aggregatedItem.binary) {
362
- binaryKeyFromAggregated = listIndex === 0 ? binaryPropertyName : `${binaryPropertyName}_${listIndex}`;
363
- if (binaryKeyFromAggregated in aggregatedItem.binary) {
364
- binaryProperty = aggregatedItem.binary[binaryKeyFromAggregated];
365
- source = 'aggregatedItem.binary';
366
- stepInfo.source = source;
367
- stepInfo.binaryKey = binaryKeyFromAggregated;
321
+ let binaryKey;
322
+ const possibleKeys = [
323
+ listIndex === 0 ? binaryPropertyName : `${binaryPropertyName}_${listIndex}`, // data или data_0, data_1, etc.
324
+ `${binaryPropertyName}_${listIndex + 1}`, // data_1 для index 0
325
+ `${listIndex}`, // просто индекс
326
+ `file_${listIndex}`, // file_0, file_1
327
+ ];
328
+ // Ищем первый доступный ключ в aggregatedItem.binary
329
+ for (const key of possibleKeys) {
330
+ if (aggregatedItem.binary && key in aggregatedItem.binary) {
331
+ binaryKey = key;
332
+ stepInfo.binaryKey = key;
368
333
  stepInfo.foundBinary = true;
369
- }
370
- else {
371
- // Пробуем альтернативные варианты именования
372
- const alternativeKeys = [
373
- `${binaryPropertyName}_${listIndex + 1}`, // data_1 для index 0
374
- `${listIndex}`, // просто индекс
375
- `file_${listIndex}`, // file_0, file_1
376
- ];
377
- for (const altKey of alternativeKeys) {
378
- if (altKey in aggregatedItem.binary) {
379
- binaryProperty = aggregatedItem.binary[altKey];
380
- source = `aggregatedItem.binary (alternative key: ${altKey})`;
381
- stepInfo.source = source;
382
- stepInfo.binaryKey = altKey;
383
- stepInfo.foundBinary = true;
384
- binaryKeyFromAggregated = altKey;
385
- break;
386
- }
387
- }
334
+ break;
388
335
  }
389
336
  }
390
- if (!binaryProperty) {
391
- stepInfo.error = `Binary property not found. Tried: listItem.binary["${binaryPropertyName}"], listItem["${binaryPropertyName}"], aggregatedItem.binary["${binaryPropertyName}${listIndex === 0 ? '' : '_' + listIndex}"]`;
337
+ if (!binaryKey) {
338
+ stepInfo.error = `Binary key not found in aggregatedItem.binary. Tried keys: ${possibleKeys.join(', ')}. Available keys: ${aggregatedBinaryKeys.join(', ')}`;
392
339
  debugInfo.processingSteps.push(stepInfo);
393
340
  continue; // Пропускаем элементы без binary данных
394
341
  }
395
- // Обрабатываем как одиночное значение, так и массив
396
- const binaryItems = Array.isArray(binaryProperty) ? binaryProperty : [binaryProperty];
397
- stepInfo.binaryItemsCount = binaryItems.length;
398
- // Добавляем все файлы из этого элемента списка
399
- for (let i = 0; i < binaryItems.length; i++) {
400
- const binaryItem = binaryItems[i];
401
- if (!binaryItem) {
402
- stepInfo.error = `Binary item ${i} is null or undefined`;
403
- continue; // Пропускаем файлы без данных
404
- }
405
- // Получаем buffer из binary данных через хелпер n8n
406
- let dataBuffer;
407
- let bufferError;
408
- const fileInfo = {
409
- listIndex,
410
- fileIndex: i,
411
- source,
412
- binaryKey: binaryKeyFromAggregated || binaryPropertyName,
413
- fileName: binaryItem.fileName || 'unknown',
414
- mimeType: binaryItem.mimeType || 'unknown',
415
- hasData: false,
416
- fileSize: 0,
417
- };
418
- try {
419
- // Если binary данные из aggregatedItem.binary, используем имя свойства напрямую
420
- if (binaryKeyFromAggregated) {
421
- dataBuffer = await this.helpers.getBinaryDataBuffer(0, binaryKeyFromAggregated);
422
- fileInfo.source = `aggregatedItem.binary["${binaryKeyFromAggregated}"]`;
423
- }
424
- else {
425
- // Используем хелпер getBinaryDataBuffer для правильной обработки binary данных
426
- // Передаем itemIndex = 0 (aggregatedItem) и IBinaryData объект
427
- dataBuffer = await this.helpers.getBinaryDataBuffer(0, binaryItem);
428
- fileInfo.source = source;
429
- }
430
- }
431
- catch (error) {
432
- bufferError = error.message || String(error);
433
- fileInfo.bufferError = bufferError;
434
- // Если не получилось через хелпер, пробуем напрямую (для обратной совместимости)
435
- if (binaryItem.data) {
436
- try {
437
- dataBuffer = Buffer.from(binaryItem.data, 'base64');
438
- fileInfo.source = `${source} (direct base64)`;
439
- }
440
- catch (e) {
441
- bufferError = `Failed to decode base64: ${e.message}`;
442
- fileInfo.bufferError = bufferError;
443
- }
444
- }
445
- else {
446
- fileInfo.bufferError = 'No data field in binaryItem and getBinaryDataBuffer failed';
447
- debugInfo.processingSteps.push(stepInfo);
448
- continue; // Пропускаем файлы без данных
449
- }
450
- }
451
- if (!dataBuffer || dataBuffer.length === 0) {
452
- fileInfo.bufferError = 'Buffer is empty or null';
453
- debugInfo.processingSteps.push(stepInfo);
454
- continue; // Пропускаем пустые файлы
455
- }
342
+ // Получаем метаданные binary файла из aggregatedItem.binary
343
+ if (!aggregatedItem.binary) {
344
+ stepInfo.error = 'aggregatedItem.binary is undefined';
345
+ debugInfo.processingSteps.push(stepInfo);
346
+ continue;
347
+ }
348
+ const binaryMetadata = aggregatedItem.binary[binaryKey];
349
+ if (!binaryMetadata) {
350
+ stepInfo.error = `Binary metadata not found for key: ${binaryKey}`;
351
+ debugInfo.processingSteps.push(stepInfo);
352
+ continue;
353
+ }
354
+ // Получаем buffer из binary данных через хелпер n8n
355
+ // Используем только getBinaryDataBuffer(0, key)
356
+ let dataBuffer;
357
+ let bufferError;
358
+ const fileInfo = {
359
+ listIndex,
360
+ fileIndex: 0,
361
+ binaryKey,
362
+ fileName: binaryMetadata.fileName || 'unknown',
363
+ mimeType: binaryMetadata.mimeType || 'application/octet-stream',
364
+ hasData: false,
365
+ fileSize: 0,
366
+ };
367
+ try {
368
+ // Используем только getBinaryDataBuffer(0, key) для получения файла
369
+ dataBuffer = await this.helpers.getBinaryDataBuffer(0, binaryKey);
456
370
  fileInfo.hasData = true;
457
371
  fileInfo.fileSize = dataBuffer.length;
458
- // Используем fileName из метаданных элемента списка, если доступно
459
- const fileName = binaryItem.fileName ||
460
- (listItem && typeof listItem === 'object' && 'fileName' in listItem
461
- ? listItem.fileName
462
- : undefined) ||
463
- (listItem && typeof listItem === 'object' && 'fileExtension' in listItem
464
- ? `${binaryPropertyName}_${listIndex}.${listItem.fileExtension}`
465
- : `${binaryPropertyName}_${listIndex}_${i}.${getFileExtensionFromMimeType(binaryItem.mimeType || '')}`);
466
- fileInfo.fileName = fileName;
467
- formData.append('files', dataBuffer, {
468
- filename: fileName,
469
- contentType: binaryItem.mimeType || 'application/octet-stream',
470
- });
372
+ }
373
+ catch (error) {
374
+ bufferError = error.message || String(error);
375
+ fileInfo.error = bufferError;
376
+ stepInfo.error = `Failed to get binary data buffer: ${bufferError}`;
377
+ debugInfo.processingSteps.push(stepInfo);
471
378
  processedFiles.push(fileInfo);
472
- totalFilesCount++;
379
+ continue; // Пропускаем файлы, которые не удалось получить
473
380
  }
474
- stepInfo.processedFiles = processedFiles.filter((f) => f.listIndex === listIndex).length;
381
+ if (!dataBuffer || dataBuffer.length === 0) {
382
+ fileInfo.error = 'Buffer is empty or null';
383
+ stepInfo.error = 'Buffer is empty or null';
384
+ debugInfo.processingSteps.push(stepInfo);
385
+ processedFiles.push(fileInfo);
386
+ continue; // Пропускаем пустые файлы
387
+ }
388
+ // Используем fileName из метаданных или генерируем на основе данных элемента списка
389
+ const fileName = binaryMetadata.fileName ||
390
+ (listItem && typeof listItem === 'object' && 'fileName' in listItem
391
+ ? listItem.fileName
392
+ : undefined) ||
393
+ (listItem && typeof listItem === 'object' && 'fileExtension' in listItem
394
+ ? `${binaryPropertyName}_${listIndex}.${listItem.fileExtension}`
395
+ : `${binaryPropertyName}_${listIndex}.${getFileExtensionFromMimeType(binaryMetadata.mimeType || '')}`);
396
+ fileInfo.fileName = fileName;
397
+ formData.append('files', dataBuffer, {
398
+ filename: fileName,
399
+ contentType: binaryMetadata.mimeType || 'application/octet-stream',
400
+ });
401
+ processedFiles.push(fileInfo);
402
+ totalFilesCount++;
403
+ stepInfo.processedFiles = 1;
475
404
  debugInfo.processingSteps.push(stepInfo);
476
405
  }
477
406
  if (totalFilesCount === 0) {
@@ -744,13 +673,14 @@ class Gotenberg {
744
673
  processedItems: listData.length,
745
674
  debug: {
746
675
  processedFiles: processedFiles.map((f) => ({
747
- source: f.source,
748
676
  binaryKey: f.binaryKey,
749
677
  fileName: f.fileName,
750
678
  fileSize: f.fileSize,
751
679
  mimeType: f.mimeType,
752
680
  listIndex: f.listIndex,
753
681
  fileIndex: f.fileIndex,
682
+ hasData: f.hasData,
683
+ error: f.error,
754
684
  })),
755
685
  processingSteps: debugInfo.processingSteps,
756
686
  aggregatedBinaryKeys: debugInfo.aggregatedItemBinaryKeys,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "n8n-nodes-sotoros-gotenberg",
3
- "version": "1.0.9",
3
+ "version": "1.0.10",
4
4
  "description": "n8n custom node for Gotenberg integration with binary data support",
5
5
  "keywords": [
6
6
  "n8n-community-node",