Skip to content
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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

DmytroHoncharuk
Copy link

No description provided.

Copy link

@mateacademy-ai-mentor mateacademy-ai-mentor left a 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];

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}`);

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.

Comment on lines +98 to +100
if (!validCompressionTypes.includes(compressionType)) {
res.statusCode = 400;
res.end('Unsupported Compression Type');

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'}`;

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants