-
Notifications
You must be signed in to change notification settings - Fork 200
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
solution #142
base: master
Are you sure you want to change the base?
solution #142
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great job on implementing the task requirements! 🎉 The server and HTML form are well-structured and meet the core functionality needed. While there are some areas for improvement, such as simplifying the logic for determining file extensions and enhancing error messages, these are minor and don't impact the overall functionality. Consider using libraries like 'multiparty' or 'busboy' for more robust multipart form data handling in the future. Keep up the good work! 😊
✨ Please rate this review in the Platform's notification center. I will be grateful for your feedback! ✨
} | ||
|
||
if (req.method === 'POST' && req.url === '/compress') { | ||
const boundary = req.headers['content-type'].split('boundary=')[1]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The code assumes that the 'Content-Type' header will always contain a boundary. It would be more robust to check if the 'Content-Type' header exists before attempting to split it.
|
||
req.on('end', () => { | ||
const buffer = Buffer.concat(chunks); | ||
const parts = buffer.toString().split(`--${boundary}`); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Splitting the buffer by the boundary might not correctly handle the multipart form data if the boundary is not unique or if there are additional CRLF sequences. Consider using a library like 'multiparty' or 'busboy' to handle multipart form data parsing more reliably.
if (!validCompressionTypes.includes(compressionType)) { | ||
res.statusCode = 400; | ||
res.end('Unsupported Compression Type'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The error message 'Unsupported Compression Type' is returned for invalid compression types, but it might be helpful to include the supported types in the response to guide the user.
br: zlib.createBrotliCompress(), | ||
}; | ||
|
||
const compressedFileName = `${fileName}.${compressionType === 'gzip' ? 'gzip' : compressionType === 'deflate' ? 'deflate' : 'br'}`; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The logic for determining the file extension based on the compression type is correct, but it could be simplified by using a map similar to 'compressionMap' to avoid repetitive ternary operations.
No description provided.