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

Plugin return again #820

Merged
merged 2 commits into from
Feb 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
# Changelog


### 3.2.2

* refactor: ([#801](https://github.com/node-formidable/formidable/pull/801))

### 3.2.1


Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "formidable",
"version": "3.2.1",
"version": "3.2.2",
"license": "MIT",
"description": "A node.js module for parsing form data, especially file uploads.",
"homepage": "https://github.com/node-formidable/formidable",
Expand Down
10 changes: 7 additions & 3 deletions src/Formidable.js
Original file line number Diff line number Diff line change
Expand Up @@ -407,9 +407,11 @@ class IncomingForm extends EventEmitter {

new DummyParser(this, this.options);

this._plugins.forEach((plugin, idx) => {
const results = [];
this._plugins.forEach((plugin, idx) => {
let pluginReturn = null;
try {
plugin(this, this.options) || this;
pluginReturn = plugin(this, this.options) || this;
} catch (err) {
// directly throw from the `form.parse` method;
// there is no other better way, except a handle through options
Expand All @@ -421,10 +423,12 @@ class IncomingForm extends EventEmitter {
error.idx = idx;
throw error;
}
Object.assign(this, pluginReturn);

// todo: use Set/Map and pass plugin name instead of the `idx` index
this.emit('plugin', idx);
this.emit('plugin', idx, pluginReturn);
});
this.emit('pluginsResults', results);
}

_error(err, eventName = 'error') {
Expand Down
2 changes: 2 additions & 0 deletions src/plugins/json.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ export default function plugin(formidable, options) {
if (/json/i.test(self.headers['content-type'])) {
init.call(self, self, options);
}

return self;
};

// Note that it's a good practice (but it's up to you) to use the `this.options` instead
Expand Down
1 change: 1 addition & 0 deletions src/plugins/multipart.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export default function plugin(formidable, options) {
self._error(err);
}
}
return self;
}

// Note that it's a good practice (but it's up to you) to use the `this.options` instead
Expand Down
1 change: 1 addition & 0 deletions src/plugins/octetstream.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export default function plugin(formidable, options) {
if (/octet-stream/i.test(self.headers['content-type'])) {
init.call(self, self, options);
}
return self;
}

// Note that it's a good practice (but it's up to you) to use the `this.options` instead
Expand Down
1 change: 1 addition & 0 deletions src/plugins/querystring.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export default function plugin(formidable, options) {
if (/urlencoded/i.test(self.headers['content-type'])) {
init.call(self, self, options);
}
return self;
};

// Note that it's a good practice (but it's up to you) to use the `this.options` instead
Expand Down