vibe-gx 1.0.6 → 1.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/utils/core/parser.js +23 -9
package/package.json
CHANGED
package/utils/core/parser.js
CHANGED
|
@@ -56,9 +56,22 @@ function parseMultipart(req, res, media, options, resolve, reject) {
|
|
|
56
56
|
const streaming = media.streaming === true;
|
|
57
57
|
let pendingWrites = 0;
|
|
58
58
|
let busboyFinished = false;
|
|
59
|
+
let alreadyRejected = false;
|
|
59
60
|
|
|
60
|
-
// Helper to
|
|
61
|
+
// Helper to reject immediately (for errors that shouldn't wait)
|
|
62
|
+
const rejectNow = (err) => {
|
|
63
|
+
if (alreadyRejected) return;
|
|
64
|
+
alreadyRejected = true;
|
|
65
|
+
// Unpipe to stop processing more data
|
|
66
|
+
req.unpipe(bb);
|
|
67
|
+
// Drain the request to prevent hanging
|
|
68
|
+
req.resume();
|
|
69
|
+
reject(err);
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
// Helper to check if we're done (for normal completion)
|
|
61
73
|
const checkComplete = () => {
|
|
74
|
+
if (alreadyRejected) return;
|
|
62
75
|
if (busboyFinished && pendingWrites === 0) {
|
|
63
76
|
if (fileError) {
|
|
64
77
|
reject(fileError);
|
|
@@ -97,10 +110,12 @@ function parseMultipart(req, res, media, options, resolve, reject) {
|
|
|
97
110
|
return allowed === mimeType;
|
|
98
111
|
});
|
|
99
112
|
if (!isAllowed) {
|
|
100
|
-
|
|
101
|
-
|
|
113
|
+
file.resume();
|
|
114
|
+
return rejectNow(
|
|
115
|
+
new Error(
|
|
116
|
+
`File type '${mimeType}' not allowed. Allowed: ${media.allowedTypes.join(", ")}`,
|
|
117
|
+
),
|
|
102
118
|
);
|
|
103
|
-
return file.resume();
|
|
104
119
|
}
|
|
105
120
|
}
|
|
106
121
|
|
|
@@ -156,19 +171,18 @@ function parseMultipart(req, res, media, options, resolve, reject) {
|
|
|
156
171
|
// Handle file size limit exceeded
|
|
157
172
|
file.on("limit", () => {
|
|
158
173
|
truncated = true;
|
|
159
|
-
|
|
174
|
+
const err = new Error(
|
|
160
175
|
`File '${filename}' exceeds max size of ${media.maxSize || 10 * 1024 * 1024} bytes`,
|
|
161
176
|
);
|
|
162
177
|
file.unpipe(writeStream);
|
|
163
178
|
writeStream.end();
|
|
164
|
-
// IMPORTANT: Resume the file stream to drain remaining data
|
|
165
|
-
// This allows busboy to finish parsing the multipart request
|
|
166
179
|
file.resume();
|
|
167
|
-
// Clean up partial file
|
|
180
|
+
// Clean up partial file and reject immediately
|
|
168
181
|
fs.unlink(filePath, () => {
|
|
169
182
|
pendingWrites--;
|
|
170
|
-
checkComplete();
|
|
171
183
|
});
|
|
184
|
+
// Reject NOW - don't wait for busboy to finish
|
|
185
|
+
rejectNow(err);
|
|
172
186
|
});
|
|
173
187
|
|
|
174
188
|
file.on("error", (err) => {
|