-
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
add solution #140
base: master
Are you sure you want to change the base?
add solution #140
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 server and HTML form! 🎉 While there are minor issues with the assumption that compressionType
and file
are arrays, the overall functionality meets the task requirements. Keep up the good work and consider verifying the data structure to enhance robustness in future projects. 😊
✨ Please rate this review in the Platform's notification center. I will be grateful for your feedback! ✨
if (req.method === 'POST' && pathname === '/compress') { | ||
const form = new formidable.IncomingForm(); | ||
|
||
form.parse(req, (error, { compressionType }, { file }) => { |
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 compressionType
and file
are accessed as arrays (e.g., compressionType[0]
and file[0]
). Ensure that these variables are indeed arrays. If they are not, you should access them directly without indexing.
return; | ||
} | ||
|
||
if (!['gzip', 'deflate', 'br'].includes(compressionType[0])) { |
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 check for compressionType[0]
assumes compressionType
is an array. Verify that compressionType
is an array. If not, adjust the code to handle it correctly.
|
||
res.setHeader( | ||
'Content-Disposition', | ||
`attachment; filename=${file[0].originalFilename}.${compressionType[0]}`, |
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 file[0].originalFilename
assumes file
is an array. Ensure that file
is indeed an array. If not, adjust the code to access the filename correctly.
`attachment; filename=${file[0].originalFilename}.${compressionType[0]}`, | ||
); | ||
|
||
const fileStream = fs.createReadStream(file[0].filepath); |
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 file[0].filepath
assumes file
is an array. Verify that file
is an array. If not, adjust the code to access the filepath correctly.
No description provided.