mbkbucket 1.4.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.
@@ -0,0 +1,526 @@
1
+ import express from "express";
2
+ import { validateSessionAndRole, } from "mbkauthe";
3
+ import { listfiles, uploadFile, deleteFile, deleteFiles, deleteFolder, downloadFile, getFileMetadata, fileExists, ensureKeyHasAppPrefix, ensurePrefix, getAppName, createMultipartUpload, uploadPart, completeMultipartUpload, abortMultipartUpload, listIncompleteMultipartUploads, cleanupIncompleteMultipartUploads } from "../s3.js";
4
+ import multer from "multer";
5
+
6
+ const router = express.Router();
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
+ };
33
+
34
+ // API endpoint for multipart upload cleanup
35
+ router.post('/api/cleanup-uploads', validateSessionAndRole('SuperAdmin'), async (req, res) => {
36
+ try {
37
+ const { olderThanDays = 7, prefix = '' } = req.body;
38
+
39
+ // Validate olderThanDays
40
+ const days = parseInt(olderThanDays, 10);
41
+ if (isNaN(days) || days < 1) {
42
+ return res.status(400).json({ success: false, error: 'olderThanDays must be a positive integer' });
43
+ }
44
+
45
+ console.log(`[mbkbucket] Starting cleanup of incomplete uploads older than ${days} days`);
46
+ const result = await cleanupIncompleteMultipartUploads(days, prefix);
47
+
48
+ res.json({
49
+ success: true,
50
+ message: `Cleaned up ${result.abortedCount} incomplete multipart upload(s)`,
51
+ ...result
52
+ });
53
+ } catch (error) {
54
+ console.error('[mbkbucket] Cleanup failed:', error);
55
+ res.status(500).json({
56
+ success: false,
57
+ error: error.message
58
+ });
59
+ }
60
+ });
61
+
62
+ // API endpoint to list incomplete multipart uploads
63
+ router.get('/api/incomplete-uploads', validateSessionAndRole('SuperAdmin'), async (req, res) => {
64
+ try {
65
+ const { prefix = '' } = req.query;
66
+ const uploads = await listIncompleteMultipartUploads(prefix);
67
+
68
+ res.json({
69
+ success: true,
70
+ count: uploads.length,
71
+ uploads: uploads.map(u => ({
72
+ key: u.Key,
73
+ uploadId: u.UploadId,
74
+ initiated: u.Initiated,
75
+ initiator: u.Initiator?.DisplayName
76
+ }))
77
+ });
78
+ } catch (error) {
79
+ console.error('[mbkbucket] Failed to list incomplete uploads:', error);
80
+ res.status(500).json({
81
+ success: false,
82
+ error: error.message
83
+ });
84
+ }
85
+ });
86
+
87
+ // API endpoint for fetching files
88
+ router.get('/api/files', validateSessionAndRole('SuperAdmin'), async (req, res) => {
89
+ const { prefix = '', page = '1', search = '', recursive = 'true', token = '' } = req.query;
90
+ const pageSize = 100;
91
+ let effectivePrefix;
92
+ try {
93
+ effectivePrefix = ensurePrefix(prefix);
94
+ } catch (e) {
95
+ return res.status(400).json({ success: false, error: e.message });
96
+ }
97
+
98
+ // Determine mode: Optimized (Folder View, No Search) vs Legacy/Deep (Flat View or Search)
99
+ const isSearch = search && search.trim().length > 0;
100
+ // If recursive is explicitly 'false', we respect it. Default to true if missing (though frontend should send it)
101
+ // Logic: Optimization works only if NOT recursive and NOT searching.
102
+ const isRecursive = recursive === 'true';
103
+ const useOptimizedListing = !isSearch && !isRecursive;
104
+
105
+ try {
106
+ let files = [];
107
+ let folders = []; // For CommonPrefixes (subfolders)
108
+ let nextContinuationToken = null;
109
+ let usedPrefix = effectivePrefix;
110
+ let legacyFallback = false;
111
+
112
+ if (useOptimizedListing) {
113
+ // --- OPTIMIZED PATH: S3 Delimiter (Folder View) ---
114
+ // We process only one page from S3. This reduces API calls significantly.
115
+
116
+ // FIX: Ensure root listing uses trailing slash to prevent "app-name" matching "app-name-backup"
117
+ // and ensure directory browsing works correctly if ensurePrefix didn't append slash (which it now does if present in input).
118
+ // But for root, input is empty, ensurePrefix returns "app", so we force "app/" here.
119
+ let listPrefix = effectivePrefix;
120
+ if (listPrefix === getAppName() && !listPrefix.endsWith('/')) {
121
+ listPrefix += '/';
122
+ }
123
+
124
+ const result = await listfiles(listPrefix, {
125
+ continuationToken: token || undefined, // Use token from query if provided
126
+ delimiter: '/',
127
+ maxKeys: 1000 // Fetch a healthy batch.
128
+ });
129
+
130
+ files = result.Contents || [];
131
+ // Filter out folder marker objects (zero-byte files ending with /)
132
+ files = files.filter(f => !f.Key.endsWith('/'));
133
+ // S3 returns CommonPrefixes for folders when delimiter is used
134
+ folders = (result.CommonPrefixes || []).map(p => p.Prefix).filter(p => p !== effectivePrefix);
135
+ nextContinuationToken = result.NextContinuationToken;
136
+
137
+ // Note: In optimized mode, totalFiles is unknown without scanning everything.
138
+ } else {
139
+ // --- LEGACY PATH: Recursive Scan (Search or Flat View) ---
140
+ let continuationToken = undefined;
141
+
142
+ // Fetch all files recursively (handling S3 pagination)
143
+ do {
144
+ const result = await listfiles(effectivePrefix, { continuationToken });
145
+ if (result.Contents) {
146
+ // Filter out folder marker objects (zero-byte files ending with /)
147
+ const actualFiles = result.Contents.filter(f => !f.Key.endsWith('/'));
148
+ files = files.concat(actualFiles);
149
+ }
150
+ continuationToken = result.nextToken;
151
+ } while (continuationToken);
152
+
153
+ // If no files found under the app prefixed path, try root as a legacy fallback
154
+ if (!files.length && !search) {
155
+ try {
156
+ const rootResult = await listfiles('');
157
+ if ((rootResult.Contents || []).length) {
158
+ files = rootResult.Contents || [];
159
+ usedPrefix = '';
160
+ legacyFallback = true;
161
+ }
162
+ } catch (fallbackErr) {
163
+ console.warn('Fallback root listing failed:', fallbackErr.message);
164
+ }
165
+ }
166
+
167
+ // Apply search filter if provided
168
+ if (isSearch) {
169
+ const searchLower = search.toLowerCase();
170
+ files = files.filter(file => {
171
+ return file.Key.toLowerCase().includes(searchLower);
172
+ });
173
+ }
174
+ }
175
+
176
+ // Response Construction
177
+ if (useOptimizedListing) {
178
+ res.json({
179
+ success: true,
180
+ files: files,
181
+ folders: folders,
182
+ prefix: effectivePrefix,
183
+ search: search,
184
+ // In optimized mode, we use token-based pagination, not page numbers
185
+ currentPage: 1,
186
+ totalPages: 1, // Always 1 since we use continuation tokens instead
187
+ hasNextPage: !!nextContinuationToken,
188
+ hasPrevPage: false, // Token-based pagination doesn't support backwards navigation
189
+ nextContinuationToken: nextContinuationToken,
190
+ mode: 'optimized',
191
+ totalFiles: -1, // Unknown in optimized mode without full scan
192
+ paginationType: 'continuation-token' // Indicate the type of pagination
193
+ });
194
+
195
+ } else {
196
+ // Legacy Pagination Logic (In-Memory)
197
+ const totalFiles = files.length;
198
+ const totalPages = Math.max(1, Math.ceil(totalFiles / pageSize));
199
+ const currentPage = Math.max(1, parseInt(page, 10) || 1);
200
+ const startIndex = (currentPage - 1) * pageSize;
201
+ const paginatedFiles = files.slice(startIndex, startIndex + pageSize);
202
+
203
+ res.json({
204
+ success: true,
205
+ files: paginatedFiles,
206
+ folders: [], // In recursive mode, frontend calculates folders from file paths
207
+ prefix: effectivePrefix,
208
+ search: search,
209
+ currentPage: currentPage,
210
+ totalPages,
211
+ hasNextPage: currentPage < totalPages,
212
+ hasPrevPage: currentPage > 1,
213
+ nextPage: currentPage + 1,
214
+ prevPage: Math.max(1, currentPage - 1),
215
+ totalFiles
216
+ });
217
+ }
218
+
219
+ } catch (error) {
220
+ console.error("Error listing files:", error);
221
+ res.status(500).json({
222
+ success: false,
223
+ error: "Error listing files: " + error.message,
224
+ files: [],
225
+ totalFiles: 0
226
+ });
227
+ }
228
+ });
229
+
230
+ // Standard single-file upload
231
+ router.post('/upload', validateSessionAndRole('SuperAdmin'), upload.single('file'), async (req, res) => {
232
+ try {
233
+ if (!req.file) {
234
+ return res.status(400).json({ success: false, error: 'No file selected' });
235
+ }
236
+
237
+ const { prefix = '' } = req.body;
238
+ let effectivePrefix;
239
+ try {
240
+ effectivePrefix = ensurePrefix(prefix);
241
+ } catch (e) {
242
+ return res.status(400).json({ success: false, error: e.message });
243
+ }
244
+
245
+ const key = `${effectivePrefix.replace(/\/+$/, '')}/${req.file.originalname}`;
246
+
247
+ const uploadOptions = {
248
+ metadata: {
249
+ 'original-name': req.file.originalname,
250
+ 'upload-source': 'web-portal',
251
+ 'user-agent': req.headers['user-agent'] || 'unknown'
252
+ },
253
+ preventOverwrite: true // Use atomic operation to prevent race conditions
254
+ };
255
+
256
+ try {
257
+ await uploadFile(key, req.file.buffer, req.file.mimetype, uploadOptions);
258
+
259
+ // Clean up folder marker if it exists in the parent directory
260
+ // This happens when a file is uploaded to a folder that was previously empty
261
+ const folderPath = key.substring(0, key.lastIndexOf('/') + 1);
262
+ if (folderPath) {
263
+ const folderMarkerKey = folderPath; // Already ends with /
264
+ try {
265
+ const markerExists = await fileExists(folderMarkerKey);
266
+ if (markerExists) {
267
+ // Check if this is actually a folder marker (zero-byte file)
268
+ const metadata = await getFileMetadata(folderMarkerKey);
269
+ if (metadata.ContentLength === 0 || metadata.Metadata?.marker === 'true') {
270
+ await deleteFile(folderMarkerKey);
271
+ console.log(`[mbkbucket] Cleaned up folder marker: ${folderMarkerKey}`);
272
+ }
273
+ }
274
+ } catch (cleanupErr) {
275
+ // Non-critical error, just log it
276
+ console.warn('[mbkbucket] Failed to clean up folder marker:', cleanupErr.message);
277
+ }
278
+ }
279
+
280
+ res.json({ success: true, message: 'File uploaded successfully', key: key });
281
+ } catch (uploadError) {
282
+ // Handle file already exists error from atomic operation
283
+ if (uploadError.message.includes('already exists')) {
284
+ return res.status(409).json({ success: false, error: `File already exists: ${req.file.originalname}` });
285
+ }
286
+ throw uploadError;
287
+ }
288
+ } catch (error) {
289
+ console.error("Error uploading file:", error);
290
+ res.status(500).json({ success: false, error: `Upload failed: ${error.message}` });
291
+ }
292
+ });
293
+
294
+ // S3 Multipart Upload — Step 1: Initiate
295
+ // Body: { fileName, prefix?, contentType? }
296
+ // Returns: { uploadId, key }
297
+ router.post('/upload-init', validateSessionAndRole('SuperAdmin'), async (req, res) => {
298
+ try {
299
+ const { fileName, prefix = '', contentType = 'application/octet-stream' } = req.body;
300
+ if (!fileName) return res.status(400).json({ success: false, error: 'fileName is required' });
301
+
302
+ let effectivePrefix;
303
+ try { effectivePrefix = ensurePrefix(prefix); } catch (e) { return res.status(400).json({ success: false, error: e.message }); }
304
+ const key = `${effectivePrefix.replace(/\/+$/, '')}/${fileName}`;
305
+
306
+ // Check if file exists before initiating multipart upload
307
+ // Note: This is still slightly racy, but multipart uploads take time so collision risk is lower
308
+ // A complete solution would require server-side locking or unique upload IDs
309
+ const exists = await fileExists(key);
310
+ if (exists) return res.status(409).json({ success: false, error: `File already exists: ${fileName}` });
311
+
312
+ const result = await createMultipartUpload(key, contentType);
313
+ return res.json({ success: true, uploadId: result.uploadId, key: result.key });
314
+ } catch (err) {
315
+ console.error('[mbkbucket] upload-init failed:', err);
316
+ return res.status(500).json({ success: false, error: err.message });
317
+ }
318
+ });
319
+
320
+ // S3 Multipart Upload — Step 2: Upload a part
321
+ // FormData: chunk (file), partNumber (1-based integer), uploadId, key
322
+ // Returns: { partNumber, ETag }
323
+ router.post('/upload-chunk', validateSessionAndRole('SuperAdmin'), uploadChunk, async (req, res) => {
324
+ try {
325
+ const { uploadId, key, partNumber } = req.body;
326
+ if (!req.file || !uploadId || !key || !partNumber) {
327
+ return res.status(400).json({ success: false, error: 'chunk file, uploadId, key, and partNumber are required' });
328
+ }
329
+ const part = parseInt(partNumber, 10);
330
+ if (isNaN(part) || part < 1 || part > 10000) {
331
+ return res.status(400).json({ success: false, error: 'partNumber must be an integer between 1 and 10000' });
332
+ }
333
+
334
+ const result = await uploadPart(key, uploadId, part, req.file.buffer);
335
+ return res.json({ success: true, partNumber: result.partNumber, ETag: result.ETag });
336
+ } catch (err) {
337
+ console.error('[mbkbucket] upload-chunk failed:', err);
338
+ return res.status(500).json({ success: false, error: err.message });
339
+ }
340
+ });
341
+
342
+ // S3 Multipart Upload — Step 3: Complete
343
+ // Body: { uploadId, key, parts: [{ partNumber, ETag }] }
344
+ // Returns: { key }
345
+ router.post('/upload-complete', validateSessionAndRole('SuperAdmin'), async (req, res) => {
346
+ try {
347
+ const { uploadId, key, parts } = req.body;
348
+ if (!uploadId || !key || !Array.isArray(parts) || !parts.length) {
349
+ return res.status(400).json({ success: false, error: 'uploadId, key, and parts array are required' });
350
+ }
351
+
352
+ const result = await completeMultipartUpload(key, uploadId, parts);
353
+
354
+ // Clean up folder marker if it exists in the parent directory
355
+ const folderPath = result.key.substring(0, result.key.lastIndexOf('/') + 1);
356
+ if (folderPath) {
357
+ const folderMarkerKey = folderPath;
358
+ try {
359
+ const markerExists = await fileExists(folderMarkerKey);
360
+ if (markerExists) {
361
+ const metadata = await getFileMetadata(folderMarkerKey);
362
+ if (metadata.ContentLength === 0 || metadata.Metadata?.marker === 'true') {
363
+ await deleteFile(folderMarkerKey);
364
+ console.log(`[mbkbucket] Cleaned up folder marker: ${folderMarkerKey}`);
365
+ }
366
+ }
367
+ } catch (cleanupErr) {
368
+ console.warn('[mbkbucket] Failed to clean up folder marker:', cleanupErr.message);
369
+ }
370
+ }
371
+
372
+ return res.json({ success: true, message: 'File uploaded successfully', key: result.key });
373
+ } catch (err) {
374
+ console.error('[mbkbucket] upload-complete failed:', err);
375
+ return res.status(500).json({ success: false, error: err.message });
376
+ }
377
+ });
378
+
379
+ // S3 Multipart Upload — Abort (cleanup on client cancel/error)
380
+ // Body: { uploadId, key }
381
+ router.post('/upload-abort', validateSessionAndRole('SuperAdmin'), async (req, res) => {
382
+ try {
383
+ const { uploadId, key } = req.body;
384
+ if (!uploadId || !key) return res.status(400).json({ success: false, error: 'uploadId and key are required' });
385
+
386
+ await abortMultipartUpload(key, uploadId);
387
+ return res.json({ success: true, message: 'Multipart upload aborted' });
388
+ } catch (err) {
389
+ console.error('[mbkbucket] upload-abort failed:', err);
390
+ return res.status(500).json({ success: false, error: err.message });
391
+ }
392
+ });
393
+
394
+ // Create folder (zero-byte object with trailing slash)
395
+ router.post('/create-folder', validateSessionAndRole('SuperAdmin'), async (req, res) => {
396
+ try {
397
+ const { prefix = '', folderName } = req.body;
398
+ if (!folderName) return res.status(400).json({ success: false, error: 'folderName is required' });
399
+
400
+ let effectivePrefix;
401
+ try { effectivePrefix = ensurePrefix(prefix); } catch (e) { return res.status(400).json({ success: false, error: e.message }); }
402
+
403
+ const folderKey = `${effectivePrefix.replace(/\/+$/, '')}/${folderName}/`;
404
+
405
+ // Check if folder marker already exists
406
+ const markerExists = await fileExists(folderKey);
407
+ if (markerExists) return res.status(409).json({ success: false, error: 'Folder already exists' });
408
+
409
+ // Check if any files already exist under this prefix (folder already has content)
410
+ const existingFiles = await listfiles(folderKey, { maxKeys: 1 });
411
+ const hasContent = existingFiles.Contents && existingFiles.Contents.length > 0;
412
+
413
+ if (hasContent) {
414
+ // Folder already exists with content, no need to create marker
415
+ return res.json({
416
+ success: true,
417
+ message: 'Folder already exists with content',
418
+ key: folderKey,
419
+ skipMarker: true
420
+ });
421
+ }
422
+
423
+ // Create zero-byte object to represent empty folder
424
+ await uploadFile(folderKey, Buffer.alloc(0), 'application/x-empty', {
425
+ metadata: { 'folder': 'true', 'marker': 'true' }
426
+ });
427
+
428
+ return res.json({ success: true, message: 'Folder created', key: folderKey });
429
+ } catch (err) {
430
+ console.error('Create folder failed:', err);
431
+ return res.status(500).json({ success: false, error: err.message });
432
+ }
433
+ });
434
+
435
+ router.post('/delete', validateSessionAndRole('SuperAdmin'), async (req, res) => {
436
+ try {
437
+ const { key, keys, folder } = req.body;
438
+
439
+ if (keys && Array.isArray(keys) && keys.length) {
440
+ // Bulk delete
441
+ await deleteFiles(keys);
442
+ return res.json({ success: true, message: 'Files deleted successfully' });
443
+ }
444
+
445
+ if (!key) return res.status(400).json({ success: false, error: 'Key is required' });
446
+
447
+ let keyToDelete;
448
+ try { keyToDelete = ensureKeyHasAppPrefix(key); } catch (e) { return res.status(400).json({ success: false, error: e.message }); }
449
+
450
+ // If caller indicates it's a folder (or key ends with '/'), delete all objects under the prefix
451
+ if (folder === true || String(keyToDelete).endsWith('/')) {
452
+ await deleteFolder(keyToDelete);
453
+ return res.json({ success: true, message: 'Folder deleted successfully' });
454
+ }
455
+
456
+ await deleteFile(keyToDelete);
457
+ res.json({ success: true, message: 'File deleted successfully' });
458
+ } catch (error) {
459
+ console.error("Error deleting file:", error);
460
+ res.status(500).json({ success: false, error: `Delete failed: ${error.message}` });
461
+ }
462
+ });
463
+
464
+ router.get('/download/:key(*)', validateSessionAndRole('SuperAdmin'), async (req, res) => {
465
+ let stream = null;
466
+ try {
467
+ const key = req.params.key;
468
+ let keyToUse;
469
+ try {
470
+ keyToUse = ensureKeyHasAppPrefix(key);
471
+ } catch (e) {
472
+ return res.status(400).json({ success: false, error: e.message });
473
+ }
474
+ const result = await downloadFile(keyToUse);
475
+ stream = result.Body;
476
+
477
+ res.setHeader('Content-Disposition', `attachment; filename="${keyToUse.split('/').pop()}"`);
478
+ res.setHeader('Content-Type', result.ContentType || 'application/octet-stream');
479
+
480
+ // Set Content-Length header for proper download progress indication
481
+ if (result.ContentLength) {
482
+ res.setHeader('Content-Length', result.ContentLength);
483
+ }
484
+
485
+ // Add cache headers for downloads
486
+ res.setHeader('Cache-Control', 'private, max-age=3600');
487
+
488
+ // Proper stream error handling
489
+ stream.on('error', (err) => {
490
+ console.error('Download stream error:', err);
491
+ if (!res.headersSent) {
492
+ res.status(500).json({ message: 'Error streaming file', error: err.message });
493
+ }
494
+ if (stream && typeof stream.destroy === 'function') stream.destroy();
495
+ });
496
+
497
+ // Clean up on client disconnect
498
+ req.on('close', () => {
499
+ if (stream && typeof stream.destroy === 'function') stream.destroy();
500
+ });
501
+
502
+ // Handle request timeout
503
+ const timeoutDuration = result.ContentLength > 50 * 1024 * 1024 ? 300000 : 120000;
504
+ req.setTimeout(timeoutDuration, () => {
505
+ console.error(`Download timeout (${timeoutDuration}ms) for: ${keyToUse}`);
506
+ if (stream && typeof stream.destroy === 'function') stream.destroy();
507
+ });
508
+
509
+ stream.pipe(res);
510
+ }
511
+ catch (error) {
512
+ console.error("Error downloading file:", error);
513
+
514
+ // Clean up stream on error
515
+ if (stream && typeof stream.destroy === 'function') stream.destroy();
516
+ if (error.message.includes('File not found')) {
517
+ res.status(404).json({ message: "File not found", key: req.params.key });
518
+ } else if (error.message.includes('Access denied')) {
519
+ res.status(403).json({ message: "Access denied" });
520
+ } else {
521
+ res.status(500).json({ message: "Download failed", error: error.message });
522
+ }
523
+ }
524
+ });
525
+
526
+ export default router;
@@ -0,0 +1,17 @@
1
+ import express from "express";
2
+ import infoRoutes from "./info.js";
3
+ import viewRoutes from "./view.js";
4
+ import apiRoutes from "./api.js";
5
+ import { validateSessionAndRole, renderPage, mbkautheVar } from "mbkauthe";
6
+
7
+ const router = express.Router();
8
+
9
+ router.get('/mbkbucket', validateSessionAndRole('SuperAdmin'), async (req, res) => {
10
+ renderPage(req, res, "bucket.handlebars", false, { page: "Admin Bucket", bucketvar: mbkautheVar?.bucket, APP_NAME: mbkautheVar?.APP_NAME, message: req.query.message, error: req.query.error });
11
+ });
12
+
13
+ router.use("/mbkbucket", infoRoutes);
14
+ router.use("/mbkbucket", viewRoutes);
15
+ router.use("/mbkbucket", apiRoutes);
16
+
17
+ export default router;
@@ -0,0 +1,28 @@
1
+ import express from "express";
2
+ import { renderPage, mbkautheVar } from "mbkauthe";
3
+ import { packageJson, getLatestVersion } from "../config/index.js";
4
+
5
+ const router = express.Router();
6
+
7
+ router.get(['/info', "/i"], async (req, res) => {
8
+ let latestVersion = 'unknown';
9
+ try {
10
+ latestVersion = await getLatestVersion();
11
+ } catch (err) {
12
+ console.error("[mbkauthe] Error fetching package-lock.json:", err);
13
+ }
14
+ renderPage(req, res, "mbkbucket_info.handlebars", false, { page: "MBK Bucket Info", CurrentVersion: packageJson.version, latestVersion, APP_NAME: mbkautheVar?.APP_NAME });
15
+ });
16
+
17
+
18
+ router.get(['/info.json', "/i.json"], async (req, res) => {
19
+ let latestVersion = 'unknown';
20
+ try {
21
+ latestVersion = await getLatestVersion();
22
+ } catch (err) {
23
+ console.error("[mbkauthe] Error fetching package-lock.json:", err);
24
+ }
25
+ res.json({CurrentVersion:packageJson.version, latestVersion, APP_NAME: mbkautheVar?.APP_NAME });
26
+ });
27
+
28
+ export default router;