Skip to content

Commit 595583e

Browse files
authored
add parts type and enable coverage checking (#491)
* add parts type * enable coverage check * test if flaky * Revert "test if flaky" This reverts commit 76388dd. * ignore line * add why we're ignoring else
1 parent 9ff3c28 commit 595583e

File tree

4 files changed

+16
-3
lines changed

4 files changed

+16
-3
lines changed

.taprc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
1-
check-coverage: false
21
files:
32
- test/**/*.test.js

index.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,8 @@ function fastifyMultipart (fastify, options, done) {
9494
const key = reqBodyKeys[i]
9595
const field = req.body[key]
9696

97+
/* Don't modify the body if a field doesn't have a value or an attached buffer */
98+
/* istanbul ignore else */
9799
if (field.value !== undefined) {
98100
body[key] = field.value
99101
} else if (field._buf) {
@@ -453,7 +455,8 @@ function fastifyMultipart (fastify, options, done) {
453455
try {
454456
await unlink(filepath)
455457
} catch (error) {
456-
this.log.error(error, 'could not delete file')
458+
/* istanbul ignore next */
459+
this.log.error(error, 'Could not delete file')
457460
}
458461
}
459462
}
@@ -462,6 +465,8 @@ function fastifyMultipart (fastify, options, done) {
462465
const parts = this[kMultipartHandler](options)
463466
let part
464467
while ((part = await parts()) != null) {
468+
/* Only return a part if the file property exists */
469+
/* istanbul ignore else */
465470
if (part.file) {
466471
return part
467472
}

types/index.d.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,12 @@ declare namespace fastifyMultipart {
158158
* Max number of header key=>value pairs
159159
*/
160160
headerPairs?: number;
161+
162+
/**
163+
* For multipart forms, the max number of parts (fields + files)
164+
* @default 1000
165+
*/
166+
parts?: number;
161167
};
162168
}
163169

types/index.test-d.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ const runServer = async () => {
1414

1515
app.register(fastifyMultipart, {
1616
attachFieldsToBody: true,
17+
limits: {
18+
parts: 500
19+
},
1720
onFile: (part: MultipartFile) => {
1821
console.log(part)
1922
}
@@ -73,7 +76,7 @@ const runServer = async () => {
7376

7477
// busboy
7578
app.post('/', async function (req, reply) {
76-
const options: Partial<BusboyConfig> = { limits: { fileSize: 1000 } }
79+
const options: Partial<BusboyConfig> = { limits: { fileSize: 1000, parts: 500 } }
7780
const data = await req.file(options)
7881
if (!data) throw new Error('missing file')
7982
await pump(data.file, fs.createWriteStream(data.filename))

0 commit comments

Comments
 (0)