mbkbucket 1.5.0 → 1.5.1

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/index.js CHANGED
@@ -37,8 +37,10 @@ const generalLimiter = rateLimit({
37
37
  }
38
38
  });
39
39
 
40
- server.use(express.json());
41
- server.use(express.urlencoded({ extended: true }));
40
+ // Increase body size limits to support larger form submissions (e.g., multipart upload init/complete payloads).
41
+ // Multipart/form-data uploads themselves are handled separately via multer in the upload endpoints.
42
+ server.use(express.json({ limit: '10mb' }));
43
+ server.use(express.urlencoded({ extended: true, limit: '10mb' }));
42
44
 
43
45
  // Serve only specific static assets (limit exposure): CSS and JS used by the dashboard
44
46
  // This replaces serving the entire /public directory.
package/lib/routes/api.js CHANGED
@@ -4,7 +4,32 @@ import { listfiles, uploadFile, deleteFile, deleteFiles, deleteFolder, downloadF
4
4
  import multer from "multer";
5
5
 
6
6
  const router = express.Router();
7
- const upload = multer({ storage: multer.memoryStorage() });
7
+
8
+ // This is the maximum size we allow per chunk upload. It should be >=
9
+ // the client chunk size (5MB) and leave room for any encoding overhead.
10
+ // If you need to support larger chunks, increase this accordingly.
11
+ const MAX_CHUNK_SIZE = 50 * 1024 * 1024; // 50 MB
12
+
13
+ const upload = multer({
14
+ storage: multer.memoryStorage(),
15
+ limits: { fileSize: MAX_CHUNK_SIZE }
16
+ });
17
+
18
+ const uploadChunk = (req, res, next) => {
19
+ upload.single('chunk')(req, res, (err) => {
20
+ if (err) {
21
+ // Multer throws an error if the file is too large (or another multipart parsing issue occurs)
22
+ if (err.code === 'LIMIT_FILE_SIZE') {
23
+ return res.status(413).json({
24
+ success: false,
25
+ error: `Chunk too large (max ${Math.round(MAX_CHUNK_SIZE / (1024 * 1024))} MB).`,
26
+ });
27
+ }
28
+ return next(err);
29
+ }
30
+ next();
31
+ });
32
+ };
8
33
 
9
34
  // API endpoint for multipart upload cleanup
10
35
  router.post('/api/cleanup-uploads', validateSessionAndRole('SuperAdmin'), async (req, res) => {
@@ -295,7 +320,7 @@ router.post('/upload-init', validateSessionAndRole('SuperAdmin'), async (req, re
295
320
  // S3 Multipart Upload — Step 2: Upload a part
296
321
  // FormData: chunk (file), partNumber (1-based integer), uploadId, key
297
322
  // Returns: { partNumber, ETag }
298
- router.post('/upload-chunk', validateSessionAndRole('SuperAdmin'), upload.single('chunk'), async (req, res) => {
323
+ router.post('/upload-chunk', validateSessionAndRole('SuperAdmin'), uploadChunk, async (req, res) => {
299
324
  try {
300
325
  const { uploadId, key, partNumber } = req.body;
301
326
  if (!req.file || !uploadId || !key || !partNumber) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mbkbucket",
3
- "version": "1.5.0",
3
+ "version": "1.5.1",
4
4
  "description": "Flexible S3/R2 bucket management library and Express router for mbktech.org applications, providing upload, download, listing, and multipart utilities with built-in configuration validation and health checks",
5
5
  "author": "Muhammad Bin Khalid",
6
6
  "homepage": "https://github.com/MIbnEKhalid/mbkbucket#readme",