mbkbucket 4.4.0 → 4.4.2

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.
@@ -128,52 +128,48 @@ async function serveFileInline(req, res, keyToUse, { noindex = true, bucketName,
128
128
  const etag = meta.ETag || `"${new Date(meta.LastModified || Date.now()).getTime()}-${meta.ContentLength || 0}"`;
129
129
  if (ifNoneMatch && (ifNoneMatch === etag || ifNoneMatch === '*')) return res.status(304).end();
130
130
 
131
- const ifRangeSatisfied = !ifRange || isIfRangeValid(ifRange, etag, meta.LastModified);
132
-
133
- if (ifRangeSatisfied) {
134
- const total = Number(meta.ContentLength);
135
- if (total) {
136
- const range = parseRangeHeader(rangeHeader, total);
137
- if (!range) {
138
- res.status(416).setHeader('Content-Range', `bytes */${total}`);
139
- return res.end();
131
+ const total = Number(meta.ContentLength);
132
+ if (total) {
133
+ const range = parseRangeHeader(rangeHeader, total);
134
+ if (!range) {
135
+ res.status(416).setHeader('Content-Range', `bytes */${total}`);
136
+ return res.end();
137
+ }
138
+
139
+ const { start, end, size: chunksize } = range;
140
+ try {
141
+ const rangeResult = await downloadFile(keyToUse, { range: `bytes=${start}-${end}`, bucketName });
142
+ if (typeof rangeResult.ContentLength === 'number' && rangeResult.ContentLength !== chunksize) {
143
+ debugView('Range size mismatch for %s: expected=%s got=%s', keyToUse, chunksize, rangeResult.ContentLength);
140
144
  }
141
145
 
142
- const { start, end, size: chunksize } = range;
143
- try {
144
- const rangeResult = await downloadFile(keyToUse, { range: `bytes=${start}-${end}`, bucketName });
145
- if (typeof rangeResult.ContentLength === 'number' && rangeResult.ContentLength !== chunksize) {
146
- debugView('Range size mismatch for %s: expected=%s got=%s', keyToUse, chunksize, rangeResult.ContentLength);
147
- }
148
-
149
- debugView('Serving range bytes %s-%s/%s (%s bytes) for %s', start, end, total, chunksize, fileName);
150
-
151
- res.status(206);
152
- res.setHeader('Content-Range', `bytes ${start}-${end}/${total}`);
153
- res.setHeader('Content-Length', chunksize);
154
- res.setHeader('Content-Type', contentType);
155
- res.setHeader('Content-Disposition', `${dispositionType}; filename="${safeAsciiName}"; filename*=UTF-8''${encodedName}`);
156
- res.setHeader('Cache-Control', buildCacheControl(contentType, { supportsRanges: true, publicCache }));
157
- if (publicCache) {
158
- res.setHeader('CDN-Cache-Control', 'public, s-maxage=31536000, stale-while-revalidate=86400');
159
- res.setHeader('Vercel-CDN-Cache-Control', 'public, s-maxage=31536000, stale-while-revalidate=86400');
160
- }
161
- res.setHeader('ETag', etag);
162
- res.setHeader('Accept-Ranges', 'bytes');
163
- res.setHeader('Vary', 'Accept-Encoding, Range');
164
- res.setHeader('X-Frame-Options', 'SAMEORIGIN');
165
- if (noindex) res.setHeader('X-Robots-Tag', 'noindex, nofollow');
166
- res.setHeader('X-Content-Type-Options', 'nosniff');
167
- const stream = rangeResult.Body || rangeResult.stream;
168
- attachStreamCleanup(req, res, stream);
169
- return stream.pipe(res);
170
- } catch (rangeError) {
171
- console.error('[mbkbucket] Range request failed for %s:', keyToUse, rangeError);
172
- if (!res.headersSent) {
173
- return res.status(500).json({ message: 'Range stream failed', error: rangeError.message });
174
- }
175
- return;
146
+ debugView('Serving range bytes %s-%s/%s (%s bytes) for %s', start, end, total, chunksize, fileName);
147
+
148
+ res.status(206);
149
+ res.setHeader('Content-Range', `bytes ${start}-${end}/${total}`);
150
+ res.setHeader('Content-Length', chunksize);
151
+ res.setHeader('Content-Type', contentType);
152
+ res.setHeader('Content-Disposition', `${dispositionType}; filename="${safeAsciiName}"; filename*=UTF-8''${encodedName}`);
153
+ res.setHeader('Cache-Control', buildCacheControl(contentType, { supportsRanges: true, publicCache }));
154
+ if (publicCache) {
155
+ res.setHeader('CDN-Cache-Control', 'public, s-maxage=31536000, stale-while-revalidate=86400');
156
+ res.setHeader('Vercel-CDN-Cache-Control', 'public, s-maxage=31536000, stale-while-revalidate=86400');
157
+ }
158
+ res.setHeader('ETag', etag);
159
+ res.setHeader('Accept-Ranges', 'bytes');
160
+ res.setHeader('Vary', 'Accept-Encoding, Range');
161
+ res.setHeader('X-Frame-Options', 'SAMEORIGIN');
162
+ if (noindex) res.setHeader('X-Robots-Tag', 'noindex, nofollow');
163
+ res.setHeader('X-Content-Type-Options', 'nosniff');
164
+ const stream = rangeResult.Body || rangeResult.stream;
165
+ attachStreamCleanup(req, res, stream);
166
+ return stream.pipe(res);
167
+ } catch (rangeError) {
168
+ console.error('[mbkbucket] Range request failed for %s:', keyToUse, rangeError);
169
+ if (!res.headersSent) {
170
+ return res.status(500).json({ message: 'Range stream failed', error: rangeError.message });
176
171
  }
172
+ return;
177
173
  }
178
174
  }
179
175
  }
@@ -19,7 +19,12 @@ export class S3StorageProvider extends StorageProvider {
19
19
  constructor(name, config = {}) {
20
20
  super(name, config);
21
21
  this.bucket = config.BUCKET_NAME;
22
- this.region = config.region || 'auto';
22
+ this.region = config.region || config.Region || 'auto';
23
+
24
+ const connectionTimeout = Number(config.connectionTimeout ?? config.CONNECTION_TIMEOUT ?? process.env.S3_CONNECTION_TIMEOUT ?? 15000);
25
+ const requestTimeout = Number(config.requestTimeout ?? config.REQUEST_TIMEOUT ?? process.env.S3_REQUEST_TIMEOUT ?? 120000);
26
+ const keepAlive = config.keepAlive ?? true;
27
+
23
28
  this.client = new S3Client({
24
29
  region: this.region,
25
30
  endpoint: config.ENDPOINT,
@@ -29,12 +34,13 @@ export class S3StorageProvider extends StorageProvider {
29
34
  },
30
35
  maxAttempts: 3,
31
36
  retryMode: 'adaptive',
32
- requestTimeout: 120000,
37
+ requestTimeout,
33
38
  requestHandler: {
34
- connectionTimeout: 5000,
35
- socketTimeout: 120000,
39
+ connectionTimeout,
40
+ requestTimeout,
41
+ socketTimeout: requestTimeout,
36
42
  maxSockets: 50,
37
- keepAlive: true,
43
+ keepAlive,
38
44
  keepAliveMsecs: 1000,
39
45
  },
40
46
  useAccelerateEndpoint: false,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mbkbucket",
3
- "version": "4.4.0",
3
+ "version": "4.4.2",
4
4
  "description": "Flexible S3/R2/Google Drive/Local bucket management — library, Express router, and standalone server CLI for mbktech.org applications. Provides upload, download, listing, multipart utilities, and a standalone server runner with built-in configuration validation and health checks",
5
5
  "author": "Muhammad Bin Khalid",
6
6
  "homepage": "https://github.com/MIbnEKhalid/mbkbucket#readme",