@unito/integration-sdk 2.3.10 → 2.3.12
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.
- package/dist/src/handler.js +14 -6
- package/dist/src/index.cjs +14 -6
- package/package.json +1 -1
- package/src/handler.ts +19 -9
- package/src/index.ts +1 -0
package/dist/src/handler.js
CHANGED
|
@@ -137,17 +137,25 @@ export class Handler {
|
|
|
137
137
|
* This is why we need to use busboy to parse the form data, extract the information about the file and pass it to the handler.
|
|
138
138
|
*/
|
|
139
139
|
const bb = busboy({ headers: req.headers });
|
|
140
|
+
const formFields = {};
|
|
141
|
+
bb.on('field', (name, value) => {
|
|
142
|
+
formFields[name] = value;
|
|
143
|
+
});
|
|
140
144
|
bb.on('file', async (_name, file, info) => {
|
|
141
145
|
try {
|
|
146
|
+
const body = {
|
|
147
|
+
file: file,
|
|
148
|
+
mimeType: info.mimeType,
|
|
149
|
+
encoding: info.encoding,
|
|
150
|
+
filename: info.filename,
|
|
151
|
+
};
|
|
152
|
+
if (formFields.fileSize) {
|
|
153
|
+
body.fileSize = Number(formFields.fileSize);
|
|
154
|
+
}
|
|
142
155
|
const createdBlob = await handler({
|
|
143
156
|
credentials: res.locals.credentials,
|
|
144
157
|
secrets: res.locals.secrets,
|
|
145
|
-
body
|
|
146
|
-
file: file,
|
|
147
|
-
mimeType: info.mimeType,
|
|
148
|
-
encoding: info.encoding,
|
|
149
|
-
filename: info.filename,
|
|
150
|
-
},
|
|
158
|
+
body,
|
|
151
159
|
logger: res.locals.logger,
|
|
152
160
|
signal: res.locals.signal,
|
|
153
161
|
params: req.params,
|
package/dist/src/index.cjs
CHANGED
|
@@ -642,17 +642,25 @@ class Handler {
|
|
|
642
642
|
* This is why we need to use busboy to parse the form data, extract the information about the file and pass it to the handler.
|
|
643
643
|
*/
|
|
644
644
|
const bb = busboy({ headers: req.headers });
|
|
645
|
+
const formFields = {};
|
|
646
|
+
bb.on('field', (name, value) => {
|
|
647
|
+
formFields[name] = value;
|
|
648
|
+
});
|
|
645
649
|
bb.on('file', async (_name, file, info) => {
|
|
646
650
|
try {
|
|
651
|
+
const body = {
|
|
652
|
+
file: file,
|
|
653
|
+
mimeType: info.mimeType,
|
|
654
|
+
encoding: info.encoding,
|
|
655
|
+
filename: info.filename,
|
|
656
|
+
};
|
|
657
|
+
if (formFields.fileSize) {
|
|
658
|
+
body.fileSize = Number(formFields.fileSize);
|
|
659
|
+
}
|
|
647
660
|
const createdBlob = await handler({
|
|
648
661
|
credentials: res.locals.credentials,
|
|
649
662
|
secrets: res.locals.secrets,
|
|
650
|
-
body
|
|
651
|
-
file: file,
|
|
652
|
-
mimeType: info.mimeType,
|
|
653
|
-
encoding: info.encoding,
|
|
654
|
-
filename: info.filename,
|
|
655
|
-
},
|
|
663
|
+
body,
|
|
656
664
|
logger: res.locals.logger,
|
|
657
665
|
signal: res.locals.signal,
|
|
658
666
|
params: req.params,
|
package/package.json
CHANGED
package/src/handler.ts
CHANGED
|
@@ -352,17 +352,29 @@ export class Handler {
|
|
|
352
352
|
* This is why we need to use busboy to parse the form data, extract the information about the file and pass it to the handler.
|
|
353
353
|
*/
|
|
354
354
|
const bb = busboy({ headers: req.headers });
|
|
355
|
+
const formFields: Record<string, string> = {};
|
|
356
|
+
|
|
357
|
+
bb.on('field', (name, value) => {
|
|
358
|
+
formFields[name] = value;
|
|
359
|
+
});
|
|
360
|
+
|
|
355
361
|
bb.on('file', async (_name, file, info: FileInfo) => {
|
|
356
362
|
try {
|
|
363
|
+
const body: API.CreateBlobRequestPayload = {
|
|
364
|
+
file: file,
|
|
365
|
+
mimeType: info.mimeType,
|
|
366
|
+
encoding: info.encoding,
|
|
367
|
+
filename: info.filename,
|
|
368
|
+
};
|
|
369
|
+
|
|
370
|
+
if (formFields.fileSize) {
|
|
371
|
+
body.fileSize = Number(formFields.fileSize);
|
|
372
|
+
}
|
|
373
|
+
|
|
357
374
|
const createdBlob = await handler({
|
|
358
375
|
credentials: res.locals.credentials,
|
|
359
376
|
secrets: res.locals.secrets,
|
|
360
|
-
body
|
|
361
|
-
file: file,
|
|
362
|
-
mimeType: info.mimeType,
|
|
363
|
-
encoding: info.encoding,
|
|
364
|
-
filename: info.filename,
|
|
365
|
-
},
|
|
377
|
+
body,
|
|
366
378
|
logger: res.locals.logger,
|
|
367
379
|
signal: res.locals.signal,
|
|
368
380
|
params: req.params,
|
|
@@ -371,17 +383,15 @@ export class Handler {
|
|
|
371
383
|
res.status(201).send(createdBlob);
|
|
372
384
|
} catch (error) {
|
|
373
385
|
if (error instanceof HttpError) {
|
|
374
|
-
res.status(
|
|
386
|
+
res.status(error.status).send(error);
|
|
375
387
|
} else {
|
|
376
388
|
res.status(500).send({ message: `Error creating the blob: ${error}` });
|
|
377
389
|
}
|
|
378
390
|
}
|
|
379
391
|
});
|
|
380
|
-
|
|
381
392
|
bb.on('error', error => {
|
|
382
393
|
res.status(500).send({ message: `Error parsing the form data: ${error}` });
|
|
383
394
|
});
|
|
384
|
-
|
|
385
395
|
req.pipe(bb);
|
|
386
396
|
});
|
|
387
397
|
}
|