@bepalo/router 1.0.3
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/LICENSE +21 -0
- package/README.md +557 -0
- package/dist/cjs/helpers.d.ts +290 -0
- package/dist/cjs/helpers.d.ts.map +1 -0
- package/dist/cjs/helpers.js +691 -0
- package/dist/cjs/helpers.js.map +1 -0
- package/dist/cjs/index.d.ts +5 -0
- package/dist/cjs/index.d.ts.map +1 -0
- package/dist/cjs/index.js +21 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/list.d.ts +166 -0
- package/dist/cjs/list.d.ts.map +1 -0
- package/dist/cjs/list.js +483 -0
- package/dist/cjs/list.js.map +1 -0
- package/dist/cjs/middlewares.d.ts +251 -0
- package/dist/cjs/middlewares.d.ts.map +1 -0
- package/dist/cjs/middlewares.js +359 -0
- package/dist/cjs/middlewares.js.map +1 -0
- package/dist/cjs/router.d.ts +333 -0
- package/dist/cjs/router.d.ts.map +1 -0
- package/dist/cjs/router.js +659 -0
- package/dist/cjs/router.js.map +1 -0
- package/dist/cjs/tree.d.ts +18 -0
- package/dist/cjs/tree.d.ts.map +1 -0
- package/dist/cjs/tree.js +162 -0
- package/dist/cjs/tree.js.map +1 -0
- package/dist/cjs/types.d.ts +127 -0
- package/dist/cjs/types.d.ts.map +1 -0
- package/dist/cjs/types.js +3 -0
- package/dist/cjs/types.js.map +1 -0
- package/dist/cjs/upload-stream.d.ts +105 -0
- package/dist/cjs/upload-stream.d.ts.map +1 -0
- package/dist/cjs/upload-stream.js +417 -0
- package/dist/cjs/upload-stream.js.map +1 -0
- package/dist/helpers.d.ts +290 -0
- package/dist/helpers.d.ts.map +1 -0
- package/dist/helpers.js +691 -0
- package/dist/helpers.js.map +1 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +21 -0
- package/dist/index.js.map +1 -0
- package/dist/list.d.ts +166 -0
- package/dist/list.d.ts.map +1 -0
- package/dist/list.js +483 -0
- package/dist/list.js.map +1 -0
- package/dist/middlewares.d.ts +251 -0
- package/dist/middlewares.d.ts.map +1 -0
- package/dist/middlewares.js +359 -0
- package/dist/middlewares.js.map +1 -0
- package/dist/router.d.ts +333 -0
- package/dist/router.d.ts.map +1 -0
- package/dist/router.js +659 -0
- package/dist/router.js.map +1 -0
- package/dist/tree.d.ts +18 -0
- package/dist/tree.d.ts.map +1 -0
- package/dist/tree.js +162 -0
- package/dist/tree.js.map +1 -0
- package/dist/types.d.ts +127 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +3 -0
- package/dist/types.js.map +1 -0
- package/dist/upload-stream.d.ts +105 -0
- package/dist/upload-stream.d.ts.map +1 -0
- package/dist/upload-stream.js +417 -0
- package/dist/upload-stream.js.map +1 -0
- package/package.json +51 -0
|
@@ -0,0 +1,417 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.parseUploadStreaming = void 0;
|
|
13
|
+
const helpers_js_1 = require("./helpers.js");
|
|
14
|
+
/**
|
|
15
|
+
* Creates a middleware function for streaming multipart/form-data upload parsing.
|
|
16
|
+
* This function processes uploads in chunks as they arrive, allowing for handling
|
|
17
|
+
* of large files without buffering the entire request in memory.
|
|
18
|
+
*
|
|
19
|
+
* @param {StreamingUploadOptions} [options] - Configuration options for upload parsing
|
|
20
|
+
* @returns {Function} A middleware function that adds uploaded files and fields to context
|
|
21
|
+
* @throws {Response} Returns a 415 response if content-type is not multipart/form-data
|
|
22
|
+
* @throws {Response} Returns a 400 response if boundary is missing in Content-Type
|
|
23
|
+
* @throws {Response} Returns a 413 response if request or file exceeds size limits
|
|
24
|
+
* @throws {Response} Returns a 415 response if file type is not allowed
|
|
25
|
+
* @throws {Response} Returns a 400 response if maximum file/field count is exceeded
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* const uploadHandler = parseUploadStreaming({
|
|
29
|
+
* maxFileSize: 10 * 1024 * 1024, // 10MB
|
|
30
|
+
* allowedTypes: ['image/jpeg', 'image/png'],
|
|
31
|
+
* onFileStart: async (uploadId, fieldName, fileName, contentType) => {
|
|
32
|
+
* console.log(`Starting upload: ${fileName}`);
|
|
33
|
+
* return { customFilename: `custom_${Date.now()}_${fileName}` };
|
|
34
|
+
* },
|
|
35
|
+
* onFileChunk: async (uploadId, fieldName, fileName, chunk, offset, isLast) => {
|
|
36
|
+
* console.log(`Received chunk for ${fileName}: ${chunk.length} bytes at offset ${offset}`);
|
|
37
|
+
* }
|
|
38
|
+
* });
|
|
39
|
+
*
|
|
40
|
+
* // Use in respondWith:
|
|
41
|
+
* const handler = respondWith({}, uploadHandler, (req, ctx) => {
|
|
42
|
+
* return json({
|
|
43
|
+
* uploadId: ctx.uploadId,
|
|
44
|
+
* files: Array.from(ctx.files.entries()),
|
|
45
|
+
* fields: Array.from(ctx.fields.entries())
|
|
46
|
+
* });
|
|
47
|
+
* });
|
|
48
|
+
*/
|
|
49
|
+
const parseUploadStreaming = (options) => {
|
|
50
|
+
const { maxTotalSize = 100 * 1024 * 1024, // 100MB default
|
|
51
|
+
maxFileSize = 20 * 1024 * 1024, // 20MB per file
|
|
52
|
+
maxFiles = 50, maxFields = 1000, allowedTypes, uploadIdGenerator = () => `upload_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`, onUploadStart, onUploadComplete, onFileStart, onFileChunk, onFileComplete, onFileError, onField, onError, } = options || {};
|
|
53
|
+
return (req, ctx) => __awaiter(void 0, void 0, void 0, function* () {
|
|
54
|
+
var _a;
|
|
55
|
+
const contentType = req.headers.get("content-type");
|
|
56
|
+
// Check if it's multipart/form-data
|
|
57
|
+
if (!(contentType === null || contentType === void 0 ? void 0 : contentType.startsWith("multipart/form-data"))) {
|
|
58
|
+
return (0, helpers_js_1.status)(415, "Expected multipart/form-data");
|
|
59
|
+
}
|
|
60
|
+
// Get boundary from content-type
|
|
61
|
+
const boundaryMatch = contentType.match(/boundary=(?:"([^"]+)"|([^;]+))/i);
|
|
62
|
+
if (!boundaryMatch) {
|
|
63
|
+
return (0, helpers_js_1.status)(400, "Missing boundary in Content-Type");
|
|
64
|
+
}
|
|
65
|
+
const boundary = boundaryMatch[1] || boundaryMatch[2];
|
|
66
|
+
// Generate upload ID
|
|
67
|
+
const uploadId = yield uploadIdGenerator();
|
|
68
|
+
ctx.uploadId = uploadId;
|
|
69
|
+
ctx.files = new Map();
|
|
70
|
+
ctx.fields = new Map();
|
|
71
|
+
try {
|
|
72
|
+
const reader = (_a = req.body) === null || _a === void 0 ? void 0 : _a.getReader();
|
|
73
|
+
if (!reader) {
|
|
74
|
+
throw new Error("No request body");
|
|
75
|
+
}
|
|
76
|
+
// Initialize tracking
|
|
77
|
+
let buffer = new Uint8Array();
|
|
78
|
+
let totalRead = 0;
|
|
79
|
+
let fileCount = 0;
|
|
80
|
+
let fieldCount = 0;
|
|
81
|
+
let currentPart = null;
|
|
82
|
+
const boundaryBytes = new TextEncoder().encode(`--${boundary}`);
|
|
83
|
+
const boundaryEndBytes = new TextEncoder().encode(`--${boundary}--`);
|
|
84
|
+
const crlfBytes = new TextEncoder().encode("\r\n");
|
|
85
|
+
const headerEndBytes = new TextEncoder().encode("\r\n\r\n");
|
|
86
|
+
// Notify upload start
|
|
87
|
+
if (onUploadStart) {
|
|
88
|
+
const contentLength = req.headers.get("content-length");
|
|
89
|
+
yield onUploadStart(uploadId, contentLength ? parseInt(contentLength) : 0);
|
|
90
|
+
}
|
|
91
|
+
// Process streaming data
|
|
92
|
+
while (true) {
|
|
93
|
+
const { done, value } = yield reader.read();
|
|
94
|
+
if (done)
|
|
95
|
+
break;
|
|
96
|
+
totalRead += value.length;
|
|
97
|
+
if (totalRead > maxTotalSize) {
|
|
98
|
+
yield reader.cancel();
|
|
99
|
+
throw new Error(`Request exceeds maximum size of ${maxTotalSize} bytes`);
|
|
100
|
+
}
|
|
101
|
+
// Add new data to buffer
|
|
102
|
+
const newBuffer = new Uint8Array(buffer.length + value.length);
|
|
103
|
+
newBuffer.set(buffer);
|
|
104
|
+
newBuffer.set(value, buffer.length);
|
|
105
|
+
buffer = newBuffer;
|
|
106
|
+
// Process while we have data
|
|
107
|
+
let processed = false;
|
|
108
|
+
do {
|
|
109
|
+
processed = false;
|
|
110
|
+
if (!currentPart) {
|
|
111
|
+
// Look for boundary to start new part
|
|
112
|
+
const boundaryIndex = findSequence(buffer, boundaryBytes);
|
|
113
|
+
if (boundaryIndex !== -1) {
|
|
114
|
+
// Check if this is the closing boundary
|
|
115
|
+
const isClosingBoundary = buffer.length >= boundaryIndex + boundaryBytes.length + 2 &&
|
|
116
|
+
buffer[boundaryIndex + boundaryBytes.length] === 45 && // '-'
|
|
117
|
+
buffer[boundaryIndex + boundaryBytes.length + 1] === 45; // '-'
|
|
118
|
+
if (isClosingBoundary) {
|
|
119
|
+
// End of multipart data
|
|
120
|
+
buffer = buffer.slice(boundaryIndex + boundaryEndBytes.length);
|
|
121
|
+
break;
|
|
122
|
+
}
|
|
123
|
+
// Remove boundary and look for headers
|
|
124
|
+
buffer = buffer.slice(boundaryIndex + boundaryBytes.length);
|
|
125
|
+
// Look for header end
|
|
126
|
+
const headerEndIndex = findSequence(buffer, headerEndBytes);
|
|
127
|
+
if (headerEndIndex !== -1) {
|
|
128
|
+
const headerBytes = buffer.slice(0, headerEndIndex);
|
|
129
|
+
const headers = parseHeaders(new TextDecoder().decode(headerBytes));
|
|
130
|
+
// Parse content-disposition
|
|
131
|
+
const contentDisposition = headers.get("content-disposition");
|
|
132
|
+
if (contentDisposition) {
|
|
133
|
+
const dispositionParams = parseDisposition(contentDisposition);
|
|
134
|
+
const fieldName = dispositionParams.get("name");
|
|
135
|
+
const fileName = dispositionParams.get("filename");
|
|
136
|
+
const contentType = headers.get("content-type") || "application/octet-stream";
|
|
137
|
+
if (fieldName) {
|
|
138
|
+
currentPart = {
|
|
139
|
+
headers,
|
|
140
|
+
fieldName,
|
|
141
|
+
fileName,
|
|
142
|
+
contentType,
|
|
143
|
+
bytesRead: 0,
|
|
144
|
+
isProcessing: false,
|
|
145
|
+
};
|
|
146
|
+
// Remove headers from buffer
|
|
147
|
+
buffer = buffer.slice(headerEndIndex + headerEndBytes.length);
|
|
148
|
+
// Start processing this part
|
|
149
|
+
processed = true;
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
if (currentPart && !currentPart.isProcessing) {
|
|
156
|
+
// Initialize part processing
|
|
157
|
+
currentPart.isProcessing = true;
|
|
158
|
+
if (currentPart.fileName) {
|
|
159
|
+
// This is a file
|
|
160
|
+
fileCount++;
|
|
161
|
+
if (fileCount > maxFiles) {
|
|
162
|
+
throw new Error(`Maximum number of files (${maxFiles}) exceeded`);
|
|
163
|
+
}
|
|
164
|
+
if (allowedTypes &&
|
|
165
|
+
!allowedTypes.includes(currentPart.contentType)) {
|
|
166
|
+
throw new Error(`File type ${currentPart.contentType} not allowed`);
|
|
167
|
+
}
|
|
168
|
+
// Call onFileStart
|
|
169
|
+
if (onFileStart) {
|
|
170
|
+
try {
|
|
171
|
+
const result = yield onFileStart(uploadId, currentPart.fieldName, currentPart.fileName, currentPart.contentType);
|
|
172
|
+
if (result) {
|
|
173
|
+
currentPart.customFilename = result.customFilename;
|
|
174
|
+
currentPart.metadata = result.metadata;
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
catch (error) {
|
|
178
|
+
if (onFileError) {
|
|
179
|
+
yield onFileError(uploadId, currentPart.fieldName, currentPart.fileName, error);
|
|
180
|
+
}
|
|
181
|
+
currentPart = null;
|
|
182
|
+
continue;
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
// Add to ctx.files
|
|
186
|
+
ctx.files.set(currentPart.fieldName, {
|
|
187
|
+
name: currentPart.fileName,
|
|
188
|
+
type: currentPart.contentType,
|
|
189
|
+
size: 0, // Will be updated as we read
|
|
190
|
+
customFilename: currentPart.customFilename,
|
|
191
|
+
metadata: currentPart.metadata,
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
else {
|
|
195
|
+
// This is a text field
|
|
196
|
+
fieldCount++;
|
|
197
|
+
if (fieldCount > maxFields) {
|
|
198
|
+
throw new Error(`Maximum number of fields (${maxFields}) exceeded`);
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
if (currentPart && currentPart.isProcessing) {
|
|
203
|
+
// Process part data until we hit a boundary
|
|
204
|
+
const boundaryIndex = findSequence(buffer, boundaryBytes);
|
|
205
|
+
if (boundaryIndex !== -1) {
|
|
206
|
+
// We found the next boundary
|
|
207
|
+
// Check for CRLF before boundary (it should be there)
|
|
208
|
+
let dataEnd = boundaryIndex;
|
|
209
|
+
if (boundaryIndex >= 2) {
|
|
210
|
+
// Check if there's a CRLF before the boundary
|
|
211
|
+
if (buffer[boundaryIndex - 2] === 13 &&
|
|
212
|
+
buffer[boundaryIndex - 1] === 10) {
|
|
213
|
+
dataEnd = boundaryIndex - 2; // Exclude the CRLF
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
const partData = buffer.slice(0, dataEnd);
|
|
217
|
+
if (currentPart.fileName) {
|
|
218
|
+
// Process file chunk
|
|
219
|
+
if (partData.length > 0) {
|
|
220
|
+
currentPart.bytesRead += partData.length;
|
|
221
|
+
// Check file size limit
|
|
222
|
+
if (currentPart.bytesRead > maxFileSize) {
|
|
223
|
+
throw new Error(`File ${currentPart.fileName} exceeds maximum size of ${maxFileSize} bytes`);
|
|
224
|
+
}
|
|
225
|
+
// Update file size in context
|
|
226
|
+
const file = ctx.files.get(currentPart.fieldName);
|
|
227
|
+
file.size = currentPart.bytesRead;
|
|
228
|
+
// Call onFileChunk
|
|
229
|
+
if (onFileChunk) {
|
|
230
|
+
yield onFileChunk(uploadId, currentPart.fieldName, currentPart.fileName, partData, currentPart.bytesRead - partData.length, true);
|
|
231
|
+
}
|
|
232
|
+
// Call onFileComplete
|
|
233
|
+
if (onFileComplete) {
|
|
234
|
+
yield onFileComplete(uploadId, currentPart.fieldName, currentPart.fileName, currentPart.bytesRead, currentPart.customFilename, currentPart.metadata);
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
else {
|
|
239
|
+
// Process text field
|
|
240
|
+
if (partData.length > 0) {
|
|
241
|
+
const value = new TextDecoder().decode(partData);
|
|
242
|
+
// Add to context
|
|
243
|
+
ctx.fields.set(currentPart.fieldName, value);
|
|
244
|
+
// Call onField
|
|
245
|
+
if (onField) {
|
|
246
|
+
yield onField(uploadId, currentPart.fieldName, value);
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
// Move buffer past processed data and boundary
|
|
251
|
+
buffer = buffer.slice(boundaryIndex);
|
|
252
|
+
currentPart = null;
|
|
253
|
+
processed = true;
|
|
254
|
+
}
|
|
255
|
+
else {
|
|
256
|
+
// No boundary found yet
|
|
257
|
+
// Process what we have in buffer (but leave enough bytes for a potential boundary)
|
|
258
|
+
const minBoundaryLength = boundaryBytes.length;
|
|
259
|
+
// Only process if we have significantly more data than boundary length
|
|
260
|
+
if (buffer.length > minBoundaryLength * 2) {
|
|
261
|
+
// Process chunks, but keep enough in buffer to detect boundary
|
|
262
|
+
const chunkSize = buffer.length - minBoundaryLength;
|
|
263
|
+
if (currentPart.fileName && chunkSize > 0) {
|
|
264
|
+
const partData = buffer.slice(0, chunkSize);
|
|
265
|
+
currentPart.bytesRead += partData.length;
|
|
266
|
+
// Check file size limit
|
|
267
|
+
if (currentPart.bytesRead > maxFileSize) {
|
|
268
|
+
throw new Error(`File ${currentPart.fileName} exceeds maximum size of ${maxFileSize} bytes`);
|
|
269
|
+
}
|
|
270
|
+
// Update file size in context
|
|
271
|
+
const file = ctx.files.get(currentPart.fieldName);
|
|
272
|
+
file.size = currentPart.bytesRead;
|
|
273
|
+
// Call onFileChunk
|
|
274
|
+
if (onFileChunk) {
|
|
275
|
+
yield onFileChunk(uploadId, currentPart.fieldName, currentPart.fileName, partData, currentPart.bytesRead - partData.length, false);
|
|
276
|
+
}
|
|
277
|
+
// Move buffer past processed data
|
|
278
|
+
buffer = buffer.slice(chunkSize);
|
|
279
|
+
processed = true;
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
} while (processed);
|
|
285
|
+
}
|
|
286
|
+
// Process any remaining data in buffer (for the last part)
|
|
287
|
+
if (currentPart && buffer.length > 0) {
|
|
288
|
+
if (currentPart.fileName) {
|
|
289
|
+
// Process remaining file data
|
|
290
|
+
currentPart.bytesRead += buffer.length;
|
|
291
|
+
// Check file size limit
|
|
292
|
+
if (currentPart.bytesRead > maxFileSize) {
|
|
293
|
+
throw new Error(`File ${currentPart.fileName} exceeds maximum size of ${maxFileSize} bytes`);
|
|
294
|
+
}
|
|
295
|
+
// Update file size in context
|
|
296
|
+
const file = ctx.files.get(currentPart.fieldName);
|
|
297
|
+
file.size = currentPart.bytesRead;
|
|
298
|
+
// Call onFileChunk for last chunk
|
|
299
|
+
if (onFileChunk) {
|
|
300
|
+
yield onFileChunk(uploadId, currentPart.fieldName, currentPart.fileName, buffer, currentPart.bytesRead - buffer.length, true);
|
|
301
|
+
}
|
|
302
|
+
// Call onFileComplete
|
|
303
|
+
if (onFileComplete) {
|
|
304
|
+
yield onFileComplete(uploadId, currentPart.fieldName, currentPart.fileName, currentPart.bytesRead, currentPart.customFilename, currentPart.metadata);
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
else {
|
|
308
|
+
// Process remaining text field data
|
|
309
|
+
const value = new TextDecoder().decode(buffer);
|
|
310
|
+
// Add to context
|
|
311
|
+
ctx.fields.set(currentPart.fieldName, value);
|
|
312
|
+
// Call onField
|
|
313
|
+
if (onField) {
|
|
314
|
+
yield onField(uploadId, currentPart.fieldName, value);
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
// Notify upload completion
|
|
319
|
+
if (onUploadComplete) {
|
|
320
|
+
yield onUploadComplete(uploadId, true);
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
catch (error) {
|
|
324
|
+
// Notify upload completion with failure
|
|
325
|
+
if (onUploadComplete) {
|
|
326
|
+
yield onUploadComplete(uploadId, false).catch(() => { });
|
|
327
|
+
}
|
|
328
|
+
// Call error handler
|
|
329
|
+
if (onError) {
|
|
330
|
+
yield onError(uploadId, error).catch(() => { });
|
|
331
|
+
}
|
|
332
|
+
console.error("Upload parsing error:", error);
|
|
333
|
+
if (error.message.includes("exceeds maximum")) {
|
|
334
|
+
return (0, helpers_js_1.status)(413, error.message);
|
|
335
|
+
}
|
|
336
|
+
if (error.message.includes("not allowed")) {
|
|
337
|
+
return (0, helpers_js_1.status)(415, error.message);
|
|
338
|
+
}
|
|
339
|
+
if (error.message.includes("exceeded")) {
|
|
340
|
+
return (0, helpers_js_1.status)(400, error.message);
|
|
341
|
+
}
|
|
342
|
+
return (0, helpers_js_1.status)(400, "Failed to parse upload");
|
|
343
|
+
}
|
|
344
|
+
});
|
|
345
|
+
};
|
|
346
|
+
exports.parseUploadStreaming = parseUploadStreaming;
|
|
347
|
+
/**
|
|
348
|
+
* Helper function to find a byte sequence within a buffer.
|
|
349
|
+
* Performs a linear search for the sequence in the buffer.
|
|
350
|
+
*
|
|
351
|
+
* @private
|
|
352
|
+
* @param {Uint8Array} buffer - The buffer to search within
|
|
353
|
+
* @param {Uint8Array} sequence - The byte sequence to find
|
|
354
|
+
* @returns {number} The index of the sequence, or -1 if not found
|
|
355
|
+
*/
|
|
356
|
+
function findSequence(buffer, sequence) {
|
|
357
|
+
if (buffer.length < sequence.length)
|
|
358
|
+
return -1;
|
|
359
|
+
// Use a more efficient search algorithm for large buffers
|
|
360
|
+
for (let i = 0; i <= buffer.length - sequence.length; i++) {
|
|
361
|
+
let found = true;
|
|
362
|
+
for (let j = 0; j < sequence.length; j++) {
|
|
363
|
+
if (buffer[i + j] !== sequence[j]) {
|
|
364
|
+
found = false;
|
|
365
|
+
break;
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
if (found)
|
|
369
|
+
return i;
|
|
370
|
+
}
|
|
371
|
+
return -1;
|
|
372
|
+
}
|
|
373
|
+
/**
|
|
374
|
+
* Helper function to parse HTTP headers from text.
|
|
375
|
+
*
|
|
376
|
+
* @private
|
|
377
|
+
* @param {string} headerText - Raw header text with CRLF separators
|
|
378
|
+
* @returns {Map<string, string>} Map of lowercase header names to values
|
|
379
|
+
*/
|
|
380
|
+
function parseHeaders(headerText) {
|
|
381
|
+
const headers = new Map();
|
|
382
|
+
const lines = headerText.split("\r\n");
|
|
383
|
+
for (const line of lines) {
|
|
384
|
+
const colonIndex = line.indexOf(":");
|
|
385
|
+
if (colonIndex !== -1) {
|
|
386
|
+
const key = line.slice(0, colonIndex).trim().toLowerCase();
|
|
387
|
+
const value = line.slice(colonIndex + 1).trim();
|
|
388
|
+
headers.set(key, value);
|
|
389
|
+
}
|
|
390
|
+
}
|
|
391
|
+
return headers;
|
|
392
|
+
}
|
|
393
|
+
/**
|
|
394
|
+
* Helper function to parse content-disposition header parameters.
|
|
395
|
+
*
|
|
396
|
+
* @private
|
|
397
|
+
* @param {string} disposition - Content-disposition header value
|
|
398
|
+
* @returns {Map<string, string>} Map of parameter names to values
|
|
399
|
+
*/
|
|
400
|
+
function parseDisposition(disposition) {
|
|
401
|
+
const params = new Map();
|
|
402
|
+
const parts = disposition.split(";").map((p) => p.trim());
|
|
403
|
+
for (let i = 1; i < parts.length; i++) {
|
|
404
|
+
const part = parts[i];
|
|
405
|
+
const eqIndex = part.indexOf("=");
|
|
406
|
+
if (eqIndex !== -1) {
|
|
407
|
+
let key = part.slice(0, eqIndex).trim();
|
|
408
|
+
let value = part.slice(eqIndex + 1).trim();
|
|
409
|
+
if (value.startsWith('"') && value.endsWith('"')) {
|
|
410
|
+
value = value.slice(1, -1);
|
|
411
|
+
}
|
|
412
|
+
params.set(key, value);
|
|
413
|
+
}
|
|
414
|
+
}
|
|
415
|
+
return params;
|
|
416
|
+
}
|
|
417
|
+
//# sourceMappingURL=upload-stream.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"upload-stream.js","sourceRoot":"","sources":["../src/upload-stream.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,6CAAsC;AAkHtC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AACI,MAAM,oBAAoB,GAAG,CAAC,OAAgC,EAAE,EAAE;IACvE,MAAM,EACJ,YAAY,GAAG,GAAG,GAAG,IAAI,GAAG,IAAI,EAAE,gBAAgB;IAClD,WAAW,GAAG,EAAE,GAAG,IAAI,GAAG,IAAI,EAAE,gBAAgB;IAChD,QAAQ,GAAG,EAAE,EACb,SAAS,GAAG,IAAI,EAChB,YAAY,EACZ,iBAAiB,GAAG,GAAG,EAAE,CACvB,UAAU,IAAI,CAAC,GAAG,EAAE,IAAI,IAAI,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,EACnE,aAAa,EACb,gBAAgB,EAChB,WAAW,EACX,WAAW,EACX,cAAc,EACd,WAAW,EACX,OAAO,EACP,OAAO,GACR,GAAG,OAAO,IAAI,EAAE,CAAC;IAElB,OAAO,CAAkC,GAAY,EAAE,GAA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C,GAAG,CAAC,EAAE,CAAC,GAAG,KAAK,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QACtC,MAAM,IAAI,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC;QACtB,MAAM,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;QAClC,IAAI,OAAO,KAAK,CAAC,CAAC,EAAE,CAAC;YACnB,IAAI,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,OAAO,CAAC,CAAC,IAAI,EAAE,CAAC;YACxC,IAAI,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,OAAO,GAAG,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;YAE3C,IAAI,KAAK,CAAC,UAAU,CAAC,GAAG,CAAC,IAAI,KAAK,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC;gBACjD,KAAK,GAAG,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;YAC7B,CAAC;YAED,MAAM,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;QACzB,CAAC;IACH,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@bepalo/router",
|
|
3
|
+
"version": "1.0.3",
|
|
4
|
+
"description": "A fast and feature-rich router for JavaScript runtimes.",
|
|
5
|
+
"author": "Natnael Eshetu",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "https://github.com/bepalo/router.git"
|
|
10
|
+
},
|
|
11
|
+
"homepage": "https://github.com/bepalo/router#readme",
|
|
12
|
+
"exports": {
|
|
13
|
+
"import": "./dist/index.js",
|
|
14
|
+
"require": "./dist/cjs/index.js"
|
|
15
|
+
},
|
|
16
|
+
"main": "./dist/cjs/index.js",
|
|
17
|
+
"module": "./dist/index.js",
|
|
18
|
+
"types": "./dist/index.d.ts",
|
|
19
|
+
"files": [
|
|
20
|
+
"dist/",
|
|
21
|
+
"LICENSE",
|
|
22
|
+
"README.md"
|
|
23
|
+
],
|
|
24
|
+
"devDependencies": {
|
|
25
|
+
"@types/bun": "latest",
|
|
26
|
+
"@types/node": "^24.0.13",
|
|
27
|
+
"typescript": "^5.8.3",
|
|
28
|
+
"vitest": "^3.2.4",
|
|
29
|
+
"vitest-markdown-reporter": "^0.1.2"
|
|
30
|
+
},
|
|
31
|
+
"keywords": [
|
|
32
|
+
"router",
|
|
33
|
+
"rest",
|
|
34
|
+
"http",
|
|
35
|
+
"https",
|
|
36
|
+
"middleware"
|
|
37
|
+
],
|
|
38
|
+
"dependencies": {
|
|
39
|
+
"@bepalo/cache": "^1.0.3",
|
|
40
|
+
"@bepalo/jwt": "^2.0.9",
|
|
41
|
+
"@bepalo/time": "^1.2.11"
|
|
42
|
+
},
|
|
43
|
+
"scripts": {
|
|
44
|
+
"build:esm": "tsc --project tsconfig.esm.json",
|
|
45
|
+
"build:cjs": "tsc --project tsconfig.cjs.json",
|
|
46
|
+
"build": "pnpm run build:esm && pnpm run build:cjs",
|
|
47
|
+
"build:watch": "tsc --watch --project tsconfig.esm.json & tsc --watch --project tsconfig.cjs.json",
|
|
48
|
+
"test": "vitest --reporter=dot",
|
|
49
|
+
"test:ci": "vitest run --reporter=vitest-markdown-reporter --outputFile=test-result.md"
|
|
50
|
+
}
|
|
51
|
+
}
|