mbkbucket 3.5.0 โ 3.6.0
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/.env.example +14 -14
- package/.mbkbucket.config.example.json +14 -14
- package/LICENSE +20 -20
- package/README.md +377 -350
- package/index.js +30 -30
- package/lib/cli.js +649 -649
- package/lib/public/bucketadmin.css +1420 -1420
- package/lib/public/bucketadmin.js +1229 -1229
- package/lib/public/mbkbucket-helper-demo.html +1184 -1184
- package/lib/public/mbkbucket-helper.css +1235 -1235
- package/lib/public/mbkbucket-helper.js +1557 -1557
- package/lib/src/app.js +109 -109
- package/lib/src/cli/auth-helper.js +150 -150
- package/lib/src/config/index.js +112 -112
- package/lib/src/config/validation.js +73 -73
- package/lib/src/controllers/api.controller.js +410 -410
- package/lib/src/controllers/dashboard.controller.js +48 -48
- package/lib/src/controllers/info.controller.js +34 -34
- package/lib/src/controllers/view.controller.js +233 -233
- package/lib/src/middleware/async-handler.js +23 -23
- package/lib/src/middleware/bucket-resolver.js +37 -37
- package/lib/src/middleware/error-handler.js +54 -54
- package/lib/src/middleware/rate-limiter.js +22 -22
- package/lib/src/middleware/security.js +27 -27
- package/lib/src/routes/api.routes.js +54 -40
- package/lib/src/routes/index.js +40 -21
- package/lib/src/routes/info.routes.js +9 -9
- package/lib/src/routes/view.routes.js +25 -20
- package/lib/src/services/s3.service.js +603 -603
- package/lib/src/utils/errors.js +54 -54
- package/lib/src/utils/helpers.js +251 -251
- package/lib/src/utils/logger.js +17 -17
- package/package.json +83 -83
- package/views/bucket.handlebars +196 -196
- package/views/bucketadmin_alerts.handlebars +15 -15
- package/views/bucketadmin_delete_modal.handlebars +36 -36
- package/views/bucketadmin_filelist_skeleton.handlebars +32 -32
- package/views/bucketadmin_newfolder_modal.handlebars +29 -29
- package/views/bucketadmin_preview_modal.handlebars +40 -40
- package/views/bucketadmin_upload_modal.handlebars +54 -54
- package/views/bucketadmincontent.handlebars +141 -141
- package/views/mbkbucket_info.handlebars +232 -232
package/README.md
CHANGED
|
@@ -1,351 +1,378 @@
|
|
|
1
|
-
# mbkbucket
|
|
2
|
-
|
|
3
|
-
> Flexible S3/R2 bucket management โ library, Express router, and CLI for mbktech.org applications.
|
|
4
|
-
|
|
5
|
-
[](https://www.npmjs.com/package/mbkbucket)
|
|
6
|
-
[](https://www.npmjs.com/package/mbkbucket)
|
|
7
|
-
[](LICENSE)
|
|
8
|
-
[](https://nodejs.org/)
|
|
9
|
-
[](https://github.com/MIbnEKhalid/mbkbucket/actions/workflows/publish.yml)
|
|
10
|
-
|
|
11
|
-
---
|
|
12
|
-
|
|
13
|
-
## Table of Contents
|
|
14
|
-
|
|
15
|
-
- [Installation](#installation-)
|
|
16
|
-
- [Quick Start](#quick-start-)
|
|
17
|
-
- [CLI Usage](#cli-usage-)
|
|
18
|
-
- [Library API](#library-api-)
|
|
19
|
-
- [Express Router](#express-router-)
|
|
20
|
-
- [Environment Configuration](#environment-configuration-)
|
|
21
|
-
- [Supported Storage Providers](#supported-storage-providers-)
|
|
22
|
-
- [Tests](#automated-tests-)
|
|
23
|
-
- [Support](#contact--support)
|
|
24
|
-
|
|
25
|
-
---
|
|
26
|
-
|
|
27
|
-
## Installation ๐ฆ
|
|
28
|
-
|
|
29
|
-
```bash
|
|
30
|
-
npm install mbkbucket
|
|
31
|
-
```
|
|
32
|
-
|
|
33
|
-
---
|
|
34
|
-
|
|
35
|
-
## Quick Start ๐
|
|
36
|
-
|
|
37
|
-
### As a Library
|
|
38
|
-
|
|
39
|
-
```js
|
|
40
|
-
import { uploadFile, downloadFile, listfiles, deleteFile, deleteFolder, getFileMetadata, generateSignedUrl,
|
|
41
|
-
bucket, // Express router
|
|
42
|
-
packageJson // Package metadata
|
|
43
|
-
} from 'mbkbucket';
|
|
44
|
-
|
|
45
|
-
// Upload a file
|
|
46
|
-
const result = await uploadFile(
|
|
47
|
-
'photos/sunset.jpg',
|
|
48
|
-
fileBuffer,
|
|
49
|
-
'image/jpeg',
|
|
50
|
-
{ bucketName: 'R2_Bucket' }
|
|
51
|
-
);
|
|
52
|
-
|
|
53
|
-
// List files
|
|
54
|
-
const { Contents, hasMore } = await listfiles('photos/', {
|
|
55
|
-
delimiter: '/',
|
|
56
|
-
maxKeys: 100
|
|
57
|
-
});
|
|
58
|
-
|
|
59
|
-
// Download a file
|
|
60
|
-
const { Body, ContentType } = await downloadFile('photos/sunset.jpg');
|
|
61
|
-
|
|
62
|
-
// Generate a pre-signed URL (valid for 1 hour)
|
|
63
|
-
const { url } = await generateSignedUrl('photos/sunset.jpg', 'getObject', 3600);
|
|
64
|
-
```
|
|
65
|
-
|
|
66
|
-
### As Express Middleware
|
|
67
|
-
|
|
68
|
-
```js
|
|
69
|
-
import mbkbucket from 'mbkbucket';
|
|
70
|
-
|
|
71
|
-
// mbkbucket is a fully configured Express app with auth, sessions, and bucket routes
|
|
72
|
-
mbkbucket.listen(3004, () => {
|
|
73
|
-
console.log('mbkbucket server running on http://localhost:3004');
|
|
74
|
-
});
|
|
75
|
-
```
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
|
139
|
-
|
|
140
|
-
|
|
|
141
|
-
|
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
|
158
|
-
|
|
159
|
-
|
|
|
160
|
-
|
|
|
161
|
-
|
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
| `
|
|
185
|
-
| `
|
|
186
|
-
| `
|
|
187
|
-
| `
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
|
192
|
-
|
|
193
|
-
| `
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
|
200
|
-
|
|
201
|
-
| `
|
|
202
|
-
| `
|
|
203
|
-
| `
|
|
204
|
-
| `
|
|
205
|
-
|
|
206
|
-
###
|
|
207
|
-
|
|
208
|
-
|
|
|
209
|
-
|---|---|
|
|
210
|
-
| `
|
|
211
|
-
| `
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
| `
|
|
222
|
-
| `
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
|
227
|
-
|
|
228
|
-
| `
|
|
229
|
-
| `
|
|
230
|
-
| `
|
|
231
|
-
| `
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
|
236
|
-
|
|
237
|
-
| `
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
|
247
|
-
|
|
248
|
-
| `
|
|
249
|
-
| `
|
|
250
|
-
| `
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
|
269
|
-
|
|
270
|
-
| `
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
```
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
---
|
|
340
|
-
|
|
341
|
-
##
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
1
|
+
# mbkbucket
|
|
2
|
+
|
|
3
|
+
> Flexible S3/R2 bucket management โ library, Express router, and CLI for mbktech.org applications.
|
|
4
|
+
|
|
5
|
+
[](https://www.npmjs.com/package/mbkbucket)
|
|
6
|
+
[](https://www.npmjs.com/package/mbkbucket)
|
|
7
|
+
[](LICENSE)
|
|
8
|
+
[](https://nodejs.org/)
|
|
9
|
+
[](https://github.com/MIbnEKhalid/mbkbucket/actions/workflows/publish.yml)
|
|
10
|
+
|
|
11
|
+
---
|
|
12
|
+
|
|
13
|
+
## Table of Contents
|
|
14
|
+
|
|
15
|
+
- [Installation](#installation-)
|
|
16
|
+
- [Quick Start](#quick-start-)
|
|
17
|
+
- [CLI Usage](#cli-usage-)
|
|
18
|
+
- [Library API](#library-api-)
|
|
19
|
+
- [Express Router](#express-router-)
|
|
20
|
+
- [Environment Configuration](#environment-configuration-)
|
|
21
|
+
- [Supported Storage Providers](#supported-storage-providers-)
|
|
22
|
+
- [Tests](#automated-tests-)
|
|
23
|
+
- [Support](#contact--support)
|
|
24
|
+
|
|
25
|
+
---
|
|
26
|
+
|
|
27
|
+
## Installation ๐ฆ
|
|
28
|
+
|
|
29
|
+
```bash
|
|
30
|
+
npm install mbkbucket
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
---
|
|
34
|
+
|
|
35
|
+
## Quick Start ๐
|
|
36
|
+
|
|
37
|
+
### As a Library
|
|
38
|
+
|
|
39
|
+
```js
|
|
40
|
+
import { uploadFile, downloadFile, listfiles, deleteFile, deleteFolder, getFileMetadata, generateSignedUrl,
|
|
41
|
+
bucket, // Express router
|
|
42
|
+
packageJson // Package metadata
|
|
43
|
+
} from 'mbkbucket';
|
|
44
|
+
|
|
45
|
+
// Upload a file
|
|
46
|
+
const result = await uploadFile(
|
|
47
|
+
'photos/sunset.jpg',
|
|
48
|
+
fileBuffer,
|
|
49
|
+
'image/jpeg',
|
|
50
|
+
{ bucketName: 'R2_Bucket' }
|
|
51
|
+
);
|
|
52
|
+
|
|
53
|
+
// List files
|
|
54
|
+
const { Contents, hasMore } = await listfiles('photos/', {
|
|
55
|
+
delimiter: '/',
|
|
56
|
+
maxKeys: 100
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
// Download a file
|
|
60
|
+
const { Body, ContentType } = await downloadFile('photos/sunset.jpg');
|
|
61
|
+
|
|
62
|
+
// Generate a pre-signed URL (valid for 1 hour)
|
|
63
|
+
const { url } = await generateSignedUrl('photos/sunset.jpg', 'getObject', 3600);
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
### As Express Middleware
|
|
67
|
+
|
|
68
|
+
```js
|
|
69
|
+
import mbkbucket from 'mbkbucket';
|
|
70
|
+
|
|
71
|
+
// mbkbucket is a fully configured Express app with auth, sessions, and bucket routes
|
|
72
|
+
mbkbucket.listen(3004, () => {
|
|
73
|
+
console.log('mbkbucket server running on http://localhost:3004');
|
|
74
|
+
});
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
### Host-controlled permissions
|
|
78
|
+
|
|
79
|
+
The default `bucket` router remains superadmin-only. A host application can
|
|
80
|
+
provide its own mbkauthe permission instead:
|
|
81
|
+
|
|
82
|
+
```js
|
|
83
|
+
import { createBucketRouter } from 'mbkbucket';
|
|
84
|
+
import { sessPerm } from 'mbkauthe';
|
|
85
|
+
import { Permissions } from './permissions.js';
|
|
86
|
+
|
|
87
|
+
app.use(createBucketRouter({
|
|
88
|
+
authorization: {
|
|
89
|
+
view: sessPerm(Permissions.storage.view),
|
|
90
|
+
upload: sessPerm(Permissions.storage.upload),
|
|
91
|
+
delete: sessPerm(Permissions.storage.delete),
|
|
92
|
+
},
|
|
93
|
+
}));
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
Define `Permissions.storage.view`, `Permissions.storage.upload`, and
|
|
97
|
+
`Permissions.storage.delete` in the host application's permission manifest and
|
|
98
|
+
sync that manifest with mbkauthe. The supplied middleware controls the
|
|
99
|
+
dashboard, private views, and bucket APIs; public views and info endpoints keep
|
|
100
|
+
their existing behavior. When no middleware is supplied, mbkbucket uses
|
|
101
|
+
`sessRole('superadmin')` for every private operation. A single middleware may
|
|
102
|
+
also be passed as `authorization` to protect all three operations uniformly.
|
|
103
|
+
|
|
104
|
+
The Express app includes:
|
|
105
|
+
- **`/mbkbucket`** โ Admin dashboard (superadmin only)
|
|
106
|
+
- **`/mbkbucket/api/*`** โ REST API for file operations
|
|
107
|
+
- **`/mbkbucket/p_view/:key(*)`** โ Public file view
|
|
108
|
+
- **`/mbkbucket/info`** โ Health & config info
|
|
109
|
+
|
|
110
|
+
---
|
|
111
|
+
|
|
112
|
+
## CLI Usage ๐ป
|
|
113
|
+
|
|
114
|
+
> **โ ๏ธ Under active development.** The CLI is functional but some features may change.
|
|
115
|
+
|
|
116
|
+
mbkbucket ships with a command-line interface for managing buckets directly from the terminal.
|
|
117
|
+
|
|
118
|
+
### Setup
|
|
119
|
+
|
|
120
|
+
```bash
|
|
121
|
+
# Set your mbkauthe server URL (one-time)
|
|
122
|
+
mbkbucket config set serverUrl https://your-server.example.com
|
|
123
|
+
|
|
124
|
+
# Set your API token profile key (one-time, optional)
|
|
125
|
+
mbkbucket config set profileKey your-profile-key
|
|
126
|
+
|
|
127
|
+
# Authenticate via device flow
|
|
128
|
+
mbkbucket login
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
### Commands
|
|
132
|
+
|
|
133
|
+
| Command | Alias | Description |
|
|
134
|
+
|---|---|---|
|
|
135
|
+
| `mbkbucket login` | โ | Authenticate via mbkauthe device flow |
|
|
136
|
+
| `mbkbucket logout` | โ | Clear stored credentials |
|
|
137
|
+
| `mbkbucket whoami` | โ | Show login status |
|
|
138
|
+
| | | |
|
|
139
|
+
| `mbkbucket list [prefix]` | `ls` | List files and folders |
|
|
140
|
+
| `mbkbucket upload <file> [key]` | `up` | Upload a file or folder |
|
|
141
|
+
| `mbkbucket download <key> [dest]` | `dl` | Download a file or folder |
|
|
142
|
+
| `mbkbucket delete <key>` | `rm` | Delete a file |
|
|
143
|
+
| `mbkbucket delete-folder <prefix>` | `rmdir` | Recursively delete a folder |
|
|
144
|
+
| `mbkbucket info <key>` | `stat` | Show file metadata (size, type, etc.) |
|
|
145
|
+
| `mbkbucket signed-url <key>` | `sign` | Generate a pre-signed download URL |
|
|
146
|
+
| | | |
|
|
147
|
+
| `mbkbucket config` | `cfg` | Show all config values |
|
|
148
|
+
| `mbkbucket config get <key>` | โ | Get a specific config value |
|
|
149
|
+
| `mbkbucket config set <k> <v>` | โ | Set a config value |
|
|
150
|
+
| `mbkbucket config unset <key>` | โ | Remove a config value |
|
|
151
|
+
| `mbkbucket config path` | โ | Show config file location |
|
|
152
|
+
| `mbkbucket config reset` | โ | Reset to demo values |
|
|
153
|
+
| `mbkbucket config edit` | โ | Open config file in editor |
|
|
154
|
+
|
|
155
|
+
### Global Options
|
|
156
|
+
|
|
157
|
+
| Flag | Description |
|
|
158
|
+
|---|---|
|
|
159
|
+
| `--app`, `-a <name>` | Override `APP_NAME` for key prefix isolation |
|
|
160
|
+
| `--bucket`, `-b <name>` | Override default bucket name |
|
|
161
|
+
| `--help`, `-h` | Show help |
|
|
162
|
+
|
|
163
|
+
### Login Options
|
|
164
|
+
|
|
165
|
+
| Flag | Description |
|
|
166
|
+
|---|---|
|
|
167
|
+
| `--server <url>` | mbkauthe server URL |
|
|
168
|
+
| `--profile-key <k>` | API token profile key |
|
|
169
|
+
|
|
170
|
+
### Config File
|
|
171
|
+
|
|
172
|
+
CLI configuration is stored at `~/.mbkbucket/config.json`. A demo config is created automatically on first use.
|
|
173
|
+
|
|
174
|
+
---
|
|
175
|
+
|
|
176
|
+
## Library API ๐
|
|
177
|
+
|
|
178
|
+
All functions are exported from the package root. Full TypeScript declarations in [index.d.ts](index.d.ts).
|
|
179
|
+
|
|
180
|
+
### File Operations
|
|
181
|
+
|
|
182
|
+
| Function | Description |
|
|
183
|
+
|---|---|
|
|
184
|
+
| `uploadFile(key, buffer, contentType, options?)` | Upload a file |
|
|
185
|
+
| `downloadFile(key, options?)` | Download a file |
|
|
186
|
+
| `deleteFile(key, bucketName?)` | Delete a single file |
|
|
187
|
+
| `deleteFiles(keys, bucketName?)` | Batch delete up to 1000 files |
|
|
188
|
+
| `deleteFolder(prefix, bucketName?)` | Recursively delete all files under a prefix |
|
|
189
|
+
| `listfiles(prefix?, options?)` | List files with pagination and filtering |
|
|
190
|
+
| `getFileMetadata(key, bucketName?)` | Get file metadata without downloading |
|
|
191
|
+
| `fileExists(key, bucketName?)` | Check if a file exists |
|
|
192
|
+
| `getFileSize(key, bucketName?)` | Get file size in bytes |
|
|
193
|
+
| `generateSignedUrl(key, operation?, expiresIn?, bucketName?)` | Generate a pre-signed URL |
|
|
194
|
+
|
|
195
|
+
### Multipart Upload
|
|
196
|
+
|
|
197
|
+
| Function | Description |
|
|
198
|
+
|---|---|
|
|
199
|
+
| `createMultipartUpload(key, contentType?, metadata?, bucketName?)` | Start a multipart upload |
|
|
200
|
+
| `uploadPart(key, uploadId, partNumber, buffer, bucketName?)` | Upload a single part |
|
|
201
|
+
| `completeMultipartUpload(key, uploadId, parts, bucketName?)` | Complete a multipart upload |
|
|
202
|
+
| `abortMultipartUpload(key, uploadId, bucketName?)` | Abort a multipart upload |
|
|
203
|
+
| `listIncompleteMultipartUploads(prefix?, bucketName?)` | List incomplete uploads |
|
|
204
|
+
| `cleanupIncompleteMultipartUploads(olderThanDays?, prefix?, bucketName?)` | Clean up stale uploads |
|
|
205
|
+
|
|
206
|
+
### Bucket Management
|
|
207
|
+
|
|
208
|
+
| Function | Description |
|
|
209
|
+
|---|---|
|
|
210
|
+
| `getAvailableBucketNames()` | List configured bucket names |
|
|
211
|
+
| `resolveBucketName(bucketName?)` | Resolve and validate a bucket name |
|
|
212
|
+
| `getBucketConfig(bucketName?)` | Get bucket credentials/config |
|
|
213
|
+
| `getBucketClient(bucketName?)` | Get an S3 client instance |
|
|
214
|
+
| `checkHealth()` | Check S3 connectivity |
|
|
215
|
+
|
|
216
|
+
### Key Prefixing
|
|
217
|
+
|
|
218
|
+
| Function | Description |
|
|
219
|
+
|---|---|
|
|
220
|
+
| `ensureKeyHasAppPrefix(key?)` | Prefix a key with the app name |
|
|
221
|
+
| `ensurePrefix(prefix?)` | Prefix a folder path with the app name |
|
|
222
|
+
| `getAppName()` | Get the current app name |
|
|
223
|
+
|
|
224
|
+
### Config
|
|
225
|
+
|
|
226
|
+
| Export | Description |
|
|
227
|
+
|---|---|
|
|
228
|
+
| `packageJson` | Package metadata (version, etc.) |
|
|
229
|
+
| `appVersion` | Parent project version |
|
|
230
|
+
| `mbkbucketVar` | Parsed mbkbucketVar config |
|
|
231
|
+
| `checkVersion()` | Check for newer package versions |
|
|
232
|
+
|
|
233
|
+
### Express
|
|
234
|
+
|
|
235
|
+
| Export | Description |
|
|
236
|
+
|---|---|
|
|
237
|
+
| `bucket` (named) | Express Router with all bucket routes |
|
|
238
|
+
| `default` | Fully configured Express application |
|
|
239
|
+
|
|
240
|
+
---
|
|
241
|
+
|
|
242
|
+
## Express Router ๐ฅ๏ธ
|
|
243
|
+
|
|
244
|
+
### Routes
|
|
245
|
+
|
|
246
|
+
| Route | Auth | Description |
|
|
247
|
+
|---|---|---|
|
|
248
|
+
| `GET /mbkbucket` | superadmin | Admin dashboard |
|
|
249
|
+
| `GET /mbkbucket/info` | Any | Health check & config info |
|
|
250
|
+
| `GET /mbkbucket/p_view/:key(*)` | Public | Public file viewer |
|
|
251
|
+
| `POST /mbkbucket/api/list` | superadmin | List files (JSON) |
|
|
252
|
+
| `POST /mbkbucket/api/upload` | superadmin | Upload file(s) |
|
|
253
|
+
| `POST /mbkbucket/api/delete` | superadmin | Delete file(s) |
|
|
254
|
+
| `POST /mbkbucket/api/delete-folder` | superadmin | Delete folder |
|
|
255
|
+
| `POST /mbkbucket/api/create-folder` | superadmin | Create folder marker |
|
|
256
|
+
| `POST /mbkbucket/api/rename` | superadmin | Rename/move a file |
|
|
257
|
+
| `GET /mbkbucket/api/download/:key(*)` | superadmin | Download a file |
|
|
258
|
+
| `GET /mbkbucket/api/metadata/:key(*)` | superadmin | Get file metadata |
|
|
259
|
+
| `POST /mbkbucket/api/multipart/init` | superadmin | Init multipart upload |
|
|
260
|
+
| `POST /mbkbucket/api/multipart/part` | superadmin | Upload multipart chunk |
|
|
261
|
+
| `POST /mbkbucket/api/multipart/complete` | superadmin | Complete multipart |
|
|
262
|
+
| `POST /mbkbucket/api/multipart/abort` | superadmin | Abort multipart |
|
|
263
|
+
| `GET /mbkbucket/api/multipart/list` | superadmin | List incomplete uploads |
|
|
264
|
+
| `POST /mbkbucket/api/multipart/cleanup` | superadmin | Clean up stale uploads |
|
|
265
|
+
|
|
266
|
+
### Views
|
|
267
|
+
|
|
268
|
+
| Template | Description |
|
|
269
|
+
|---|---|
|
|
270
|
+
| `bucketportal.handlebars` | Admin dashboard shell |
|
|
271
|
+
| `bucketadmincontent.handlebars` | File listing & management UI |
|
|
272
|
+
| `bucketadmin_alerts.handlebars` | Alert/notification partial |
|
|
273
|
+
| `bucketadmin_delete_modal.handlebars` | Delete confirmation modal |
|
|
274
|
+
| `bucketadmin_preview_modal.handlebars` | File preview modal |
|
|
275
|
+
| `bucketadmin_filelist_skeleton.handlebars` | Loading skeleton |
|
|
276
|
+
| `bucket.handlebars` | Public file viewer |
|
|
277
|
+
| `mbkbucket_info.handlebars` | Info/health page |
|
|
278
|
+
|
|
279
|
+
---
|
|
280
|
+
|
|
281
|
+
## Environment Configuration โ๏ธ
|
|
282
|
+
|
|
283
|
+
### `BucketConnection` (required)
|
|
284
|
+
|
|
285
|
+
JSON mapping of bucket names to S3-compatible credentials:
|
|
286
|
+
|
|
287
|
+
```env
|
|
288
|
+
BucketConnection={"R2_Bucket":{"BUCKET_NAME":"my-bucket","ACCESS_KEY_ID":"...","SECRET_ACCESS_KEY":"...","ENDPOINT":"https://<id>.r2.cloudflarestorage.com"}}
|
|
289
|
+
```
|
|
290
|
+
|
|
291
|
+
| Field | Required | Description |
|
|
292
|
+
|---|---|---|
|
|
293
|
+
| `BUCKET_NAME` | Yes | Target bucket name |
|
|
294
|
+
| `ACCESS_KEY_ID` | Yes | Access key |
|
|
295
|
+
| `SECRET_ACCESS_KEY` | Yes | Secret key |
|
|
296
|
+
| `ENDPOINT` | Yes | S3-compatible endpoint URL |
|
|
297
|
+
| `region` | No | AWS region (default: `auto`) |
|
|
298
|
+
|
|
299
|
+
### `mbkautheVar` (required)
|
|
300
|
+
|
|
301
|
+
Standard mbkauthe configuration. Key fields for mbkbucket:
|
|
302
|
+
|
|
303
|
+
| Field | Description |
|
|
304
|
+
|---|---|
|
|
305
|
+
| `APP_NAME` | App name used for key prefix isolation |
|
|
306
|
+
| `bucket` | Default bucket name (falls back to first in `BucketConnection`) |
|
|
307
|
+
| `CLI_AUTH_ENABLED` | Enable CLI device-flow login (`"true"` / `"false"`) |
|
|
308
|
+
|
|
309
|
+
### `mbkbucketVar` (optional)
|
|
310
|
+
|
|
311
|
+
| Field | Default | Description |
|
|
312
|
+
|---|---|---|
|
|
313
|
+
| `publiView_enabled` | `"false"` | Enable public file viewer |
|
|
314
|
+
| `p_view_inline` | `"false"` | Show files inline vs download |
|
|
315
|
+
|
|
316
|
+
### Common Mistakes
|
|
317
|
+
|
|
318
|
+
```env
|
|
319
|
+
# โ Wrong โ inner object quoted as string
|
|
320
|
+
BucketConnection={"R2_Bucket":"{\"BUCKET_NAME\":\"...\"}"}
|
|
321
|
+
|
|
322
|
+
# โ
Correct โ proper JSON nesting
|
|
323
|
+
BucketConnection={"R2_Bucket":{"BUCKET_NAME":"...","ACCESS_KEY_ID":"...","SECRET_ACCESS_KEY":"...","ENDPOINT":"https://..."}}
|
|
324
|
+
```
|
|
325
|
+
|
|
326
|
+
---
|
|
327
|
+
|
|
328
|
+
## Supported Storage Providers ๐๏ธ
|
|
329
|
+
|
|
330
|
+
Any S3-compatible object storage:
|
|
331
|
+
|
|
332
|
+
- **AWS S3**
|
|
333
|
+
- **Cloudflare R2**
|
|
334
|
+
- **IDrive e2**
|
|
335
|
+
- **MinIO**
|
|
336
|
+
- **Backblaze B2** (via S3-compatible API)
|
|
337
|
+
- **DigitalOcean Spaces**
|
|
338
|
+
|
|
339
|
+
---
|
|
340
|
+
|
|
341
|
+
## Automated Tests ๐งช
|
|
342
|
+
|
|
343
|
+
```bash
|
|
344
|
+
npm test
|
|
345
|
+
```
|
|
346
|
+
|
|
347
|
+
Covers:
|
|
348
|
+
- `mbkbucketVar` parsing, defaults, and boolean normalization
|
|
349
|
+
- `BucketConnection` shape validation and required fields
|
|
350
|
+
|
|
351
|
+
---
|
|
352
|
+
|
|
353
|
+
## Contact & Support
|
|
354
|
+
|
|
355
|
+
- **Website**: [mbktech.org/Support](https://mbktech.org/Support/?Project=MIbnEKhalidWeb)
|
|
356
|
+
- **Email**: [support@mbktech.org](mailto:support@mbktech.org)
|
|
357
|
+
- **GitHub**: [MIbnEKhalid/mbkbucket](https://github.com/MIbnEKhalid/mbkbucket)
|
|
358
|
+
|
|
359
|
+
---
|
|
360
|
+
|
|
361
|
+
## About
|
|
362
|
+
|
|
363
|
+
Developed by [Muhammad Bin Khalid](https://github.com/MIbnEKhalid)
|
|
364
|
+
Part of [MBK Tech](https://mbktech.org/)
|
|
365
|
+
|
|
366
|
+
---
|
|
367
|
+
|
|
368
|
+
## License
|
|
369
|
+
|
|
370
|
+
Licensed under the MIT License. See [LICENSE](LICENSE) for details.
|
|
371
|
+
|
|
372
|
+
|
|
373
|
+
<!--
|
|
374
|
+
* MBKBucket
|
|
375
|
+
* Copyright (c) 2026 Muhammad Bin Khalid, MBKTech.org and contributors
|
|
376
|
+
* Licensed under the MIT License.
|
|
377
|
+
* Source: https://github.com/MIbnEKhalid/mbkbucket
|
|
351
378
|
-->
|