mbkbucket 1.3.0 → 1.4.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 +5 -2
- package/README.md +59 -14
- package/index.d.ts +67 -3
- package/index.js +4 -79
- package/lib/bucket.js +658 -405
- package/lib/config/index.js +134 -1
- package/lib/s3.js +297 -54
- package/package.json +2 -1
- package/public/bucketadmin.js +139 -33
- package/views/bucketadmincontent.handlebars +3 -2
- package/views/mbkbucket_info.handlebars +226 -0
- package/views/info.handlebars +0 -1056
package/.env.example
CHANGED
|
@@ -3,8 +3,11 @@ mbkauthShared={"Main_SECRET_TOKEN": 123,"DOMAIN":"mbktech.org","IS_DEPLOYED":"fa
|
|
|
3
3
|
# See @node_modules/mbkauthe/docs/env.md for more details
|
|
4
4
|
NODE_ENV=development
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
E2_Bucket={"BUCKET_NAME":"","ACCESS_KEY_ID":"","SECRET_ACCESS_KEY":"","ENDPOINT":"","Region":"ap-southeast-1"}
|
|
6
|
+
BucketConnection={"r2":{"BUCKET_NAME":"","ACCESS_KEY_ID":"","SECRET_ACCESS_KEY":"","ENDPOINT":""},"e2":{"BUCKET_NAME":"","ACCESS_KEY_ID":"","SECRET_ACCESS_KEY":"","ENDPOINT":"","Region":"ap-southeast-1"},"custom":{"BUCKET_NAME":"","ACCESS_KEY_ID":"","SECRET_ACCESS_KEY":"","ENDPOINT":"","Region":""}}
|
|
8
7
|
# Region is optional
|
|
9
8
|
|
|
9
|
+
mbkbucketVar={"publiView_enabled":"true","p_view_inline":"true"}
|
|
10
|
+
# publiView_enabled mean if this app storage is public or private. If true, then anyone can access the files if they have the link. If false, then only authenticated users can access the files.
|
|
11
|
+
# p_view_inline means if the file should be displayed inline in the browser (proxy) or redirect to s3 signed url if false.
|
|
12
|
+
|
|
10
13
|
PORT=3005
|
package/README.md
CHANGED
|
@@ -1,34 +1,44 @@
|
|
|
1
1
|
# mbkbucket
|
|
2
2
|
|
|
3
|
+
S3 Bucket manager for Node.js applications with Express integration.
|
|
4
|
+
|
|
3
5
|
[](https://www.npmjs.com/package/mbkbucket)
|
|
6
|
+
[](https://www.npmjs.com/package/mbkbucket)
|
|
4
7
|
[](LICENSE)
|
|
5
8
|
[](https://nodejs.org/)
|
|
6
|
-
[](https://github.com/MIbnEKhalid/mbkbucket/actions/workflows/publish.yml)
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
## Usage 📖
|
|
7
13
|
|
|
8
|
-
|
|
14
|
+
### Installation
|
|
9
15
|
|
|
10
|
-
Install:
|
|
16
|
+
Install the package via npm:
|
|
11
17
|
|
|
12
18
|
```bash
|
|
13
19
|
npm install mbkbucket
|
|
14
20
|
```
|
|
15
21
|
|
|
16
|
-
###
|
|
22
|
+
### Getting Started
|
|
17
23
|
|
|
18
|
-
|
|
24
|
+
#### Named imports from package root
|
|
19
25
|
|
|
20
26
|
```js
|
|
21
27
|
import { uploadFile, downloadFile, listfiles, getBucketConfig, packageJson, bucket } from 'mbkbucket';
|
|
22
28
|
```
|
|
23
29
|
|
|
24
|
-
|
|
30
|
+
#### Default aggregate import
|
|
31
|
+
|
|
32
|
+
This imports the configured Express server instance:
|
|
25
33
|
|
|
26
34
|
```js
|
|
27
35
|
import mbkbucket from 'mbkbucket';
|
|
28
|
-
// mbkbucket.
|
|
36
|
+
// Access bucket router via: mbkbucket.bucket
|
|
29
37
|
```
|
|
30
38
|
|
|
31
|
-
|
|
39
|
+
#### Direct subpath imports (optional)
|
|
40
|
+
|
|
41
|
+
For more granular control, import directly from submodules:
|
|
32
42
|
|
|
33
43
|
```js
|
|
34
44
|
import { uploadFile } from 'mbkbucket/lib/s3';
|
|
@@ -36,17 +46,52 @@ import { packageJson } from 'mbkbucket/lib/config/index';
|
|
|
36
46
|
import bucketRouter from 'mbkbucket/lib/bucket';
|
|
37
47
|
```
|
|
38
48
|
|
|
39
|
-
###
|
|
49
|
+
### Additional Information
|
|
40
50
|
|
|
41
51
|
- All functions, objects, and variables exported from `lib/` are re-exported at the package root for convenience.
|
|
42
|
-
-
|
|
43
|
-
- The default export
|
|
52
|
+
- TypeScript support with full type declarations (`index.d.ts`) for IDE intellisense and type safety.
|
|
53
|
+
- The default export is the configured Express `server` instance; access the `bucket` router as a named export.
|
|
54
|
+
- Supports Node.js 14.0.0 and higher with ES Modules.
|
|
44
55
|
|
|
45
56
|
---
|
|
46
57
|
|
|
58
|
+
## API Overview
|
|
59
|
+
|
|
60
|
+
- **uploadFile()** - Upload files to S3 bucket
|
|
61
|
+
- **downloadFile()** - Retrieve files from S3 bucket
|
|
62
|
+
- **listfiles()** - List contents of S3 bucket
|
|
63
|
+
- **getBucketConfig()** - Get current bucket configuration
|
|
64
|
+
- **bucket** - Express router with bucket management endpoints
|
|
65
|
+
|
|
66
|
+
For complete API documentation, refer to the TypeScript declarations in [index.d.ts](index.d.ts).
|
|
67
|
+
|
|
68
|
+
---
|
|
69
|
+
|
|
70
|
+
## Requirements
|
|
71
|
+
|
|
72
|
+
- Node.js >= 14.0.0
|
|
73
|
+
- AWS S3 credentials configured
|
|
74
|
+
- AWS SDK v3 compatible environment
|
|
47
75
|
|
|
48
|
-
|
|
76
|
+
---
|
|
77
|
+
|
|
78
|
+
## Contact & Support
|
|
79
|
+
|
|
80
|
+
For questions, issues, or contributions, please reach out:
|
|
81
|
+
|
|
82
|
+
- **Website**: [mbktech.org/Support](https://mbktech.org/Support/?Project=MIbnEKhalidWeb)
|
|
83
|
+
- **Email**: [support@mbktech.org](mailto:support@mbktech.org) or [chmuhammadbinkhalid28@gmail.com](mailto:chmuhammadbinkhalid28@gmail.com)
|
|
84
|
+
- **GitHub**: [MIbnEKhalid](https://github.com/MIbnEKhalid)
|
|
85
|
+
|
|
86
|
+
---
|
|
87
|
+
|
|
88
|
+
## About
|
|
89
|
+
|
|
90
|
+
Developed by [Muhammad Bin Khalid](https://github.com/MIbnEKhalid)
|
|
91
|
+
Part of [MBK Tech Studio](https://mbktech.org/)
|
|
92
|
+
|
|
93
|
+
---
|
|
49
94
|
|
|
50
|
-
|
|
95
|
+
## License
|
|
51
96
|
|
|
52
|
-
|
|
97
|
+
Licensed under the GPL-2.0 License. See [LICENSE](LICENSE) file for details.
|
package/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// Type definitions for mbkbucket 1.
|
|
1
|
+
// Type definitions for mbkbucket 1.4.0
|
|
2
2
|
// Project: https://github.com/MIbnEKhalid/mbkbucket
|
|
3
3
|
// Definitions by: Muhammad Bin Khalid <https://github.com/MIbnEKhalid">
|
|
4
4
|
|
|
@@ -35,7 +35,7 @@ export function getAppName(): string;
|
|
|
35
35
|
export function ensureKeyHasAppPrefix(key?: string): string;
|
|
36
36
|
export function ensurePrefix(prefix?: string): string;
|
|
37
37
|
export function getBucketClient(bucketName?: string): any;
|
|
38
|
-
export function
|
|
38
|
+
export function checkHealth(): Promise<{ status: string; responseTime?: number; bucket?: string; error?: string; checkedAt: string; region?: string }>;
|
|
39
39
|
|
|
40
40
|
export function uploadFile(
|
|
41
41
|
key: string,
|
|
@@ -120,6 +120,44 @@ export function generateSignedUrl(
|
|
|
120
120
|
generatedAt: string;
|
|
121
121
|
}>;
|
|
122
122
|
|
|
123
|
+
/**
|
|
124
|
+
* S3 Multipart Upload Functions
|
|
125
|
+
*/
|
|
126
|
+
export function createMultipartUpload(
|
|
127
|
+
key: string,
|
|
128
|
+
contentType?: string,
|
|
129
|
+
metadata?: Record<string, string>
|
|
130
|
+
): Promise<{ uploadId: string; key: string }>;
|
|
131
|
+
|
|
132
|
+
export function uploadPart(
|
|
133
|
+
key: string,
|
|
134
|
+
uploadId: string,
|
|
135
|
+
partNumber: number,
|
|
136
|
+
buffer: Buffer | Uint8Array
|
|
137
|
+
): Promise<{ ETag: string; partNumber: number }>;
|
|
138
|
+
|
|
139
|
+
export function completeMultipartUpload(
|
|
140
|
+
key: string,
|
|
141
|
+
uploadId: string,
|
|
142
|
+
parts: Array<{ partNumber: number; ETag: string }>
|
|
143
|
+
): Promise<{ key: string }>;
|
|
144
|
+
|
|
145
|
+
export function abortMultipartUpload(
|
|
146
|
+
key: string,
|
|
147
|
+
uploadId: string
|
|
148
|
+
): Promise<{ key: string; abortedAt: string }>;
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* Configuration variables from mbkbucket
|
|
152
|
+
*/
|
|
153
|
+
export interface ConfigVars {
|
|
154
|
+
publiView_enabled: boolean;
|
|
155
|
+
p_view_inline: boolean;
|
|
156
|
+
[key: string]: any;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
export const mbkbucketVar: ConfigVars;
|
|
160
|
+
|
|
123
161
|
/**
|
|
124
162
|
* Exported router from `lib/bucket` (re-exported at package root as `bucket`)
|
|
125
163
|
*/
|
|
@@ -161,7 +199,7 @@ declare module "mbkbucket/lib/s3" {
|
|
|
161
199
|
export function ensureKeyHasAppPrefix(key?: string): string;
|
|
162
200
|
export function ensurePrefix(prefix?: string): string;
|
|
163
201
|
export function getBucketClient(bucketName?: string): any;
|
|
164
|
-
export function
|
|
202
|
+
export function checkHealth(): Promise<{ status: string; responseTime?: number; bucket?: string; error?: string; checkedAt: string; region?: string }>;
|
|
165
203
|
export function uploadFile(
|
|
166
204
|
key: string,
|
|
167
205
|
fileBuffer: Buffer | Uint8Array,
|
|
@@ -237,11 +275,37 @@ declare module "mbkbucket/lib/s3" {
|
|
|
237
275
|
expiresAt: string;
|
|
238
276
|
generatedAt: string;
|
|
239
277
|
}>;
|
|
278
|
+
export function createMultipartUpload(
|
|
279
|
+
key: string,
|
|
280
|
+
contentType?: string,
|
|
281
|
+
metadata?: Record<string, string>
|
|
282
|
+
): Promise<{ uploadId: string; key: string }>;
|
|
283
|
+
export function uploadPart(
|
|
284
|
+
key: string,
|
|
285
|
+
uploadId: string,
|
|
286
|
+
partNumber: number,
|
|
287
|
+
buffer: Buffer | Uint8Array
|
|
288
|
+
): Promise<{ ETag: string; partNumber: number }>;
|
|
289
|
+
export function completeMultipartUpload(
|
|
290
|
+
key: string,
|
|
291
|
+
uploadId: string,
|
|
292
|
+
parts: Array<{ partNumber: number; ETag: string }>
|
|
293
|
+
): Promise<{ key: string }>;
|
|
294
|
+
export function abortMultipartUpload(
|
|
295
|
+
key: string,
|
|
296
|
+
uploadId: string
|
|
297
|
+
): Promise<{ key: string; abortedAt: string }>;
|
|
240
298
|
}
|
|
241
299
|
|
|
242
300
|
declare module "mbkbucket/lib/config/index" {
|
|
301
|
+
export interface ConfigVars {
|
|
302
|
+
publiView_enabled: boolean;
|
|
303
|
+
p_view_inline: boolean;
|
|
304
|
+
[key: string]: any;
|
|
305
|
+
}
|
|
243
306
|
export const packageJson: Record<string, any>;
|
|
244
307
|
export const appVersion: string;
|
|
308
|
+
export const mbkbucketVar: ConfigVars;
|
|
245
309
|
export function getLatestVersion(): Promise<string | null>;
|
|
246
310
|
export function checkVersion(): Promise<void>;
|
|
247
311
|
}
|
package/index.js
CHANGED
|
@@ -2,11 +2,11 @@ import express from "express";
|
|
|
2
2
|
import path from "path";
|
|
3
3
|
import dotenv from "dotenv";
|
|
4
4
|
import { fileURLToPath } from "url";
|
|
5
|
-
import
|
|
5
|
+
import mbkautheRoutes from "mbkauthe";
|
|
6
6
|
import { engine } from "express-handlebars";
|
|
7
7
|
import compression from "compression";
|
|
8
8
|
import rateLimit from 'express-rate-limit';
|
|
9
|
-
import
|
|
9
|
+
import bucketRoutes from "./lib/bucket.js";
|
|
10
10
|
import { checkVersion } from "./lib/config/index.js";
|
|
11
11
|
import { appVersion } from "./lib/config/index.js";
|
|
12
12
|
|
|
@@ -71,83 +71,8 @@ server.engine("handlebars", engine({
|
|
|
71
71
|
],
|
|
72
72
|
cache: process.env.NODE_ENV === "production",
|
|
73
73
|
helpers: {
|
|
74
|
-
formatDate: (date) => {
|
|
75
|
-
return new Date(date).toLocaleString('en-US', {
|
|
76
|
-
year: 'numeric',
|
|
77
|
-
month: 'long',
|
|
78
|
-
day: 'numeric',
|
|
79
|
-
hour: '2-digit',
|
|
80
|
-
minute: '2-digit',
|
|
81
|
-
second: '2-digit',
|
|
82
|
-
hour12: true
|
|
83
|
-
});
|
|
84
|
-
},
|
|
85
|
-
in: function (value, list) {
|
|
86
|
-
if (!list || !Array.isArray(list)) return false;
|
|
87
|
-
return list.includes(parseInt(value) || value);
|
|
88
|
-
},
|
|
89
|
-
trim: function (str) {
|
|
90
|
-
return str ? str.trim() : '';
|
|
91
|
-
},
|
|
92
74
|
eq: function (a, b) {
|
|
93
75
|
return a === b;
|
|
94
|
-
},
|
|
95
|
-
encodeURIComponent: function (str) {
|
|
96
|
-
return encodeURIComponent(str);
|
|
97
|
-
},
|
|
98
|
-
formatTimestamp: function (timestamp) {
|
|
99
|
-
return new Date(timestamp).toLocaleString();
|
|
100
|
-
},
|
|
101
|
-
jsonStringify: function (context) {
|
|
102
|
-
return JSON.stringify(context);
|
|
103
|
-
},
|
|
104
|
-
truncate: (str, len) => {
|
|
105
|
-
if (!str) return '';
|
|
106
|
-
if (str.length > len) {
|
|
107
|
-
return str.substring(0, len) + '...';
|
|
108
|
-
}
|
|
109
|
-
return str;
|
|
110
|
-
},
|
|
111
|
-
section: function (name, options) {
|
|
112
|
-
if (!this._sections) this._sections = {};
|
|
113
|
-
this._sections[name] = options.fn(this);
|
|
114
|
-
return null;
|
|
115
|
-
},
|
|
116
|
-
getCanonicalUrl: function (req, path) {
|
|
117
|
-
const protocol = req.protocol || 'https';
|
|
118
|
-
const host = req.get('host') || 'blog.mbktechstudio.com';
|
|
119
|
-
return `${protocol}://${host}${path}`;
|
|
120
|
-
},
|
|
121
|
-
index: function (array, idx) {
|
|
122
|
-
return array ? array[idx] : null;
|
|
123
|
-
},
|
|
124
|
-
add: function (a, b) {
|
|
125
|
-
return Number(a) + Number(b);
|
|
126
|
-
},
|
|
127
|
-
subtract: function (a, b) {
|
|
128
|
-
return Number(a) - Number(b);
|
|
129
|
-
},
|
|
130
|
-
gt: function (a, b) {
|
|
131
|
-
return Number(a) > Number(b);
|
|
132
|
-
},
|
|
133
|
-
gte: function (a, b) {
|
|
134
|
-
return Number(a) >= Number(b);
|
|
135
|
-
},
|
|
136
|
-
lte: function (a, b) {
|
|
137
|
-
return Number(a) <= Number(b);
|
|
138
|
-
},
|
|
139
|
-
and: function () {
|
|
140
|
-
return Array.prototype.slice.call(arguments, 0, -1).every(Boolean);
|
|
141
|
-
},
|
|
142
|
-
or: function () {
|
|
143
|
-
return Array.prototype.slice.call(arguments, 0, -1).some(Boolean);
|
|
144
|
-
},
|
|
145
|
-
range: function (start, end) {
|
|
146
|
-
const result = [];
|
|
147
|
-
for (let i = start; i < end; i++) {
|
|
148
|
-
result.push(i);
|
|
149
|
-
}
|
|
150
|
-
return result;
|
|
151
76
|
}
|
|
152
77
|
}
|
|
153
78
|
}));
|
|
@@ -159,9 +84,9 @@ server.set("views", [
|
|
|
159
84
|
path.join(__dirname, "../mbkauthe/views")
|
|
160
85
|
]);
|
|
161
86
|
|
|
162
|
-
server.use(
|
|
87
|
+
server.use(mbkautheRoutes);
|
|
163
88
|
server.use(generalLimiter);
|
|
164
|
-
server.use(
|
|
89
|
+
server.use(bucketRoutes);
|
|
165
90
|
|
|
166
91
|
if (process.env.mbkbucket_test === "dev") {
|
|
167
92
|
|