n8n-nodes-h2i 1.0.0

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.
@@ -0,0 +1,572 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DavixH2I = void 0;
4
+ const GenericFunctions_1 = require("./GenericFunctions");
5
+ function toBoolString(v) {
6
+ if (typeof v === 'boolean')
7
+ return v ? 'true' : 'false';
8
+ if (typeof v === 'number')
9
+ return v === 1 ? 'true' : 'false';
10
+ if (typeof v === 'string')
11
+ return v;
12
+ return 'false';
13
+ }
14
+ class DavixH2I {
15
+ description = {
16
+ displayName: 'Davix H2I',
17
+ name: 'davixH2I',
18
+ icon: 'file:davixH2I.svg',
19
+ group: ['transform'],
20
+ version: 1,
21
+ subtitle: '={{$parameter["resource"]}}',
22
+ description: 'Use Davix PixLab public API endpoints (H2I, Image, PDF, Tools).',
23
+ defaults: {
24
+ name: 'Davix H2I',
25
+ },
26
+ inputs: ['main'],
27
+ outputs: ['main'],
28
+ credentials: [{ name: 'davixH2IApi', required: true }],
29
+ properties: [
30
+ {
31
+ displayName: 'Resource',
32
+ name: 'resource',
33
+ type: 'options',
34
+ default: 'h2i',
35
+ options: [
36
+ { name: 'H2I (HTML → Image)', value: 'h2i' },
37
+ { name: 'Image (Transform / Export PDF)', value: 'image' },
38
+ { name: 'PDF (Merge/Split/Compress/Convert)', value: 'pdf' },
39
+ { name: 'Tools (Analyze Images)', value: 'tools' },
40
+ ],
41
+ },
42
+ // -------------------------
43
+ // H2I
44
+ // -------------------------
45
+ {
46
+ displayName: 'HTML',
47
+ name: 'html',
48
+ type: 'string',
49
+ default: '',
50
+ required: true,
51
+ typeOptions: { rows: 6 },
52
+ displayOptions: { show: { resource: ['h2i'] } },
53
+ },
54
+ {
55
+ displayName: 'CSS',
56
+ name: 'css',
57
+ type: 'string',
58
+ default: '',
59
+ typeOptions: { rows: 4 },
60
+ displayOptions: { show: { resource: ['h2i'] } },
61
+ },
62
+ {
63
+ displayName: 'Width',
64
+ name: 'width',
65
+ type: 'number',
66
+ default: 1000,
67
+ displayOptions: { show: { resource: ['h2i'] } },
68
+ },
69
+ {
70
+ displayName: 'Height',
71
+ name: 'height',
72
+ type: 'number',
73
+ default: 1500,
74
+ displayOptions: { show: { resource: ['h2i'] } },
75
+ },
76
+ {
77
+ displayName: 'Format',
78
+ name: 'format',
79
+ type: 'options',
80
+ default: 'png',
81
+ options: [
82
+ { name: 'PNG', value: 'png' },
83
+ { name: 'JPEG', value: 'jpeg' },
84
+ ],
85
+ displayOptions: { show: { resource: ['h2i'] } },
86
+ },
87
+ {
88
+ displayName: 'Download Result as Binary',
89
+ name: 'downloadBinary',
90
+ type: 'boolean',
91
+ default: false,
92
+ displayOptions: { show: { resource: ['h2i'] } },
93
+ },
94
+ {
95
+ displayName: 'Output Binary Property',
96
+ name: 'outputBinaryProperty',
97
+ type: 'string',
98
+ default: 'data',
99
+ displayOptions: { show: { resource: ['h2i'], downloadBinary: [true] } },
100
+ },
101
+ // -------------------------
102
+ // Image
103
+ // -------------------------
104
+ {
105
+ displayName: 'Input Binary Properties',
106
+ name: 'imageBinaryProps',
107
+ type: 'string',
108
+ default: 'data',
109
+ placeholder: 'data OR image1,image2',
110
+ description: 'Comma-separated binary property names from previous nodes (each will be sent as an `images` file).',
111
+ displayOptions: { show: { resource: ['image'] } },
112
+ },
113
+ {
114
+ displayName: 'Format',
115
+ name: 'imageFormat',
116
+ type: 'options',
117
+ default: 'webp',
118
+ options: [
119
+ { name: 'JPEG', value: 'jpeg' },
120
+ { name: 'PNG', value: 'png' },
121
+ { name: 'WebP', value: 'webp' },
122
+ { name: 'AVIF', value: 'avif' },
123
+ { name: 'GIF', value: 'gif' },
124
+ { name: 'SVG', value: 'svg' },
125
+ { name: 'PDF', value: 'pdf' },
126
+ ],
127
+ displayOptions: { show: { resource: ['image'] } },
128
+ },
129
+ { displayName: 'Width', name: 'imageWidth', type: 'number', default: 0, displayOptions: { show: { resource: ['image'] } } },
130
+ { displayName: 'Height', name: 'imageHeight', type: 'number', default: 0, displayOptions: { show: { resource: ['image'] } } },
131
+ { displayName: 'Enlarge', name: 'enlarge', type: 'boolean', default: false, displayOptions: { show: { resource: ['image'] } } },
132
+ { displayName: 'Crop X', name: 'cropX', type: 'number', default: 0, displayOptions: { show: { resource: ['image'] } } },
133
+ { displayName: 'Crop Y', name: 'cropY', type: 'number', default: 0, displayOptions: { show: { resource: ['image'] } } },
134
+ { displayName: 'Crop Width', name: 'cropWidth', type: 'number', default: 0, displayOptions: { show: { resource: ['image'] } } },
135
+ { displayName: 'Crop Height', name: 'cropHeight', type: 'number', default: 0, displayOptions: { show: { resource: ['image'] } } },
136
+ { displayName: 'Rotate (degrees)', name: 'rotate', type: 'number', default: 0, displayOptions: { show: { resource: ['image'] } } },
137
+ { displayName: 'Flip Horizontal', name: 'flipH', type: 'boolean', default: false, displayOptions: { show: { resource: ['image'] } } },
138
+ { displayName: 'Flip Vertical', name: 'flipV', type: 'boolean', default: false, displayOptions: { show: { resource: ['image'] } } },
139
+ { displayName: 'Target Size (KB)', name: 'targetSizeKB', type: 'number', default: 0, displayOptions: { show: { resource: ['image'] } } },
140
+ { displayName: 'Quality', name: 'quality', type: 'number', default: 82, displayOptions: { show: { resource: ['image'] } } },
141
+ { displayName: 'Keep Metadata', name: 'keepMetadata', type: 'boolean', default: false, displayOptions: { show: { resource: ['image'] } } },
142
+ // PDF-only options
143
+ {
144
+ displayName: 'PDF Mode',
145
+ name: 'pdfMode',
146
+ type: 'options',
147
+ default: 'single',
148
+ options: [
149
+ { name: 'Single', value: 'single' },
150
+ { name: 'Multi', value: 'multi' },
151
+ ],
152
+ displayOptions: { show: { resource: ['image'], imageFormat: ['pdf'] } },
153
+ },
154
+ {
155
+ displayName: 'PDF Page Size',
156
+ name: 'pdfPageSize',
157
+ type: 'options',
158
+ default: 'auto',
159
+ options: [
160
+ { name: 'Auto', value: 'auto' },
161
+ { name: 'A4', value: 'a4' },
162
+ { name: 'Letter', value: 'letter' },
163
+ ],
164
+ displayOptions: { show: { resource: ['image'], imageFormat: ['pdf'] } },
165
+ },
166
+ {
167
+ displayName: 'PDF Orientation',
168
+ name: 'pdfOrientation',
169
+ type: 'options',
170
+ default: 'portrait',
171
+ options: [
172
+ { name: 'Portrait', value: 'portrait' },
173
+ { name: 'Landscape', value: 'landscape' },
174
+ ],
175
+ displayOptions: { show: { resource: ['image'], imageFormat: ['pdf'] } },
176
+ },
177
+ {
178
+ displayName: 'PDF Margin',
179
+ name: 'pdfMargin',
180
+ type: 'number',
181
+ default: 0,
182
+ displayOptions: { show: { resource: ['image'], imageFormat: ['pdf'] } },
183
+ },
184
+ {
185
+ displayName: 'PDF Embed Format',
186
+ name: 'pdfEmbedFormat',
187
+ type: 'options',
188
+ default: 'png',
189
+ options: [
190
+ { name: 'PNG', value: 'png' },
191
+ { name: 'JPEG', value: 'jpeg' },
192
+ ],
193
+ displayOptions: { show: { resource: ['image'], imageFormat: ['pdf'] } },
194
+ },
195
+ {
196
+ displayName: 'PDF JPEG Quality',
197
+ name: 'pdfJpegQuality',
198
+ type: 'number',
199
+ default: 85,
200
+ displayOptions: { show: { resource: ['image'], imageFormat: ['pdf'] } },
201
+ },
202
+ {
203
+ displayName: 'Download Result(s) as Binary',
204
+ name: 'imageDownloadBinary',
205
+ type: 'boolean',
206
+ default: false,
207
+ displayOptions: { show: { resource: ['image'] } },
208
+ },
209
+ {
210
+ displayName: 'Output Binary Property',
211
+ name: 'imageOutputBinaryProperty',
212
+ type: 'string',
213
+ default: 'data',
214
+ displayOptions: { show: { resource: ['image'], imageDownloadBinary: [true] } },
215
+ },
216
+ // -------------------------
217
+ // PDF
218
+ // -------------------------
219
+ {
220
+ displayName: 'Action',
221
+ name: 'pdfAction',
222
+ type: 'options',
223
+ default: 'merge',
224
+ options: [
225
+ { name: 'Merge', value: 'merge' },
226
+ { name: 'Split', value: 'split' },
227
+ { name: 'Compress', value: 'compress' },
228
+ { name: 'To Images', value: 'to-images' },
229
+ { name: 'Extract Images', value: 'extract-images' },
230
+ ],
231
+ displayOptions: { show: { resource: ['pdf'] } },
232
+ },
233
+ {
234
+ displayName: 'Input Binary Properties',
235
+ name: 'pdfBinaryProps',
236
+ type: 'string',
237
+ default: 'data',
238
+ placeholder: 'data OR pdf1,pdf2',
239
+ description: 'Comma-separated binary property names (each will be sent as a `files` PDF). For merge, provide multiple.',
240
+ displayOptions: { show: { resource: ['pdf'] } },
241
+ },
242
+ {
243
+ displayName: 'Sort By Name',
244
+ name: 'sortByName',
245
+ type: 'boolean',
246
+ default: false,
247
+ displayOptions: { show: { resource: ['pdf'], pdfAction: ['merge'] } },
248
+ },
249
+ {
250
+ displayName: 'Ranges',
251
+ name: 'ranges',
252
+ type: 'string',
253
+ default: '',
254
+ placeholder: '1-3,4-5',
255
+ displayOptions: { show: { resource: ['pdf'], pdfAction: ['split'] } },
256
+ },
257
+ {
258
+ displayName: 'Prefix',
259
+ name: 'prefix',
260
+ type: 'string',
261
+ default: 'split_',
262
+ displayOptions: { show: { resource: ['pdf'], pdfAction: ['split'] } },
263
+ },
264
+ {
265
+ displayName: 'Pages',
266
+ name: 'pages',
267
+ type: 'string',
268
+ default: 'all',
269
+ placeholder: 'all OR 1-3,5,7',
270
+ displayOptions: { show: { resource: ['pdf'], pdfAction: ['to-images', 'extract-images'] } },
271
+ },
272
+ {
273
+ displayName: 'To Format',
274
+ name: 'toFormat',
275
+ type: 'options',
276
+ default: 'png',
277
+ options: [
278
+ { name: 'PNG', value: 'png' },
279
+ { name: 'JPEG', value: 'jpeg' },
280
+ { name: 'WebP', value: 'webp' },
281
+ ],
282
+ displayOptions: { show: { resource: ['pdf'], pdfAction: ['to-images'] } },
283
+ },
284
+ { displayName: 'Width', name: 'pdfWidth', type: 'number', default: 0, displayOptions: { show: { resource: ['pdf'], pdfAction: ['to-images'] } } },
285
+ { displayName: 'Height', name: 'pdfHeight', type: 'number', default: 0, displayOptions: { show: { resource: ['pdf'], pdfAction: ['to-images'] } } },
286
+ { displayName: 'DPI', name: 'dpi', type: 'number', default: 150, displayOptions: { show: { resource: ['pdf'], pdfAction: ['to-images'] } } },
287
+ {
288
+ displayName: 'Extract Image Format',
289
+ name: 'imageFormat',
290
+ type: 'options',
291
+ default: 'png',
292
+ options: [
293
+ { name: 'PNG', value: 'png' },
294
+ { name: 'JPEG', value: 'jpeg' },
295
+ { name: 'WebP', value: 'webp' },
296
+ ],
297
+ displayOptions: { show: { resource: ['pdf'], pdfAction: ['extract-images'] } },
298
+ },
299
+ {
300
+ displayName: 'Download Result(s) as Binary',
301
+ name: 'pdfDownloadBinary',
302
+ type: 'boolean',
303
+ default: false,
304
+ displayOptions: { show: { resource: ['pdf'] } },
305
+ },
306
+ {
307
+ displayName: 'Output Binary Property',
308
+ name: 'pdfOutputBinaryProperty',
309
+ type: 'string',
310
+ default: 'data',
311
+ displayOptions: { show: { resource: ['pdf'], pdfDownloadBinary: [true] } },
312
+ },
313
+ // -------------------------
314
+ // Tools
315
+ // -------------------------
316
+ {
317
+ displayName: 'Input Binary Properties',
318
+ name: 'toolsBinaryProps',
319
+ type: 'string',
320
+ default: 'data',
321
+ placeholder: 'data OR img1,img2',
322
+ description: 'Comma-separated binary property names (each will be sent as an `images` file).',
323
+ displayOptions: { show: { resource: ['tools'] } },
324
+ },
325
+ {
326
+ displayName: 'Tools',
327
+ name: 'tools',
328
+ type: 'multiOptions',
329
+ default: ['metadata'],
330
+ options: [
331
+ { name: 'Metadata', value: 'metadata' },
332
+ { name: 'Colors', value: 'colors' },
333
+ { name: 'Detect Format', value: 'detect-format' },
334
+ { name: 'Orientation', value: 'orientation' },
335
+ { name: 'Hash', value: 'hash' },
336
+ ],
337
+ displayOptions: { show: { resource: ['tools'] } },
338
+ },
339
+ { displayName: 'Include Raw EXIF', name: 'includeRawExif', type: 'boolean', default: false, displayOptions: { show: { resource: ['tools'] } } },
340
+ { displayName: 'Palette Size', name: 'paletteSize', type: 'number', default: 5, displayOptions: { show: { resource: ['tools'] } } },
341
+ {
342
+ displayName: 'Hash Type',
343
+ name: 'hashType',
344
+ type: 'options',
345
+ default: 'phash',
346
+ options: [
347
+ { name: 'pHash', value: 'phash' },
348
+ { name: 'MD5', value: 'md5' },
349
+ { name: 'SHA1', value: 'sha1' },
350
+ ],
351
+ displayOptions: { show: { resource: ['tools'] } },
352
+ },
353
+ ],
354
+ };
355
+ async execute() {
356
+ const items = this.getInputData();
357
+ const out = [];
358
+ for (let itemIndex = 0; itemIndex < items.length; itemIndex++) {
359
+ const resource = this.getNodeParameter('resource', itemIndex);
360
+ // ---- H2I (JSON)
361
+ if (resource === 'h2i') {
362
+ const body = {
363
+ html: this.getNodeParameter('html', itemIndex),
364
+ css: this.getNodeParameter('css', itemIndex),
365
+ width: this.getNodeParameter('width', itemIndex),
366
+ height: this.getNodeParameter('height', itemIndex),
367
+ format: this.getNodeParameter('format', itemIndex),
368
+ };
369
+ const response = await GenericFunctions_1.davixRequest.call(this, {
370
+ method: 'POST',
371
+ url: '/v1/h2i',
372
+ json: true,
373
+ body,
374
+ });
375
+ const downloadBinary = this.getNodeParameter('downloadBinary', itemIndex);
376
+ if (downloadBinary && typeof response.url === 'string') {
377
+ const binName = this.getNodeParameter('outputBinaryProperty', itemIndex);
378
+ const dl = await GenericFunctions_1.downloadToBinary.call(this, response.url, `h2i.${body.format === 'jpeg' ? 'jpg' : 'png'}`);
379
+ const binary = await this.helpers.prepareBinaryData(dl.data, dl.fileName, dl.mimeType);
380
+ out.push({ json: response, binary: { [binName]: binary } });
381
+ }
382
+ else {
383
+ out.push({ json: response });
384
+ }
385
+ continue;
386
+ }
387
+ // Helper to attach multiple binaries as files
388
+ const attachFiles = async (fieldName, propList, formData) => {
389
+ const names = propList.split(',').map((s) => s.trim()).filter(Boolean);
390
+ if (names.length === 0)
391
+ throw new Error('No binary property names provided.');
392
+ for (const name of names) {
393
+ const buffer = await this.helpers.getBinaryDataBuffer(itemIndex, name);
394
+ const meta = items[itemIndex].binary?.[name];
395
+ const fileName = meta?.fileName ?? `${fieldName}-${name}`;
396
+ const mimeType = meta?.mimeType;
397
+ // n8n request helper supports this shape for multipart file upload
398
+ formData[fieldName] = formData[fieldName] || [];
399
+ formData[fieldName].push({
400
+ value: buffer,
401
+ options: {
402
+ filename: fileName,
403
+ contentType: mimeType,
404
+ },
405
+ });
406
+ }
407
+ };
408
+ // ---- IMAGE (multipart)
409
+ if (resource === 'image') {
410
+ const imageBinaryProps = this.getNodeParameter('imageBinaryProps', itemIndex);
411
+ const format = this.getNodeParameter('imageFormat', itemIndex);
412
+ const formData = {};
413
+ await attachFiles('images', imageBinaryProps, formData);
414
+ // core params
415
+ formData.format = format;
416
+ const w = this.getNodeParameter('imageWidth', itemIndex);
417
+ const h = this.getNodeParameter('imageHeight', itemIndex);
418
+ if (w)
419
+ formData.width = String(w);
420
+ if (h)
421
+ formData.height = String(h);
422
+ formData.enlarge = toBoolString(this.getNodeParameter('enlarge', itemIndex));
423
+ formData.rotate = String(this.getNodeParameter('rotate', itemIndex));
424
+ formData.flipH = toBoolString(this.getNodeParameter('flipH', itemIndex));
425
+ formData.flipV = toBoolString(this.getNodeParameter('flipV', itemIndex));
426
+ const cropX = this.getNodeParameter('cropX', itemIndex);
427
+ const cropY = this.getNodeParameter('cropY', itemIndex);
428
+ const cropWidth = this.getNodeParameter('cropWidth', itemIndex);
429
+ const cropHeight = this.getNodeParameter('cropHeight', itemIndex);
430
+ if (cropWidth && cropHeight) {
431
+ formData.cropX = String(cropX);
432
+ formData.cropY = String(cropY);
433
+ formData.cropWidth = String(cropWidth);
434
+ formData.cropHeight = String(cropHeight);
435
+ }
436
+ const targetSizeKB = this.getNodeParameter('targetSizeKB', itemIndex);
437
+ if (targetSizeKB)
438
+ formData.targetSizeKB = String(targetSizeKB);
439
+ formData.quality = String(this.getNodeParameter('quality', itemIndex));
440
+ formData.keepMetadata = toBoolString(this.getNodeParameter('keepMetadata', itemIndex));
441
+ // pdf-only params
442
+ if (format === 'pdf') {
443
+ formData.pdfMode = this.getNodeParameter('pdfMode', itemIndex);
444
+ formData.pdfPageSize = this.getNodeParameter('pdfPageSize', itemIndex);
445
+ formData.pdfOrientation = this.getNodeParameter('pdfOrientation', itemIndex);
446
+ formData.pdfMargin = String(this.getNodeParameter('pdfMargin', itemIndex));
447
+ formData.pdfEmbedFormat = this.getNodeParameter('pdfEmbedFormat', itemIndex);
448
+ formData.pdfJpegQuality = String(this.getNodeParameter('pdfJpegQuality', itemIndex));
449
+ }
450
+ const response = await GenericFunctions_1.davixRequest.call(this, {
451
+ method: 'POST',
452
+ url: '/v1/image',
453
+ formData,
454
+ json: true,
455
+ });
456
+ // optional download
457
+ const downloadBinary = this.getNodeParameter('imageDownloadBinary', itemIndex);
458
+ if (downloadBinary) {
459
+ const binName = this.getNodeParameter('imageOutputBinaryProperty', itemIndex);
460
+ // PixLab returns either url or results[] with urls (depending on implementation),
461
+ // so we support both.
462
+ const urls = [];
463
+ if (typeof response.url === 'string')
464
+ urls.push(response.url);
465
+ if (Array.isArray(response.results)) {
466
+ for (const r of response.results) {
467
+ if (r?.url)
468
+ urls.push(String(r.url));
469
+ }
470
+ }
471
+ if (urls.length) {
472
+ const firstUrl = urls[0];
473
+ const ext = format === 'jpeg' ? 'jpg' : format;
474
+ const dl = await GenericFunctions_1.downloadToBinary.call(this, firstUrl, `pixlab-image.${ext}`);
475
+ const binary = await this.helpers.prepareBinaryData(dl.data, dl.fileName, dl.mimeType);
476
+ out.push({ json: response, binary: { [binName]: binary } });
477
+ }
478
+ else {
479
+ out.push({ json: response });
480
+ }
481
+ }
482
+ else {
483
+ out.push({ json: response });
484
+ }
485
+ continue;
486
+ }
487
+ // ---- PDF (multipart)
488
+ if (resource === 'pdf') {
489
+ const action = this.getNodeParameter('pdfAction', itemIndex);
490
+ const pdfBinaryProps = this.getNodeParameter('pdfBinaryProps', itemIndex);
491
+ const formData = {};
492
+ await attachFiles('files', pdfBinaryProps, formData);
493
+ formData.action = action;
494
+ if (action === 'merge') {
495
+ formData.sortByName = toBoolString(this.getNodeParameter('sortByName', itemIndex));
496
+ }
497
+ if (action === 'split') {
498
+ formData.ranges = this.getNodeParameter('ranges', itemIndex);
499
+ formData.prefix = this.getNodeParameter('prefix', itemIndex);
500
+ }
501
+ if (action === 'to-images') {
502
+ formData.pages = this.getNodeParameter('pages', itemIndex);
503
+ formData.toFormat = this.getNodeParameter('toFormat', itemIndex);
504
+ const w = this.getNodeParameter('pdfWidth', itemIndex);
505
+ const h = this.getNodeParameter('pdfHeight', itemIndex);
506
+ if (w)
507
+ formData.width = String(w);
508
+ if (h)
509
+ formData.height = String(h);
510
+ formData.dpi = String(this.getNodeParameter('dpi', itemIndex));
511
+ }
512
+ if (action === 'extract-images') {
513
+ formData.pages = this.getNodeParameter('pages', itemIndex);
514
+ formData.imageFormat = this.getNodeParameter('imageFormat', itemIndex);
515
+ }
516
+ const response = await GenericFunctions_1.davixRequest.call(this, {
517
+ method: 'POST',
518
+ url: '/v1/pdf',
519
+ formData,
520
+ json: true,
521
+ });
522
+ const downloadBinary = this.getNodeParameter('pdfDownloadBinary', itemIndex);
523
+ if (downloadBinary) {
524
+ const binName = this.getNodeParameter('pdfOutputBinaryProperty', itemIndex);
525
+ const urls = [];
526
+ if (typeof response.url === 'string')
527
+ urls.push(response.url);
528
+ if (Array.isArray(response.results)) {
529
+ for (const r of response.results) {
530
+ if (r?.url)
531
+ urls.push(String(r.url));
532
+ }
533
+ }
534
+ if (urls.length) {
535
+ const firstUrl = urls[0];
536
+ const dl = await GenericFunctions_1.downloadToBinary.call(this, firstUrl, `pixlab-pdf-result.bin`);
537
+ const binary = await this.helpers.prepareBinaryData(dl.data, dl.fileName, dl.mimeType);
538
+ out.push({ json: response, binary: { [binName]: binary } });
539
+ }
540
+ else {
541
+ out.push({ json: response });
542
+ }
543
+ }
544
+ else {
545
+ out.push({ json: response });
546
+ }
547
+ continue;
548
+ }
549
+ // ---- TOOLS (multipart)
550
+ if (resource === 'tools') {
551
+ const toolsBinaryProps = this.getNodeParameter('toolsBinaryProps', itemIndex);
552
+ const formData = {};
553
+ await attachFiles('images', toolsBinaryProps, formData);
554
+ const tools = this.getNodeParameter('tools', itemIndex);
555
+ formData.tools = tools.join(',');
556
+ formData.includeRawExif = toBoolString(this.getNodeParameter('includeRawExif', itemIndex));
557
+ formData.paletteSize = String(this.getNodeParameter('paletteSize', itemIndex));
558
+ formData.hashType = this.getNodeParameter('hashType', itemIndex);
559
+ const response = await GenericFunctions_1.davixRequest.call(this, {
560
+ method: 'POST',
561
+ url: '/v1/tools',
562
+ formData,
563
+ json: true,
564
+ });
565
+ out.push({ json: response });
566
+ continue;
567
+ }
568
+ }
569
+ return [out];
570
+ }
571
+ }
572
+ exports.DavixH2I = DavixH2I;
@@ -0,0 +1,7 @@
1
+ import type { IDataObject, IExecuteFunctions, IHttpRequestOptions } from 'n8n-workflow';
2
+ export declare function davixRequest(this: IExecuteFunctions, options: IHttpRequestOptions): Promise<IDataObject>;
3
+ export declare function downloadToBinary(this: IExecuteFunctions, url: string, fileName: string): Promise<{
4
+ data: Buffer;
5
+ fileName: string;
6
+ mimeType?: string;
7
+ }>;
@@ -0,0 +1,37 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.davixRequest = davixRequest;
4
+ exports.downloadToBinary = downloadToBinary;
5
+ function stripTrailingSlash(url) {
6
+ return url.endsWith('/') ? url.slice(0, -1) : url;
7
+ }
8
+ async function davixRequest(options) {
9
+ const creds = await this.getCredentials('davixH2IApi');
10
+ const baseUrl = stripTrailingSlash(String(creds.baseUrl || ''));
11
+ const apiKey = String(creds.apiKey || '');
12
+ if (!baseUrl)
13
+ throw new Error('Missing Base URL in credentials.');
14
+ if (!apiKey)
15
+ throw new Error('Missing API Key in credentials.');
16
+ const requestOptions = {
17
+ ...options,
18
+ url: `${baseUrl}${options.url}`,
19
+ headers: {
20
+ ...(options.headers || {}),
21
+ // PixLab accepts x-api-key
22
+ 'x-api-key': apiKey,
23
+ },
24
+ };
25
+ return await this.helpers.request(requestOptions);
26
+ }
27
+ async function downloadToBinary(url, fileName) {
28
+ const res = await this.helpers.request({
29
+ method: 'GET',
30
+ url,
31
+ encoding: null, // IMPORTANT: Buffer
32
+ resolveWithFullResponse: true,
33
+ });
34
+ const body = res.body;
35
+ const mimeType = res.headers?.['content-type'] || undefined;
36
+ return { data: body, fileName, mimeType };
37
+ }