-
Notifications
You must be signed in to change notification settings - Fork 133
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: sypress 500 error instead 400 in artifact
- Loading branch information
Ihar
committed
May 11, 2024
1 parent
8a0bbdc
commit 02a77e3
Showing
3 changed files
with
35 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,25 @@ | ||
import { MultipartFile as MultipartFileFastify} from '@fastify/multipart'; | ||
import { MultipartFile as MultipartFileFastify } from '@fastify/multipart'; | ||
|
||
//types and interfaces | ||
import { MultipartFile } from '../types/index.js'; | ||
|
||
export const getFileFromPart = async (part: MultipartFileFastify): Promise<MultipartFile> => { | ||
const buffer: Buffer = await part.toBuffer() | ||
export const getFileFromPart = async (part: MultipartFileFastify): Promise<MultipartFile | null> => { | ||
const buffer: Buffer = await part.toBuffer(); | ||
|
||
const { byteLength: size } = buffer; | ||
const { filename, mimetype, fieldname, encoding } = part; | ||
|
||
if (!size || !fieldname) { | ||
return null; | ||
} | ||
|
||
return { | ||
buffer, | ||
size: buffer.byteLength, | ||
filename: part.filename, | ||
mimetype: part.mimetype, | ||
fieldname: part.fieldname, | ||
encoding: part.encoding, | ||
originalname: part.fieldname | ||
size, | ||
filename, | ||
mimetype, | ||
fieldname, | ||
encoding, | ||
originalname: fieldname, | ||
}; | ||
}; |