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

fixes(#1283): Add documentation for Multer functions #1284

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

Conversation

arham-sayyed
Copy link

@arham-sayyed arham-sayyed commented Nov 11, 2024

PR Title:

docs: Add documentation for Multer functions

fixes: #1283

#1283

Description:

This pull request adds comprehensive documentation for various Multer functions, improving code readability and helping developers understand the purpose and usage of each function. The following functions have been documented:

  • allowAll
  • Multer.prototype.single
  • Multer.prototype.array
  • Multer.prototype.fields
  • Multer.prototype.none
  • Multer.prototype.any
  • Multer.prototype._makeMiddleware
  • wrappedFileFilter

These additions aim to enhance the clarity of the codebase and provide better insight into the functionality of the Multer library.

Changes:

  • Added JSDoc comments for all relevant functions.
  • Provided detailed descriptions of each function's behavior and parameters.
  • Improved inline documentation to support better developer experience.

Motivation and Context:

Clear documentation helps developers understand how to use the Multer library effectively. This PR aims to improve the usability and maintainability of the code.

Type of Change:

  • Documentation update.

How to Test:

No testing required, as this is purely a documentation update. Review the code for clarity and accuracy of the added comments.

* @param {Object} req - The HTTP request object.
* @param {Object} file - The file object containing file details such as `fieldname`, `originalname`, `encoding`, and `mimetype`.
* @param {Function} cb - A callback function that takes two arguments:
* - `err` (Error, if any, or `null` to allow the file)
Copy link
Member

@IamLizu IamLizu Dec 26, 2024

Choose a reason for hiding this comment

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

@arham-sayyed hey 👋

Can you please help me understand this line (13) according the code written in the function?

Copy link
Author

Choose a reason for hiding this comment

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

Hey 👋

Sure! Let me explain line 13:

 * - `err` (Error, if any, or `null` to allow the file)

This describes the first parameter of the callback function (cb) used in the allowAll function. The err parameter is intended to indicate if there's an error that should prevent the file from being processed.

  • If you pass null as the err value (as done in cb(null, true)), it means there's no error, and the file is allowed to proceed.
  • If you pass an Error object instead of null, it will stop the processing of that specific file and trigger an error in the file upload flow.

Essentially, this mechanism allows you to handle file validation or other conditions dynamically, depending on your use case. In this case, since allowAll is a default filter that accepts all files, we simply pass null for err to indicate no error. 😊

Let me know if you have any further questions!

@IamLizu
Copy link
Member

IamLizu commented Dec 27, 2024

This adds a lot of changes, in internal methods as well. While the work is appreciated, I suggest changing the PR to DRAFT so that we do not accidentally land it before its ready as there's so much jsDoc to review.

cc: @UlisesGascon

@arham-sayyed arham-sayyed requested a review from IamLizu January 4, 2025 11:28
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.

Improve Code Documentation for Enhanced IntelliSense Support
2 participants