mbkbucket 2.1.0 → 3.0.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 +4 -2
- package/.github/PACKAGE.md +6 -0
- package/.mbkbucket.config.example.json +14 -0
- package/LICENSE +161 -335
- package/README.md +262 -81
- package/cli.js +977 -0
- package/index.js +18 -140
- package/lib/index.js +7 -7
- package/package.json +18 -6
- package/public/bucketadmin.js +41 -6
- package/src/app.js +110 -0
- package/src/cli/auth-helper.js +223 -0
- package/{lib → src}/config/index.js +26 -19
- package/{lib/routes/api.js → src/controllers/api.controller.js} +125 -221
- package/{lib/routes/index.js → src/controllers/dashboard.controller.js} +8 -36
- package/src/controllers/info.controller.js +37 -0
- package/src/controllers/view.controller.js +276 -0
- package/src/middleware/async-handler.js +38 -0
- package/src/middleware/bucket-resolver.js +43 -0
- package/src/middleware/error-handler.js +34 -0
- package/src/middleware/rate-limiter.js +30 -0
- package/src/middleware/security.js +43 -0
- package/src/routes/api.routes.js +66 -0
- package/src/routes/index.js +22 -0
- package/src/routes/info.routes.js +10 -0
- package/src/routes/view.routes.js +25 -0
- package/{lib/s3.js → src/services/s3.service.js} +116 -190
- package/src/utils/errors.js +76 -0
- package/src/utils/helpers.js +173 -0
- package/{lib/debug.js → src/utils/logger.js} +5 -0
- package/test/config-validation.test.js +1 -1
- package/views/bucket.handlebars +0 -1
- package/lib/routes/info.js +0 -28
- package/lib/routes/view.js +0 -531
- /package/{lib → src}/config/validation.js +0 -0
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { createRequire } from "module";
|
|
2
2
|
import dotenv from "dotenv";
|
|
3
3
|
import { parseAndValidateMbkbucketVar, parseAndValidateBucketConnection } from "./validation.js";
|
|
4
|
-
import { createLogger } from "../
|
|
4
|
+
import { createLogger } from "../utils/logger.js";
|
|
5
5
|
|
|
6
6
|
dotenv.config();
|
|
7
7
|
const debugConfig = createLogger('config');
|
|
@@ -99,28 +99,35 @@ function validateBucketConnection() {
|
|
|
99
99
|
}
|
|
100
100
|
|
|
101
101
|
try {
|
|
102
|
-
|
|
103
|
-
|
|
102
|
+
parseAndValidateBucketConnection(process.env.BucketConnection);
|
|
103
|
+
debugConfig('BucketConnection configuration validated successfully');
|
|
104
|
+
} catch (error) {
|
|
105
|
+
throw new Error(`[mbkbucket] BucketConnection validation failed:\n - ${error.message}`);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
104
108
|
|
|
105
|
-
|
|
106
|
-
|
|
109
|
+
// Validate all configuration at startup
|
|
110
|
+
function validateAllConfiguration() {
|
|
111
|
+
try {
|
|
112
|
+
validateConfiguration();
|
|
113
|
+
validateBucketConnection();
|
|
114
|
+
debugConfig('All configurations validated successfully');
|
|
115
|
+
return true;
|
|
107
116
|
} catch (error) {
|
|
108
|
-
console.error(
|
|
109
|
-
|
|
110
|
-
console.error(`[mbkbucket] Correct format example:`);
|
|
111
|
-
console.error(`[mbkbucket] BucketConnection={"r2":{"BUCKET_NAME":"my-bucket","ACCESS_KEY_ID":"key","SECRET_ACCESS_KEY":"secret","ENDPOINT":"https://endpoint.com"}}`);
|
|
112
|
-
console.error(`[mbkbucket] ⚠️ Note: Inner objects should NOT be quoted as strings!`);
|
|
113
|
-
throw new Error(`[mbkbucket] Invalid BucketConnection configuration`);
|
|
117
|
+
console.error(error.message);
|
|
118
|
+
return false;
|
|
114
119
|
}
|
|
115
120
|
}
|
|
116
121
|
|
|
117
|
-
// Parse and validate mbkbucketVar once
|
|
118
122
|
const mbkbucketVar = validateConfiguration();
|
|
119
|
-
debugConfig('mbkbucketVar configuration: %O', mbkbucketVar);
|
|
120
|
-
|
|
121
|
-
// Validate BucketConnection
|
|
122
|
-
validateBucketConnection();
|
|
123
123
|
|
|
124
|
-
export {
|
|
125
|
-
|
|
126
|
-
|
|
124
|
+
export {
|
|
125
|
+
packageJson,
|
|
126
|
+
appVersion,
|
|
127
|
+
mbkbucketVar,
|
|
128
|
+
checkVersion,
|
|
129
|
+
getLatestVersion,
|
|
130
|
+
validateConfiguration,
|
|
131
|
+
validateBucketConnection,
|
|
132
|
+
validateAllConfiguration
|
|
133
|
+
};
|