Skip to content

solution#230

Open
dmdamyan wants to merge 2 commits intomate-academy:masterfrom
dmdamyan:develop
Open

solution#230
dmdamyan wants to merge 2 commits intomate-academy:masterfrom
dmdamyan:develop

Conversation

@dmdamyan
Copy link
Copy Markdown

No description provided.

Copy link
Copy Markdown

@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.

Review Summary

I am approving your solution because it correctly implements the required server behavior: GET / serves the index HTML, POST /compress uses streams plus zlib to compress uploads, GET /compress returns 400, and unknown routes return 404 as expected by the tests. The remaining points identified are improvements rather than blockers: relying on array-shaped formidable results (around lines 46–56) could be fragile if configuration changes, and quoting the filename in the Content-Disposition header would make downloads more robust for names with spaces or special characters. Similarly, switching the GET / index serving to use pipeline (and adding consistent error handling on stream failures) would make the code more resilient but does not break current functionality. None of these issues prevent the implementation from satisfying the task requirements or passing the tests. As a follow-up, I recommend you 1) either configure/document formidable to always return arrays or access files.file / fields.compressionType in a shape-agnostic way, 2) wrap the filename in Content-Disposition like attachment; filename="${fileName}${extension}", and 3) consider using pipeline for serving index.html to unify error handling. Overall, you’ve met the core functional and technical requirements; polishing these details will make your solution more robust in real-world scenarios.


✨ Please rate this review in the Platform's notification center1. I will be grateful for your feedback! ✨

Important

Fix the issues, commit the changes, and then re-request my review using the Re-request review button2 in the Reviewers tab.

Tip

If you have any comments about this review, please leave a message in the Add a comment section below and mention me with the @mateacademy-ai-mentor tag3.
I will read your message during my next review of your pull request. Please do not reply directly to my comments, as that feature is not supported yet.

Caution

Do not close the pull request until the review is complete. Closing it early can lead to unexpected behavior and disrupt the review process.

Footnotes

  1. Rate AI review example

  2. Re-request AI review example

  3. Add AI review comments example

Comment thread src/createServer.js Outdated
Comment on lines +23 to +34
const file = fs.createReadStream('public/index.html');

file.on('error', () => {
res.statusCode = 404;
res.end('No such file');
});

file.on('close', () => {
console.log('connection close');
file.destroy();
});
file.pipe(res);
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When serving the index HTML you create a read stream and pipe it to the response, but you never set an explicit error handler on the response stream for pipeline errors. Consider using pipeline for consistency (reads + piping) to ensure stream errors close the response properly.

Comment thread src/createServer.js
Comment on lines +46 to +56
if (!files.file?.[0] || !fields.compressionType?.[0]) {
res.statusCode = 400;
res.end();

return;
}

const uploadedFilePath = files.file[0].filepath;
const readStream = fs.createReadStream(uploadedFilePath);
const compressionType = fields.compressionType[0];
const fileName = files.file[0].originalFilename;
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Form parsing uses formidable and expects arrays (files.file[0], fields.compressionType[0]). This is fine only if formidable is configured to return arrays; default behavior may provide single values. Verify that the tests/invocation provide fields as arrays; otherwise access files.file and fields.compressionType directly. If you intend to rely on arrays, document or configure formidable accordingly.

Comment thread src/createServer.js
Comment on lines +86 to +89
res.setHeader(
'Content-Disposition',
`attachment; filename=${fileName}${extension}`,
);
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You set Content-Disposition header to attachment; filename=${fileName}${extension} without escaping or wrapping filename. If fileName contains spaces or special chars the header can become invalid. Wrap the filename in double quotes: attachment; filename="${fileName}${extension}".

Comment thread src/createServer.js Outdated
Comment on lines +19 to +34
if (method === 'GET' && path === '/') {
res.statusCode = 200;
res.setHeader('Content-Type', 'text/html');

const file = fs.createReadStream('public/index.html');

file.on('error', () => {
res.statusCode = 404;
res.end('No such file');
});

file.on('close', () => {
console.log('connection close');
file.destroy();
});
file.pipe(res);
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The server responds with 400 for GET /compress as required, and 404 for other endpoints — good. However, ensure public/index.html exists in the expected path; missing file produces 404 which is handled, but tests expect the root GET to return the HTML. If tests require synchronous file existence you may need to ensure that file is present in the project.

Copy link
Copy Markdown

@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.

Review Summary

I am approving your solution because it meets the core functional requirements and the tests now pass: GET / correctly responds with 200, POST /compress handles the multipart upload and compression with streams and zlib, and error paths return the expected 400/404 status codes. The overall structure of createServer.js is solid and uses pipeline appropriately for the compression flow.

There are a few non-blocking improvements you should consider: around lines 51, 58, 60, and 61 in src/createServer.js, you assume formidable returns arrays for files.file and fields.compressionType; to avoid false 400 responses in different configs, normalize these values (e.g., handle both single objects and arrays) before validation. Around lines 91–93, the Content-Disposition header should quote the filename (attachment; filename="${fileName}${extension}") so downloads work reliably with spaces or special characters. Finally, when serving public/index.html, you can simplify and harden error handling by relying on stream.pipeline’s callback instead of mixing separate stream event listeners with the pipeline, ensuring errors are handled in one place. Overall, the implementation is correct and robust enough for the task, and these suggestions will help make it more production-friendly.


✨ Please rate this review in the Platform's notification center1. I will be grateful for your feedback! ✨

Important

Fix the issues, commit the changes, and then re-request my review using the Re-request review button2 in the Reviewers tab.

Tip

If you have any comments about this review, please leave a message in the Add a comment section below and mention me with the @mateacademy-ai-mentor tag3.
I will read your message during my next review of your pull request. Please do not reply directly to my comments, as that feature is not supported yet.

Caution

Do not close the pull request until the review is complete. Closing it early can lead to unexpected behavior and disrupt the review process.

Footnotes

  1. Rate AI review example

  2. Re-request AI review example

  3. Add AI review comments example

Comment thread src/createServer.js
Comment on lines +51 to +61
if (!files.file?.[0] || !fields.compressionType?.[0]) {
res.statusCode = 400;
res.end();

return;
}

const uploadedFilePath = files.file[0].filepath;
const readStream = fs.createReadStream(uploadedFilePath);
const compressionType = fields.compressionType[0];
const fileName = files.file[0].originalFilename;
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using array indexing for files.file and fields.compressionType assumes formidable returns arrays. This is brittle if formidable configuration changes — access values in a shape-agnostic way (e.g., handle both arrays and single values) or configure/document formidable to always return arrays. This relates to requirements to validate the form and could cause false 400 responses. (Around lines 51, 58, 60, 61)

Comment thread src/createServer.js
Comment on lines +91 to +93
res.setHeader(
'Content-Disposition',
`attachment; filename=${fileName}${extension}`,
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Content-Disposition header uses an unquoted filename. Filenames containing spaces or special characters may break downloads. Wrap the filename in quotes like attachment; filename="${fileName}${extension}". (lines 91-93)

Comment thread src/createServer.js
Comment on lines +23 to +35
const file = fs.createReadStream('public/index.html');

file.on('error', () => {
res.statusCode = 404;
res.end('No such file');
});

file.on('close', () => {
console.log('connection close');
file.destroy();
});

pipeline(file, res, (err) => {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The server serves public/index.html with a read stream but handles stream errors with an event listener plus pipeline callback. Consider using pipeline exclusively (and handling its error) to make the flow more robust and avoid double handling; at minimum, ensure the file.on('close') handler won't conflict with pipeline. This is an improvement suggestion rather than a task-blocking bug. (lines 23, 25, 30, 35)

Copy link
Copy Markdown

@vadiimvooo vadiimvooo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well done

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.

3 participants