arkos 1.1.12-test → 1.1.14-test
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/dist/cjs/app.js +1 -1
- package/dist/cjs/app.js.map +1 -1
- package/dist/cjs/modules/auth/auth.controller.js +53 -64
- package/dist/cjs/modules/auth/auth.controller.js.map +1 -1
- package/dist/cjs/modules/auth/auth.router.js +46 -58
- package/dist/cjs/modules/auth/auth.router.js.map +1 -1
- package/dist/cjs/modules/auth/auth.service.js +75 -97
- package/dist/cjs/modules/auth/auth.service.js.map +1 -1
- package/dist/cjs/modules/auth/utils/helpers/auth.controller.helpers.js +6 -7
- package/dist/cjs/modules/auth/utils/helpers/auth.controller.helpers.js.map +1 -1
- package/dist/cjs/modules/base/base.controller.js +30 -46
- package/dist/cjs/modules/base/base.controller.js.map +1 -1
- package/dist/cjs/modules/base/base.middlewares.js +17 -21
- package/dist/cjs/modules/base/base.middlewares.js.map +1 -1
- package/dist/cjs/modules/base/base.router.js +6 -17
- package/dist/cjs/modules/base/base.router.js.map +1 -1
- package/dist/cjs/modules/base/base.service.js +128 -116
- package/dist/cjs/modules/base/base.service.js.map +1 -1
- package/dist/cjs/modules/base/utils/helpers/base.controller.helpers.js +3 -5
- package/dist/cjs/modules/base/utils/helpers/base.controller.helpers.js.map +1 -1
- package/dist/cjs/modules/base/utils/helpers/base.router.helpers.js +36 -47
- package/dist/cjs/modules/base/utils/helpers/base.router.helpers.js.map +1 -1
- package/dist/cjs/modules/base/utils/helpers/base.service.helpers.js +30 -40
- package/dist/cjs/modules/base/utils/helpers/base.service.helpers.js.map +1 -1
- package/dist/cjs/modules/email/email.service.js +28 -39
- package/dist/cjs/modules/email/email.service.js.map +1 -1
- package/dist/cjs/modules/error-handler/error-handler.controller.js +6 -3
- package/dist/cjs/modules/error-handler/error-handler.controller.js.map +1 -1
- package/dist/cjs/modules/error-handler/utils/catch-async.js +3 -12
- package/dist/cjs/modules/error-handler/utils/catch-async.js.map +1 -1
- package/dist/cjs/modules/error-handler/utils/error-handler.helpers.js +17 -31
- package/dist/cjs/modules/error-handler/utils/error-handler.helpers.js.map +1 -1
- package/dist/cjs/modules/file-uploader/file-uploader.controller.js +18 -27
- package/dist/cjs/modules/file-uploader/file-uploader.controller.js.map +1 -1
- package/dist/cjs/modules/file-uploader/file-uploader.router.js +23 -34
- package/dist/cjs/modules/file-uploader/file-uploader.router.js.map +1 -1
- package/dist/cjs/modules/file-uploader/file-uploader.service.js +117 -131
- package/dist/cjs/modules/file-uploader/file-uploader.service.js.map +1 -1
- package/dist/cjs/modules/file-uploader/utils/helpers/file-uploader.helpers.js +15 -26
- package/dist/cjs/modules/file-uploader/utils/helpers/file-uploader.helpers.js.map +1 -1
- package/dist/cjs/proxy.js +1 -0
- package/dist/cjs/proxy.js.map +1 -0
- package/dist/cjs/server.js +1 -1
- package/dist/cjs/server.js.map +1 -1
- package/dist/cjs/utils/cli/build.js +9 -2
- package/dist/cjs/utils/cli/build.js.map +1 -1
- package/dist/cjs/utils/cli/dev.js +108 -48
- package/dist/cjs/utils/cli/dev.js.map +1 -1
- package/dist/cjs/utils/cli/start.js +35 -38
- package/dist/cjs/utils/cli/start.js.map +1 -1
- package/dist/cjs/utils/features/api.features.js +26 -33
- package/dist/cjs/utils/features/api.features.js.map +1 -1
- package/dist/cjs/utils/helpers/api.features.helpers.js +4 -6
- package/dist/cjs/utils/helpers/api.features.helpers.js.map +1 -1
- package/dist/cjs/utils/helpers/change-case.helpers.js +28 -36
- package/dist/cjs/utils/helpers/change-case.helpers.js.map +1 -1
- package/dist/cjs/utils/helpers/deepmerge.helper.js +4 -8
- package/dist/cjs/utils/helpers/deepmerge.helper.js.map +1 -1
- package/dist/cjs/utils/helpers/global.helpers.js +2 -13
- package/dist/cjs/utils/helpers/global.helpers.js.map +1 -1
- package/dist/cjs/utils/helpers/models.helpers.js +65 -80
- package/dist/cjs/utils/helpers/models.helpers.js.map +1 -1
- package/dist/cjs/utils/helpers/prisma.helpers.js +23 -34
- package/dist/cjs/utils/helpers/prisma.helpers.js.map +1 -1
- package/dist/cjs/utils/validate-dto.js +6 -17
- package/dist/cjs/utils/validate-dto.js.map +1 -1
- package/dist/cjs/utils/validate-schema.js +6 -17
- package/dist/cjs/utils/validate-schema.js.map +1 -1
- package/dist/es2020/app.js +1 -1
- package/dist/es2020/app.js.map +1 -1
- package/dist/es2020/modules/auth/auth.controller.js +53 -64
- package/dist/es2020/modules/auth/auth.controller.js.map +1 -1
- package/dist/es2020/modules/auth/auth.router.js +46 -58
- package/dist/es2020/modules/auth/auth.router.js.map +1 -1
- package/dist/es2020/modules/auth/auth.service.js +75 -97
- package/dist/es2020/modules/auth/auth.service.js.map +1 -1
- package/dist/es2020/modules/auth/utils/helpers/auth.controller.helpers.js +6 -7
- package/dist/es2020/modules/auth/utils/helpers/auth.controller.helpers.js.map +1 -1
- package/dist/es2020/modules/base/base.controller.js +30 -46
- package/dist/es2020/modules/base/base.controller.js.map +1 -1
- package/dist/es2020/modules/base/base.middlewares.js +17 -21
- package/dist/es2020/modules/base/base.middlewares.js.map +1 -1
- package/dist/es2020/modules/base/base.router.js +6 -17
- package/dist/es2020/modules/base/base.router.js.map +1 -1
- package/dist/es2020/modules/base/base.service.js +128 -116
- package/dist/es2020/modules/base/base.service.js.map +1 -1
- package/dist/es2020/modules/base/utils/helpers/base.controller.helpers.js +3 -5
- package/dist/es2020/modules/base/utils/helpers/base.controller.helpers.js.map +1 -1
- package/dist/es2020/modules/base/utils/helpers/base.router.helpers.js +36 -47
- package/dist/es2020/modules/base/utils/helpers/base.router.helpers.js.map +1 -1
- package/dist/es2020/modules/base/utils/helpers/base.service.helpers.js +30 -40
- package/dist/es2020/modules/base/utils/helpers/base.service.helpers.js.map +1 -1
- package/dist/es2020/modules/email/email.service.js +28 -39
- package/dist/es2020/modules/email/email.service.js.map +1 -1
- package/dist/es2020/modules/error-handler/error-handler.controller.js +6 -3
- package/dist/es2020/modules/error-handler/error-handler.controller.js.map +1 -1
- package/dist/es2020/modules/error-handler/utils/catch-async.js +3 -12
- package/dist/es2020/modules/error-handler/utils/catch-async.js.map +1 -1
- package/dist/es2020/modules/error-handler/utils/error-handler.helpers.js +17 -31
- package/dist/es2020/modules/error-handler/utils/error-handler.helpers.js.map +1 -1
- package/dist/es2020/modules/file-uploader/file-uploader.controller.js +18 -27
- package/dist/es2020/modules/file-uploader/file-uploader.controller.js.map +1 -1
- package/dist/es2020/modules/file-uploader/file-uploader.router.js +23 -34
- package/dist/es2020/modules/file-uploader/file-uploader.router.js.map +1 -1
- package/dist/es2020/modules/file-uploader/file-uploader.service.js +117 -131
- package/dist/es2020/modules/file-uploader/file-uploader.service.js.map +1 -1
- package/dist/es2020/modules/file-uploader/utils/helpers/file-uploader.helpers.js +15 -26
- package/dist/es2020/modules/file-uploader/utils/helpers/file-uploader.helpers.js.map +1 -1
- package/dist/es2020/server.js +1 -1
- package/dist/es2020/server.js.map +1 -1
- package/dist/es2020/utils/cli/build.js +9 -2
- package/dist/es2020/utils/cli/build.js.map +1 -1
- package/dist/es2020/utils/cli/dev.js +75 -48
- package/dist/es2020/utils/cli/dev.js.map +1 -1
- package/dist/es2020/utils/cli/start.js +35 -38
- package/dist/es2020/utils/cli/start.js.map +1 -1
- package/dist/es2020/utils/features/api.features.js +26 -33
- package/dist/es2020/utils/features/api.features.js.map +1 -1
- package/dist/es2020/utils/helpers/api.features.helpers.js +4 -6
- package/dist/es2020/utils/helpers/api.features.helpers.js.map +1 -1
- package/dist/es2020/utils/helpers/change-case.helpers.js +28 -36
- package/dist/es2020/utils/helpers/change-case.helpers.js.map +1 -1
- package/dist/es2020/utils/helpers/deepmerge.helper.js +4 -8
- package/dist/es2020/utils/helpers/deepmerge.helper.js.map +1 -1
- package/dist/es2020/utils/helpers/global.helpers.js +2 -13
- package/dist/es2020/utils/helpers/global.helpers.js.map +1 -1
- package/dist/es2020/utils/helpers/models.helpers.js +65 -80
- package/dist/es2020/utils/helpers/models.helpers.js.map +1 -1
- package/dist/es2020/utils/helpers/prisma.helpers.js +23 -34
- package/dist/es2020/utils/helpers/prisma.helpers.js.map +1 -1
- package/dist/es2020/utils/validate-dto.js +6 -17
- package/dist/es2020/utils/validate-dto.js.map +1 -1
- package/dist/es2020/utils/validate-schema.js +6 -17
- package/dist/es2020/utils/validate-schema.js.map +1 -1
- package/dist/types/server.d.ts +3 -1
- package/package.json +1 -1
|
@@ -46,7 +46,7 @@ function handleJWTExpired() {
|
|
|
46
46
|
return new app_error_1.default("Your token has expired, Please log again!", 401);
|
|
47
47
|
}
|
|
48
48
|
function handlePrismaClientValidationError(err) {
|
|
49
|
-
const message = err
|
|
49
|
+
const message = err?.message.split("\n")[err?.message.split("\n").length - 1];
|
|
50
50
|
return new app_error_1.default(message, 400);
|
|
51
51
|
}
|
|
52
52
|
function handleAuthenticationError(err) {
|
|
@@ -66,13 +66,12 @@ function handleDatabaseNotFoundError(err) {
|
|
|
66
66
|
return new app_error_1.default(message, 404);
|
|
67
67
|
}
|
|
68
68
|
function handleEnvironmentVariableError(err) {
|
|
69
|
-
const missingVars =
|
|
69
|
+
const missingVars = err?.missing || "unknown environment variables";
|
|
70
70
|
const message = `Missing or invalid environment variables: ${missingVars}. Please check your configuration.`;
|
|
71
71
|
return new app_error_1.default(message, 500);
|
|
72
72
|
}
|
|
73
73
|
function handleFieldValueTooLargeError(err) {
|
|
74
|
-
|
|
75
|
-
const message = `The value for the field "${(_a = err === null || err === void 0 ? void 0 : err.meta) === null || _a === void 0 ? void 0 : _a.field_name}" is too large. Please provide a smaller value.`;
|
|
74
|
+
const message = `The value for the field "${err?.meta?.field_name}" is too large. Please provide a smaller value.`;
|
|
76
75
|
return new app_error_1.default(message, 400);
|
|
77
76
|
}
|
|
78
77
|
function handleRecordNotFoundError(err) {
|
|
@@ -80,8 +79,7 @@ function handleRecordNotFoundError(err) {
|
|
|
80
79
|
return new app_error_1.default(message, 404);
|
|
81
80
|
}
|
|
82
81
|
function handleUniqueConstraintError(err) {
|
|
83
|
-
|
|
84
|
-
const field = ((_a = err === null || err === void 0 ? void 0 : err.meta) === null || _a === void 0 ? void 0 : _a.target) || "unknown field";
|
|
82
|
+
const field = err?.meta?.target || "unknown field";
|
|
85
83
|
const message = `Duplicate value detected for the unique field(s): ${field}. Please use a different value.`;
|
|
86
84
|
return new app_error_1.default(message, 409);
|
|
87
85
|
}
|
|
@@ -90,20 +88,17 @@ function handleForeignKeyConstraintError(err) {
|
|
|
90
88
|
return new app_error_1.default(message, 400);
|
|
91
89
|
}
|
|
92
90
|
function handleConstraintFailedError(err) {
|
|
93
|
-
|
|
94
|
-
const constraint = ((_a = err === null || err === void 0 ? void 0 : err.meta) === null || _a === void 0 ? void 0 : _a.constraint) || "unknown constraint";
|
|
91
|
+
const constraint = err?.meta?.constraint || "unknown constraint";
|
|
95
92
|
const message = `A database constraint "${constraint}" failed. Please review your input data.`;
|
|
96
93
|
return new app_error_1.default(message, 400);
|
|
97
94
|
}
|
|
98
95
|
function handleInvalidFieldValueError(err) {
|
|
99
|
-
|
|
100
|
-
const fieldName = ((_a = err === null || err === void 0 ? void 0 : err.meta) === null || _a === void 0 ? void 0 : _a.field_name) || "unknown field";
|
|
96
|
+
const fieldName = err?.meta?.field_name || "unknown field";
|
|
101
97
|
const message = `Invalid value provided for the field "${fieldName}". Please provide a valid value.`;
|
|
102
98
|
return new app_error_1.default(message, 400);
|
|
103
99
|
}
|
|
104
100
|
function handleInvalidFieldProvidedError(err) {
|
|
105
|
-
|
|
106
|
-
const fieldName = ((_a = err === null || err === void 0 ? void 0 : err.meta) === null || _a === void 0 ? void 0 : _a.field_name) || "unknown field";
|
|
101
|
+
const fieldName = err?.meta?.field_name || "unknown field";
|
|
107
102
|
const message = `The field "${fieldName}" has been provided with an invalid value. Check the data and try again.`;
|
|
108
103
|
return new app_error_1.default(message, 400);
|
|
109
104
|
}
|
|
@@ -112,14 +107,12 @@ function handleDataValidationError(err) {
|
|
|
112
107
|
return new app_error_1.default(message, 400);
|
|
113
108
|
}
|
|
114
109
|
function handleQueryParsingError(err) {
|
|
115
|
-
|
|
116
|
-
const query = ((_a = err === null || err === void 0 ? void 0 : err.meta) === null || _a === void 0 ? void 0 : _a.query) || "unknown query";
|
|
110
|
+
const query = err?.meta?.query || "unknown query";
|
|
117
111
|
const message = `Failed to parse the query: "${query}". Check the syntax and structure.`;
|
|
118
112
|
return new app_error_1.default(message, 400);
|
|
119
113
|
}
|
|
120
114
|
function handleInvalidQueryFormatError(err) {
|
|
121
|
-
|
|
122
|
-
const query = ((_a = err === null || err === void 0 ? void 0 : err.meta) === null || _a === void 0 ? void 0 : _a.query) || "unknown query";
|
|
115
|
+
const query = err?.meta?.query || "unknown query";
|
|
123
116
|
const message = `The query format is invalid: "${query}". Ensure the query adheres to the expected format.`;
|
|
124
117
|
return new app_error_1.default(message, 400);
|
|
125
118
|
}
|
|
@@ -128,8 +121,7 @@ function handleRawQueryExecutionError(err) {
|
|
|
128
121
|
return new app_error_1.default(message, 500);
|
|
129
122
|
}
|
|
130
123
|
function handleNullConstraintViolationError(err) {
|
|
131
|
-
|
|
132
|
-
const fieldName = ((_a = err === null || err === void 0 ? void 0 : err.meta) === null || _a === void 0 ? void 0 : _a.field_name) || "unknown field";
|
|
124
|
+
const fieldName = err?.meta?.field_name || "unknown field";
|
|
133
125
|
const message = `The field "${fieldName}" cannot be null. Please provide a value.`;
|
|
134
126
|
return new app_error_1.default(message, 400);
|
|
135
127
|
}
|
|
@@ -138,14 +130,12 @@ function handleSchemaCreationFailedError(err) {
|
|
|
138
130
|
return new app_error_1.default(message, 500);
|
|
139
131
|
}
|
|
140
132
|
function handleMigrationAlreadyAppliedError(err) {
|
|
141
|
-
|
|
142
|
-
const migrationName = ((_a = err === null || err === void 0 ? void 0 : err.meta) === null || _a === void 0 ? void 0 : _a.migration) || "unknown migration";
|
|
133
|
+
const migrationName = err?.meta?.migration || "unknown migration";
|
|
143
134
|
const message = `The migration "${migrationName}" has already been applied to the database.`;
|
|
144
135
|
return new app_error_1.default(message, 409);
|
|
145
136
|
}
|
|
146
137
|
function handleMigrationScriptFailedError(err) {
|
|
147
|
-
|
|
148
|
-
const migrationName = ((_a = err === null || err === void 0 ? void 0 : err.meta) === null || _a === void 0 ? void 0 : _a.migration) || "unknown migration";
|
|
138
|
+
const migrationName = err?.meta?.migration || "unknown migration";
|
|
149
139
|
const message = `The migration script "${migrationName}" failed. Review the script and resolve any issues.`;
|
|
150
140
|
return new app_error_1.default(message, 500);
|
|
151
141
|
}
|
|
@@ -154,8 +144,7 @@ function handleVersionMismatchError(err) {
|
|
|
154
144
|
return new app_error_1.default(message, 400);
|
|
155
145
|
}
|
|
156
146
|
function handleMigrationFileReadError(err) {
|
|
157
|
-
|
|
158
|
-
const migrationFile = ((_a = err === null || err === void 0 ? void 0 : err.meta) === null || _a === void 0 ? void 0 : _a.migration_file) || "unknown file";
|
|
147
|
+
const migrationFile = err?.meta?.migration_file || "unknown file";
|
|
159
148
|
const message = `Failed to read the migration file "${migrationFile}". Ensure the file exists and is accessible.`;
|
|
160
149
|
return new app_error_1.default(message, 500);
|
|
161
150
|
}
|
|
@@ -176,14 +165,12 @@ function handleDynamicQueryError(err) {
|
|
|
176
165
|
return new app_error_1.default(message, 400);
|
|
177
166
|
}
|
|
178
167
|
function handleRelationLoadingError(err) {
|
|
179
|
-
|
|
180
|
-
const relation = ((_a = err === null || err === void 0 ? void 0 : err.meta) === null || _a === void 0 ? void 0 : _a.relation) || "unknown relation";
|
|
168
|
+
const relation = err?.meta?.relation || "unknown relation";
|
|
181
169
|
const message = `Error loading relation "${relation}". Ensure it is correctly defined and included in the query.`;
|
|
182
170
|
return new app_error_1.default(message, 400);
|
|
183
171
|
}
|
|
184
172
|
function handleBinaryError(err) {
|
|
185
|
-
|
|
186
|
-
const binaryName = ((_a = err === null || err === void 0 ? void 0 : err.meta) === null || _a === void 0 ? void 0 : _a.binary) || "unknown binary";
|
|
173
|
+
const binaryName = err?.meta?.binary || "unknown binary";
|
|
187
174
|
const message = `Error with Prisma binary "${binaryName}". Ensure the binary is properly installed and compatible.`;
|
|
188
175
|
return new app_error_1.default(message, 500);
|
|
189
176
|
}
|
|
@@ -196,9 +183,8 @@ function handleUnhandledPromiseError(err) {
|
|
|
196
183
|
return new app_error_1.default(message, 500);
|
|
197
184
|
}
|
|
198
185
|
function handleDataTypeError(err) {
|
|
199
|
-
|
|
200
|
-
const
|
|
201
|
-
const expectedType = ((_b = err === null || err === void 0 ? void 0 : err.meta) === null || _b === void 0 ? void 0 : _b.expected_type) || "unknown type";
|
|
186
|
+
const field = err?.meta?.field || "unknown field";
|
|
187
|
+
const expectedType = err?.meta?.expected_type || "unknown type";
|
|
202
188
|
const message = `Invalid data type for field "${field}". Expected type: ${expectedType}.`;
|
|
203
189
|
return new app_error_1.default(message, 400);
|
|
204
190
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"error-handler.helpers.js","sourceRoot":"","sources":["../../../../../src/modules/error-handler/utils/error-handler.helpers.ts"],"names":[],"mappings":";;;;;AA2BA,wCAEC;AAED,4CAEC;AAED,8EAGC;AAED,8DAIC;AAED,sEAIC;AAED,oEAIC;AAED,kEAGC;AAED,wEAIC;AAED,sEAGC;AAED,8DAIC;AAED,kEAIC;AAED,0EAIC;AAED,kEAIC;AAED,oEAIC;AAED,0EAIC;AAED,8DAIC;AAED,0DAIC;AAED,sEAIC;AAED,oEAIC;AAED,gFAIC;AAED,0EAIC;AAED,gFAIC;AAED,4EAIC;AAED,gEAGC;AAED,oEAIC;AAED,wDAGC;AAED,0DAGC;AAED,sDAGC;AAED,0DAGC;AAED,gEAIC;AAED,8CAIC;AAED,gDAGC;AAED,kEAGC;AAED,kDAKC;AAED,wDAGC;AA7ND,4DAAmC;AA2BnC,SAAgB,cAAc;IAC5B,OAAO,IAAI,mBAAQ,CAAC,qCAAqC,EAAE,GAAG,CAAC,CAAC;AAClE,CAAC;AAED,SAAgB,gBAAgB;IAC9B,OAAO,IAAI,mBAAQ,CAAC,2CAA2C,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B,kBAAkB,CAAC,GAAa;IAC9C,MAAM,OAAO,GAAG,qGAAqG,CAAC;IACtH,OAAO,IAAI,mBAAQ,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC;AACpC,CAAC;AAED,SAAgB,2BAA2B,CAAC,GAAa;IACvD,MAAM,OAAO,GAAG,iGAAiG,CAAC;IAClH,OAAO,IAAI,mBAAQ,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC;AACpC,CAAC;AAED,SAAgB,mBAAmB,CAAC,GAAa;;IAC/C,MAAM,KAAK,GAAG,CAAA,MAAA,GAAG,aAAH,GAAG,uBAAH,GAAG,CAAE,IAAI,0CAAE,KAAK,KAAI,eAAe,CAAC;IAClD,MAAM,YAAY,GAAG,CAAA,MAAA,GAAG,aAAH,GAAG,uBAAH,GAAG,CAAE,IAAI,0CAAE,aAAa,KAAI,cAAc,CAAC;IAChE,MAAM,OAAO,GAAG,gCAAgC,KAAK,qBAAqB,YAAY,GAAG,CAAC;IAC1F,OAAO,IAAI,mBAAQ,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC;AACpC,CAAC;AAED,SAAgB,sBAAsB,CAAC,GAAa;IAClD,MAAM,OAAO,GAAG,6FAA6F,CAAC;IAC9G,OAAO,IAAI,mBAAQ,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC;AACpC,CAAC","sourcesContent":["import AppError from \"./app-error\";\n\nexport interface PrismaError {\n code?: string; // Prisma-specific error code\n message: string; // Error message\n meta?: Record<string, any>; // Metadata provided by Prisma\n name?: string; // Error name\n}\n\n// const handleCastErrorDB = (err: AppError) => {\n// const message = `Invalid ${err?.path}: ${err?.value}`\n// return new AppError(message, 400)\n// }\n\n// const handleDuplicateFieldDB = (err: AppError) => {\n// const value = err?.keyValue.name\n// const message = `Duplicate fiedl value: ${value}. Please use another value!`\n\n// return new AppError(message, 400)\n// }\n\n// const handleValidationErrorDB = (err: AppError) => {\n// const errors = Object.values(err?.errors).map((el) => el.message)\n// const message = `Ivalid input data. ${errors.join('. ')}`\n// return new AppError(message, 400)\n// }\n\nexport function handleJWTError() {\n return new AppError(\"Invalid token. Please log in again!\", 401);\n}\n\nexport function handleJWTExpired() {\n return new AppError(\"Your token has expired, Please log again!\", 401);\n}\n\nexport function handlePrismaClientValidationError(err: AppError) {\n const message = err?.message.split(\"\\n\")[err?.message.split(\"\\n\").length - 1];\n return new AppError(message, 400);\n}\n\nexport function handleAuthenticationError(err: AppError) {\n const message =\n \"Authentication failed against the database server. Please check your credentials.\";\n return new AppError(message, 401);\n}\n\nexport function handleServerNotReachableError(err: AppError) {\n const message =\n \"The database server is not reachable. Verify your connection string or ensure the server is online.\";\n return new AppError(message, 503);\n}\n\nexport function handleConnectionTimeoutError(err: AppError) {\n const message =\n \"Connection to the database timed out. Please check server performance or network connectivity.\";\n return new AppError(message, 504);\n}\n\nexport function handleDatabaseNotFoundError(err: AppError) {\n const message = \"The specified database does not exist on the server.\";\n return new AppError(message, 404);\n}\n\nexport function handleEnvironmentVariableError(err: AppError) {\n const missingVars = err?.missing || \"unknown environment variables\";\n const message = `Missing or invalid environment variables: ${missingVars}. Please check your configuration.`;\n return new AppError(message, 500);\n}\n\nexport function handleFieldValueTooLargeError(err: AppError) {\n const message = `The value for the field \"${err?.meta?.field_name}\" is too large. Please provide a smaller value.`;\n return new AppError(message, 400);\n}\n\nexport function handleRecordNotFoundError(err: AppError) {\n const message =\n \"No record found for the given query. Ensure the query parameters are correct.\";\n return new AppError(message, 404);\n}\n\nexport function handleUniqueConstraintError(err: AppError) {\n const field = err?.meta?.target || \"unknown field\";\n const message = `Duplicate value detected for the unique field(s): ${field}. Please use a different value.`;\n return new AppError(message, 409);\n}\n\nexport function handleForeignKeyConstraintError(err: AppError) {\n const message =\n \"Foreign key constraint violation. Ensure that the referenced record exists.\";\n return new AppError(message, 400);\n}\n\nexport function handleConstraintFailedError(err: AppError) {\n const constraint = err?.meta?.constraint || \"unknown constraint\";\n const message = `A database constraint \"${constraint}\" failed. Please review your input data.`;\n return new AppError(message, 400);\n}\n\nexport function handleInvalidFieldValueError(err: AppError) {\n const fieldName = err?.meta?.field_name || \"unknown field\";\n const message = `Invalid value provided for the field \"${fieldName}\". Please provide a valid value.`;\n return new AppError(message, 400);\n}\n\nexport function handleInvalidFieldProvidedError(err: AppError) {\n const fieldName = err?.meta?.field_name || \"unknown field\";\n const message = `The field \"${fieldName}\" has been provided with an invalid value. Check the data and try again.`;\n return new AppError(message, 400);\n}\n\nexport function handleDataValidationError(err: AppError) {\n const message =\n \"Data validation error occurred. Please ensure all fields meet the required criteria.\";\n return new AppError(message, 400);\n}\n\nexport function handleQueryParsingError(err: AppError) {\n const query = err?.meta?.query || \"unknown query\";\n const message = `Failed to parse the query: \"${query}\". Check the syntax and structure.`;\n return new AppError(message, 400);\n}\n\nexport function handleInvalidQueryFormatError(err: AppError) {\n const query = err?.meta?.query || \"unknown query\";\n const message = `The query format is invalid: \"${query}\". Ensure the query adheres to the expected format.`;\n return new AppError(message, 400);\n}\n\nexport function handleRawQueryExecutionError(err: AppError) {\n const message =\n \"An error occurred during the execution of a raw query. Verify the query and try again.\";\n return new AppError(message, 500);\n}\n\nexport function handleNullConstraintViolationError(err: AppError) {\n const fieldName = err?.meta?.field_name || \"unknown field\";\n const message = `The field \"${fieldName}\" cannot be null. Please provide a value.`;\n return new AppError(message, 400);\n}\n\nexport function handleSchemaCreationFailedError(err: AppError) {\n const message =\n \"Failed to create the database schema. Verify the schema definition and try again.\";\n return new AppError(message, 500);\n}\n\nexport function handleMigrationAlreadyAppliedError(err: AppError) {\n const migrationName = err?.meta?.migration || \"unknown migration\";\n const message = `The migration \"${migrationName}\" has already been applied to the database.`;\n return new AppError(message, 409);\n}\n\nexport function handleMigrationScriptFailedError(err: AppError) {\n const migrationName = err?.meta?.migration || \"unknown migration\";\n const message = `The migration script \"${migrationName}\" failed. Review the script and resolve any issues.`;\n return new AppError(message, 500);\n}\n\nexport function handleVersionMismatchError(err: AppError) {\n const message = `Version mismatch: The database schema and migration versions are inconsistent. Please check and resolve this issue.`;\n return new AppError(message, 400);\n}\n\nexport function handleMigrationFileReadError(err: AppError) {\n const migrationFile = err?.meta?.migration_file || \"unknown file\";\n const message = `Failed to read the migration file \"${migrationFile}\". Ensure the file exists and is accessible.`;\n return new AppError(message, 500);\n}\n\nexport function handleSchemaDriftError(err: AppError) {\n const message = `Schema drift detected: The database schema differs from the expected state. Run migrations or sync schema to resolve.`;\n return new AppError(message, 400);\n}\n\nexport function handleSchemaSyntaxError(err: AppError) {\n const message = `Syntax error in the schema file. Please check for typos or invalid syntax in your schema definition.`;\n return new AppError(message, 500);\n}\n\nexport function handleClientTypeError(err: AppError) {\n const message = `Type error, Ensure proper usage of methods and correct data types.`;\n return new AppError(message, 400);\n}\n\nexport function handleDynamicQueryError(err: AppError) {\n const message = `Error constructing or executing a dynamic query. Verify query structure and parameters.`;\n return new AppError(message, 400);\n}\n\nexport function handleRelationLoadingError(err: AppError) {\n const relation = err?.meta?.relation || \"unknown relation\";\n const message = `Error loading relation \"${relation}\". Ensure it is correctly defined and included in the query.`;\n return new AppError(message, 400);\n}\n\nexport function handleBinaryError(err: AppError) {\n const binaryName = err?.meta?.binary || \"unknown binary\";\n const message = `Error with Prisma binary \"${binaryName}\". Ensure the binary is properly installed and compatible.`;\n return new AppError(message, 500);\n}\n\nexport function handleNetworkError(err: AppError) {\n const message = `Network error: Unable to connect to the database or internet. Please check your network connection.`;\n return new AppError(message, 500);\n}\n\nexport function handleUnhandledPromiseError(err: AppError) {\n const message = `Unhandled promise rejection detected. Please check asynchronous code for proper error handling.`;\n return new AppError(message, 500);\n}\n\nexport function handleDataTypeError(err: AppError) {\n const field = err?.meta?.field || \"unknown field\";\n const expectedType = err?.meta?.expected_type || \"unknown type\";\n const message = `Invalid data type for field \"${field}\". Expected type: ${expectedType}.`;\n return new AppError(message, 400);\n}\n\nexport function handleEmptyResultError(err: AppError) {\n const message = `Empty result: No data was found for the given query. Ensure the query criteria are correct.`;\n return new AppError(message, 404);\n}\n"]}
|
|
1
|
+
{"version":3,"file":"error-handler.helpers.js","sourceRoot":"","sources":["../../../../../src/modules/error-handler/utils/error-handler.helpers.ts"],"names":[],"mappings":";;;;;AA2BA,wCAEC;AAED,4CAEC;AAED,8EAGC;AAED,8DAIC;AAED,sEAIC;AAED,oEAIC;AAED,kEAGC;AAED,wEAIC;AAED,sEAGC;AAED,8DAIC;AAED,kEAIC;AAED,0EAIC;AAED,kEAIC;AAED,oEAIC;AAED,0EAIC;AAED,8DAIC;AAED,0DAIC;AAED,sEAIC;AAED,oEAIC;AAED,gFAIC;AAED,0EAIC;AAED,gFAIC;AAED,4EAIC;AAED,gEAGC;AAED,oEAIC;AAED,wDAGC;AAED,0DAGC;AAED,sDAGC;AAED,0DAGC;AAED,gEAIC;AAED,8CAIC;AAED,gDAGC;AAED,kEAGC;AAED,kDAKC;AAED,wDAGC;AA7ND,4DAAmC;AA2BnC,SAAgB,cAAc;IAC5B,OAAO,IAAI,mBAAQ,CAAC,qCAAqC,EAAE,GAAG,CAAC,CAAC;AAClE,CAAC;AAED,SAAgB,gBAAgB;IAC9B,OAAO,IAAI,mBAAQ,CAAC,2CAA2C,EAAE,GAAG,CAAC,CAAC;AACxE,CAAC;AAED,SAAgB,iCAAiC,CAAC,GAAa;IAC7D,MAAM,OAAO,GAAG,GAAG,EAAE,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,GAAG,EAAE,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;IAC9E,OAAO,IAAI,mBAAQ,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC;AACpC,CAAC;AAED,SAAgB,yBAAyB,CAAC,GAAa;IACrD,MAAM,OAAO,GACX,mFAAmF,CAAC;IACtF,OAAO,IAAI,mBAAQ,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC;AACpC,CAAC;AAED,SAAgB,6BAA6B,CAAC,GAAa;IACzD,MAAM,OAAO,GACX,qGAAqG,CAAC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OAAO,GAAG,6BAA6B,UAAU,4DAA4D,CAAC;IACpH,OAAO,IAAI,mBAAQ,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC;AACpC,CAAC;AAED,SAAgB,kBAAkB,CAAC,GAAa;IAC9C,MAAM,OAAO,GAAG,qGAAqG,CAAC;IACtH,OAAO,IAAI,mBAAQ,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC;AACpC,CAAC;AAED,SAAgB,2BAA2B,CAAC,GAAa;IACvD,MAAM,OAAO,GAAG,iGAAiG,CAAC;IAClH,OAAO,IAAI,mBAAQ,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC;AACpC,CAAC;AAED,SAAgB,mBAAmB,CAAC,GAAa;IAC/C,MAAM,KAAK,GAAG,GAAG,EAAE,IAAI,EAAE,KAAK,IAAI,eAAe,CAAC;IAClD,MAAM,YAAY,GAAG,GAAG,EAAE,IAAI,EAAE,aAAa,IAAI,cAAc,CAAC;IAChE,MAAM,OAAO,GAAG,gCAAgC,KAAK,qBAAqB,YAAY,GAAG,CAAC;IAC1F,OAAO,IAAI,mBAAQ,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC;AACpC,CAAC;AAED,SAAgB,sBAAsB,CAAC,GAAa;IAClD,MAAM,OAAO,GAAG,6FAA6F,CAAC;IAC9G,OAAO,IAAI,mBAAQ,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC;AACpC,CAAC","sourcesContent":["import AppError from \"./app-error\";\n\nexport interface PrismaError {\n code?: string; // Prisma-specific error code\n message: string; // Error message\n meta?: Record<string, any>; // Metadata provided by Prisma\n name?: string; // Error name\n}\n\n// const handleCastErrorDB = (err: AppError) => {\n// const message = `Invalid ${err?.path}: ${err?.value}`\n// return new AppError(message, 400)\n// }\n\n// const handleDuplicateFieldDB = (err: AppError) => {\n// const value = err?.keyValue.name\n// const message = `Duplicate fiedl value: ${value}. Please use another value!`\n\n// return new AppError(message, 400)\n// }\n\n// const handleValidationErrorDB = (err: AppError) => {\n// const errors = Object.values(err?.errors).map((el) => el.message)\n// const message = `Ivalid input data. ${errors.join('. ')}`\n// return new AppError(message, 400)\n// }\n\nexport function handleJWTError() {\n return new AppError(\"Invalid token. Please log in again!\", 401);\n}\n\nexport function handleJWTExpired() {\n return new AppError(\"Your token has expired, Please log again!\", 401);\n}\n\nexport function handlePrismaClientValidationError(err: AppError) {\n const message = err?.message.split(\"\\n\")[err?.message.split(\"\\n\").length - 1];\n return new AppError(message, 400);\n}\n\nexport function handleAuthenticationError(err: AppError) {\n const message =\n \"Authentication failed against the database server. Please check your credentials.\";\n return new AppError(message, 401);\n}\n\nexport function handleServerNotReachableError(err: AppError) {\n const message =\n \"The database server is not reachable. Verify your connection string or ensure the server is online.\";\n return new AppError(message, 503);\n}\n\nexport function handleConnectionTimeoutError(err: AppError) {\n const message =\n \"Connection to the database timed out. Please check server performance or network connectivity.\";\n return new AppError(message, 504);\n}\n\nexport function handleDatabaseNotFoundError(err: AppError) {\n const message = \"The specified database does not exist on the server.\";\n return new AppError(message, 404);\n}\n\nexport function handleEnvironmentVariableError(err: AppError) {\n const missingVars = err?.missing || \"unknown environment variables\";\n const message = `Missing or invalid environment variables: ${missingVars}. Please check your configuration.`;\n return new AppError(message, 500);\n}\n\nexport function handleFieldValueTooLargeError(err: AppError) {\n const message = `The value for the field \"${err?.meta?.field_name}\" is too large. Please provide a smaller value.`;\n return new AppError(message, 400);\n}\n\nexport function handleRecordNotFoundError(err: AppError) {\n const message =\n \"No record found for the given query. Ensure the query parameters are correct.\";\n return new AppError(message, 404);\n}\n\nexport function handleUniqueConstraintError(err: AppError) {\n const field = err?.meta?.target || \"unknown field\";\n const message = `Duplicate value detected for the unique field(s): ${field}. Please use a different value.`;\n return new AppError(message, 409);\n}\n\nexport function handleForeignKeyConstraintError(err: AppError) {\n const message =\n \"Foreign key constraint violation. Ensure that the referenced record exists.\";\n return new AppError(message, 400);\n}\n\nexport function handleConstraintFailedError(err: AppError) {\n const constraint = err?.meta?.constraint || \"unknown constraint\";\n const message = `A database constraint \"${constraint}\" failed. Please review your input data.`;\n return new AppError(message, 400);\n}\n\nexport function handleInvalidFieldValueError(err: AppError) {\n const fieldName = err?.meta?.field_name || \"unknown field\";\n const message = `Invalid value provided for the field \"${fieldName}\". Please provide a valid value.`;\n return new AppError(message, 400);\n}\n\nexport function handleInvalidFieldProvidedError(err: AppError) {\n const fieldName = err?.meta?.field_name || \"unknown field\";\n const message = `The field \"${fieldName}\" has been provided with an invalid value. Check the data and try again.`;\n return new AppError(message, 400);\n}\n\nexport function handleDataValidationError(err: AppError) {\n const message =\n \"Data validation error occurred. Please ensure all fields meet the required criteria.\";\n return new AppError(message, 400);\n}\n\nexport function handleQueryParsingError(err: AppError) {\n const query = err?.meta?.query || \"unknown query\";\n const message = `Failed to parse the query: \"${query}\". Check the syntax and structure.`;\n return new AppError(message, 400);\n}\n\nexport function handleInvalidQueryFormatError(err: AppError) {\n const query = err?.meta?.query || \"unknown query\";\n const message = `The query format is invalid: \"${query}\". Ensure the query adheres to the expected format.`;\n return new AppError(message, 400);\n}\n\nexport function handleRawQueryExecutionError(err: AppError) {\n const message =\n \"An error occurred during the execution of a raw query. Verify the query and try again.\";\n return new AppError(message, 500);\n}\n\nexport function handleNullConstraintViolationError(err: AppError) {\n const fieldName = err?.meta?.field_name || \"unknown field\";\n const message = `The field \"${fieldName}\" cannot be null. Please provide a value.`;\n return new AppError(message, 400);\n}\n\nexport function handleSchemaCreationFailedError(err: AppError) {\n const message =\n \"Failed to create the database schema. Verify the schema definition and try again.\";\n return new AppError(message, 500);\n}\n\nexport function handleMigrationAlreadyAppliedError(err: AppError) {\n const migrationName = err?.meta?.migration || \"unknown migration\";\n const message = `The migration \"${migrationName}\" has already been applied to the database.`;\n return new AppError(message, 409);\n}\n\nexport function handleMigrationScriptFailedError(err: AppError) {\n const migrationName = err?.meta?.migration || \"unknown migration\";\n const message = `The migration script \"${migrationName}\" failed. Review the script and resolve any issues.`;\n return new AppError(message, 500);\n}\n\nexport function handleVersionMismatchError(err: AppError) {\n const message = `Version mismatch: The database schema and migration versions are inconsistent. Please check and resolve this issue.`;\n return new AppError(message, 400);\n}\n\nexport function handleMigrationFileReadError(err: AppError) {\n const migrationFile = err?.meta?.migration_file || \"unknown file\";\n const message = `Failed to read the migration file \"${migrationFile}\". Ensure the file exists and is accessible.`;\n return new AppError(message, 500);\n}\n\nexport function handleSchemaDriftError(err: AppError) {\n const message = `Schema drift detected: The database schema differs from the expected state. Run migrations or sync schema to resolve.`;\n return new AppError(message, 400);\n}\n\nexport function handleSchemaSyntaxError(err: AppError) {\n const message = `Syntax error in the schema file. Please check for typos or invalid syntax in your schema definition.`;\n return new AppError(message, 500);\n}\n\nexport function handleClientTypeError(err: AppError) {\n const message = `Type error, Ensure proper usage of methods and correct data types.`;\n return new AppError(message, 400);\n}\n\nexport function handleDynamicQueryError(err: AppError) {\n const message = `Error constructing or executing a dynamic query. Verify query structure and parameters.`;\n return new AppError(message, 400);\n}\n\nexport function handleRelationLoadingError(err: AppError) {\n const relation = err?.meta?.relation || \"unknown relation\";\n const message = `Error loading relation \"${relation}\". Ensure it is correctly defined and included in the query.`;\n return new AppError(message, 400);\n}\n\nexport function handleBinaryError(err: AppError) {\n const binaryName = err?.meta?.binary || \"unknown binary\";\n const message = `Error with Prisma binary \"${binaryName}\". Ensure the binary is properly installed and compatible.`;\n return new AppError(message, 500);\n}\n\nexport function handleNetworkError(err: AppError) {\n const message = `Network error: Unable to connect to the database or internet. Please check your network connection.`;\n return new AppError(message, 500);\n}\n\nexport function handleUnhandledPromiseError(err: AppError) {\n const message = `Unhandled promise rejection detected. Please check asynchronous code for proper error handling.`;\n return new AppError(message, 500);\n}\n\nexport function handleDataTypeError(err: AppError) {\n const field = err?.meta?.field || \"unknown field\";\n const expectedType = err?.meta?.expected_type || \"unknown type\";\n const message = `Invalid data type for field \"${field}\". Expected type: ${expectedType}.`;\n return new AppError(message, 400);\n}\n\nexport function handleEmptyResultError(err: AppError) {\n const message = `Empty result: No data was found for the given query. Ensure the query criteria are correct.`;\n return new AppError(message, 404);\n}\n"]}
|
|
@@ -1,13 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
4
|
};
|
|
@@ -21,19 +12,19 @@ const catch_async_1 = __importDefault(require("../error-handler/utils/catch-asyn
|
|
|
21
12
|
const server_1 = require("../../server");
|
|
22
13
|
const file_uploader_helpers_1 = require("./utils/helpers/file-uploader.helpers");
|
|
23
14
|
const fs_helpers_1 = require("../../utils/helpers/fs.helpers");
|
|
24
|
-
exports.uploadFile = (0, catch_async_1.default)((req, res, next) =>
|
|
15
|
+
exports.uploadFile = (0, catch_async_1.default)(async (req, res, next) => {
|
|
25
16
|
const { fileType } = req.params;
|
|
26
17
|
const { format, width, height, resizeTo } = req.query;
|
|
27
18
|
const options = { format, width, height, resizeTo };
|
|
28
19
|
const { documentUploaderService, fileUploaderService, imageUploaderService, videoUploaderService, } = (0, file_uploader_service_1.getFileUploaderServices)();
|
|
29
20
|
const { fileUpload } = (0, server_1.getArkosConfig)();
|
|
30
|
-
const baseUploadDir =
|
|
21
|
+
const baseUploadDir = fileUpload?.baseUploadDir || "/uploads";
|
|
31
22
|
const uploadPath = path_1.default.resolve(process.cwd(), baseUploadDir, fileType);
|
|
32
23
|
try {
|
|
33
|
-
|
|
24
|
+
await (0, fs_helpers_1.accessAsync)(uploadPath);
|
|
34
25
|
}
|
|
35
26
|
catch (err) {
|
|
36
|
-
|
|
27
|
+
await (0, fs_helpers_1.mkdirAsync)(uploadPath, { recursive: true });
|
|
37
28
|
}
|
|
38
29
|
let uploader;
|
|
39
30
|
switch (fileType) {
|
|
@@ -52,25 +43,25 @@ exports.uploadFile = (0, catch_async_1.default)((req, res, next) => __awaiter(vo
|
|
|
52
43
|
default:
|
|
53
44
|
return next(new app_error_1.default("Invalid file type", 400));
|
|
54
45
|
}
|
|
55
|
-
uploader.handleMultipleUpload()(req, res, (err) =>
|
|
46
|
+
uploader.handleMultipleUpload()(req, res, async (err) => {
|
|
56
47
|
if (err)
|
|
57
48
|
return next(err);
|
|
58
49
|
let data;
|
|
59
50
|
if (req.files && Array.isArray(req.files)) {
|
|
60
51
|
if (fileType === "images") {
|
|
61
|
-
data =
|
|
52
|
+
data = await Promise.all(req.files.map((file) => (0, file_uploader_helpers_1.processImage)(req, file.path, options)));
|
|
62
53
|
}
|
|
63
54
|
else {
|
|
64
|
-
data =
|
|
55
|
+
data = await Promise.all(req.files.map((file) => (0, file_uploader_helpers_1.processFile)(req, file.path)));
|
|
65
56
|
}
|
|
66
57
|
data = data.filter((url) => url !== null);
|
|
67
58
|
}
|
|
68
59
|
else if (req.file) {
|
|
69
60
|
if (fileType === "images") {
|
|
70
|
-
data =
|
|
61
|
+
data = await (0, file_uploader_helpers_1.processImage)(req, req.file.path, options);
|
|
71
62
|
}
|
|
72
63
|
else {
|
|
73
|
-
data =
|
|
64
|
+
data = await (0, file_uploader_helpers_1.processFile)(req, req.file.path);
|
|
74
65
|
}
|
|
75
66
|
}
|
|
76
67
|
else {
|
|
@@ -83,9 +74,9 @@ exports.uploadFile = (0, catch_async_1.default)((req, res, next) => __awaiter(vo
|
|
|
83
74
|
? `${data.length} files uploaded successfully`
|
|
84
75
|
: "File uploaded successfully",
|
|
85
76
|
});
|
|
86
|
-
})
|
|
87
|
-
})
|
|
88
|
-
exports.deleteFile = (0, catch_async_1.default)((req, res, next) =>
|
|
77
|
+
});
|
|
78
|
+
});
|
|
79
|
+
exports.deleteFile = (0, catch_async_1.default)(async (req, res, next) => {
|
|
89
80
|
const { fileType, fileName } = req.params;
|
|
90
81
|
const { documentUploaderService, fileUploaderService, imageUploaderService, videoUploaderService, } = (0, file_uploader_service_1.getFileUploaderServices)();
|
|
91
82
|
let uploader;
|
|
@@ -107,7 +98,7 @@ exports.deleteFile = (0, catch_async_1.default)((req, res, next) => __awaiter(vo
|
|
|
107
98
|
}
|
|
108
99
|
try {
|
|
109
100
|
const fullUrl = `${req.protocol}://${req.get("host")}${req.originalUrl}`;
|
|
110
|
-
|
|
101
|
+
await uploader.deleteFileByUrl(fullUrl);
|
|
111
102
|
res.status(200).json({
|
|
112
103
|
success: true,
|
|
113
104
|
message: "File deleted successfully",
|
|
@@ -116,17 +107,17 @@ exports.deleteFile = (0, catch_async_1.default)((req, res, next) => __awaiter(vo
|
|
|
116
107
|
catch (error) {
|
|
117
108
|
return next(new app_error_1.default("File not found", 404));
|
|
118
109
|
}
|
|
119
|
-
})
|
|
120
|
-
exports.streamFile = (0, catch_async_1.default)((req, res, next) =>
|
|
110
|
+
});
|
|
111
|
+
exports.streamFile = (0, catch_async_1.default)(async (req, res, next) => {
|
|
121
112
|
const { fileName, fileType } = req.params;
|
|
122
113
|
const filePath = path_1.default.join(".", "uploads", fileType, fileName);
|
|
123
114
|
try {
|
|
124
|
-
|
|
115
|
+
await (0, fs_helpers_1.accessAsync)(filePath);
|
|
125
116
|
}
|
|
126
117
|
catch (err) {
|
|
127
118
|
throw new app_error_1.default("File not found", 404);
|
|
128
119
|
}
|
|
129
|
-
const fileStat =
|
|
120
|
+
const fileStat = await (0, fs_helpers_1.statAsync)(filePath);
|
|
130
121
|
const fileSize = fileStat.size;
|
|
131
122
|
const range = req.headers.range;
|
|
132
123
|
if (range) {
|
|
@@ -154,5 +145,5 @@ exports.streamFile = (0, catch_async_1.default)((req, res, next) => __awaiter(vo
|
|
|
154
145
|
});
|
|
155
146
|
fs_1.default.createReadStream(filePath).pipe(res);
|
|
156
147
|
}
|
|
157
|
-
})
|
|
148
|
+
});
|
|
158
149
|
//# sourceMappingURL=file-uploader.controller.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"file-uploader.controller.js","sourceRoot":"","sources":["../../../../src/modules/file-uploader/file-uploader.controller.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,iFAAwD;AACxD,mEAGiC;AACjC,gDAAwB;AACxB,4CAAoB;AAEpB,qFAA4D;AAE5D,yCAA8C;AAC9C,iFAG+C;AAC/C,+DAIwC;AAS3B,QAAA,UAAU,GAAG,IAAA,qBAAU,EAClC,CAAO,GAAY,EAAE,GAAa,EAAE,IAAkB,EAAE,EAAE;IACxD,MAAM,EAAE,QAAQ,EAAE,GAAG,GAAG,CAAC,MAAM,CAAC;IAChC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,GAAG,GAAG,CAAC,KAAK,CAAC;IACtD,MAAM,OAAO,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC;IAEpD,MAAM,EACJ,uBAAuB,EACvB,mBAAmB,EACnB,oBAAoB,EACpB,oBAAoB,GACrB,GAAG,IAAA,+CAAuB,GAAE,CAAC;IAE9B,MAAM,EAAE,UAAU,EAAE,GAAG,IAAA,uBAAc,GAAE,CAAC;IACxC,MAAM,aAAa,GAAG,CAAA,UAAU,aAAV,UAAU,uBAAV,UAAU,CAAE,aAAa,KAAI,UAAU,CAAC;IAG9D,MAAM,UAAU,GAAG,cAAI,CAAC,OAAO,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,aAAa,EAAE,QAAQ,CAAC,CAAC;IACxE,IAAI,CAAC;QACH,MAAM,IAAA,wBAAW,E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IAAI,CAAC,GAAG,CAAC,CAAC;IAC1D,CAAC;SAAM,CAAC;QACN,GAAG,CAAC,SAAS,CAAC,GAAG,EAAE;YACjB,gBAAgB,EAAE,QAAQ;YAC1B,cAAc,EAAE,0BAA0B;YAC1C,qBAAqB,EAAE,qBAAqB,QAAQ,GAAG;SACxD,CAAC,CAAC;QACH,YAAE,CAAC,gBAAgB,CAAC,QAAQ,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IAC1C,CAAC;AACH,CAAC,CAAA,CACF,CAAC","sourcesContent":["import AppError from \"../error-handler/utils/app-error\";\nimport {\n FileUploaderService,\n getFileUploaderServices,\n} from \"./file-uploader.service\";\nimport path from \"path\";\nimport fs from \"fs\";\nimport { NextFunction, Request, Response } from \"express\";\nimport catchAsync from \"../error-handler/utils/catch-async\";\nimport { promisify } from \"util\";\nimport { getArkosConfig } from \"../../server\";\nimport {\n processFile,\n processImage,\n} from \"./utils/helpers/file-uploader.helpers\";\nimport {\n accessAsync,\n mkdirAsync,\n statAsync,\n} from \"../../utils/helpers/fs.helpers\";\n\n/**\n * Handles file upload requests, processes images if needed, and returns URLs\n * Supports paths outside of the project directory with '../' prefix\n * @param {Request} req - Express request object\n * @param {Response} res - Express response object\n * @param {NextFunction} next - Express next middleware function\n */\nexport const uploadFile = catchAsync(\n async (req: Request, res: Response, next: NextFunction) => {\n const { fileType } = req.params;\n const { format, width, height, resizeTo } = req.query;\n const options = { format, width, height, resizeTo };\n\n const {\n documentUploaderService,\n fileUploaderService,\n imageUploaderService,\n videoUploaderService,\n } = getFileUploaderServices();\n\n const { fileUpload } = getArkosConfig();\n const baseUploadDir = fileUpload?.baseUploadDir || \"/uploads\";\n\n // Ensure upload directory exists\n const uploadPath = path.resolve(process.cwd(), baseUploadDir, fileType);\n try {\n await accessAsync(uploadPath);\n } catch (err) {\n // Create directory if it doesn't exist\n await mkdirAsync(uploadPath, { recursive: true });\n }\n\n // Select the appropriate uploader service based on file type\n let uploader: FileUploaderService;\n switch (fileType) {\n case \"images\":\n uploader = imageUploaderService;\n break;\n case \"videos\":\n uploader = videoUploaderService;\n break;\n case \"documents\":\n uploader = documentUploaderService;\n break;\n case \"files\":\n uploader = fileUploaderService;\n break;\n default:\n return next(new AppError(\"Invalid file type\", 400));\n }\n\n // Handle the file upload\n uploader.handleMultipleUpload()(req, res, async (err) => {\n if (err) return next(err);\n\n // Process all uploaded files\n let data;\n if (req.files && Array.isArray(req.files)) {\n if (fileType === \"images\") {\n // Process multiple image files with image transformations\n data = await Promise.all(\n req.files.map((file) => processImage(req, file.path, options))\n );\n } else {\n // Just store other file types without processing\n data = await Promise.all(\n req.files.map((file) => processFile(req, file.path))\n );\n }\n // Filter out any null values from failed processing\n data = data.filter((url) => url !== null);\n } else if (req.file) {\n // Process a single file\n if (fileType === \"images\") {\n data = await processImage(req, req.file.path, options);\n } else {\n data = await processFile(req, req.file.path);\n }\n } else {\n return next(new AppError(\"No file uploaded\", 400));\n }\n\n res.status(200).json({\n success: true,\n data,\n message: Array.isArray(data)\n ? `${data.length} files uploaded successfully`\n : \"File uploaded successfully\",\n });\n });\n }\n);\n\n/**\n * Handles file deletion requests\n * Supports paths outside of the project directory with '../' prefix\n * @param {Request} req - Express request object\n * @param {Response} res - Express response object\n * @param {NextFunction} next - Express next middleware function\n */\nexport const deleteFile = catchAsync(\n async (req: Request, res: Response, next: NextFunction) => {\n const { fileType, fileName } = req.params;\n\n // if (!fileName) {\n // return next(new AppError(\"File name is required\", 400));\n // }\n\n // if (!fileType) {\n // return next(new AppError(\"File type is required\", 400));\n // }\n\n // // Get the base upload directory from config\n // const { fileUpload } = getArkosConfig();\n // const baseUploadDir = fileUpload?.baseUploadDir || \"/uploads\";\n\n // // Construct the actual file path using path.resolve to handle '../' paths\n // const actualFilePath = path.resolve(\n // process.cwd(),\n // baseUploadDir,\n // fileType,\n // fileName\n // );\n\n const {\n documentUploaderService,\n fileUploaderService,\n imageUploaderService,\n videoUploaderService,\n } = getFileUploaderServices();\n\n let uploader: FileUploaderService;\n switch (fileType) {\n case \"images\":\n uploader = imageUploaderService;\n break;\n case \"videos\":\n uploader = videoUploaderService;\n break;\n case \"documents\":\n uploader = documentUploaderService;\n break;\n case \"files\":\n uploader = fileUploaderService;\n break;\n default:\n return next(new AppError(\"Invalid file type\", 400));\n }\n\n try {\n // // Check if file exists\n // await access(actualFilePath, fs.constants.F_OK);\n\n // // Delete the file\n // await unlink(actualFilePath);\n\n const fullUrl = `${req.protocol}://${req.get(\"host\")}${req.originalUrl}`;\n await uploader.deleteFileByUrl(fullUrl);\n\n res.status(200).json({\n success: true,\n message: \"File deleted successfully\",\n });\n } catch (error) {\n // File doesn't exist\n return next(new AppError(\"File not found\", 404));\n }\n }\n);\n\nexport const streamFile = catchAsync(\n async (req: Request, res: Response, next: NextFunction) => {\n const { fileName, fileType } = req.params;\n\n const filePath = path.join(\".\", \"uploads\", fileType, fileName);\n try {\n await accessAsync(filePath);\n } catch (err) {\n throw new AppError(\"File not found\", 404);\n }\n\n const fileStat = await statAsync(filePath);\n const fileSize = fileStat.size;\n const range = req.headers.range;\n\n if (range) {\n const [partialStart, partialEnd] = range.replace(/bytes=/, \"\").split(\"-\");\n const start = parseInt(partialStart, 10) || 0;\n const end = partialEnd ? parseInt(partialEnd, 10) : fileSize - 1;\n\n if (start >= fileSize || end >= fileSize) {\n res.status(416).json({ error: \"Range Not Satisfiable\" });\n return;\n }\n\n res.writeHead(206, {\n \"Content-Range\": `bytes ${start}-${end}/${fileSize}`,\n \"Accept-Ranges\": \"bytes\",\n \"Content-Length\": end - start + 1,\n \"Content-Type\": \"application/octet-stream\",\n \"Content-Disposition\": `inline; filename=\"${fileName}\"`,\n });\n\n fs.createReadStream(filePath, { start, end }).pipe(res);\n } else {\n res.writeHead(200, {\n \"Content-Length\": fileSize,\n \"Content-Type\": \"application/octet-stream\",\n \"Content-Disposition\": `inline; filename=\"${fileName}\"`,\n });\n fs.createReadStream(filePath).pipe(res);\n }\n }\n);\n"]}
|
|
1
|
+
{"version":3,"file":"file-uploader.controller.js","sourceRoot":"","sources":["../../../../src/modules/file-uploader/file-uploader.controller.ts"],"names":[],"mappings":";;;;;;AAAA,iFAAwD;AACxD,mEAGiC;AACjC,gDAAwB;AACxB,4CAAoB;AAEpB,qFAA4D;AAE5D,yCAA8C;AAC9C,iFAG+C;AAC/C,+DAIwC;AAS3B,QAAA,UAAU,GAAG,IAAA,qBAAU,EAClC,KAAK,EAAE,GAAY,EAAE,GAAa,EAAE,IAAkB,EAAE,EAAE;IACxD,MAAM,EAAE,QAAQ,EAAE,GAAG,GAAG,CAAC,MAAM,CAAC;IAChC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,GAAG,GAAG,CAAC,KAAK,CAAC;IACtD,MAAM,OAAO,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC;IAEpD,MAAM,EACJ,uBAAuB,EACvB,mBAAmB,EACnB,oBAAoB,EACpB,oBAAoB,GACrB,GAAG,IAAA,+CAAuB,GAAE,CAAC;IAE9B,MAAM,EAAE,UAAU,EAAE,GAAG,IAAA,uBAAc,GAAE,CAAC;IACxC,MAAM,aAAa,GAAG,UAAU,EAAE,aAAa,IAAI,UAAU,CAAC;IAG9D,MAAM,UAAU,GAAG,cAAI,CAAC,OAAO,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,aAAa,EAAE,QAAQ,CAAC,CAAC;IACxE,IAAI,CAAC;QACH,MAAM,IAAA,wBAAW,EAAC,UAAU,CAAC,CAAC;IAChC,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QAEb,MAAM,IAAA,uBAAU,EAAC,UAAU,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;IACpD,CAAC;IAGD,IAAI,QAA6B,CAAC;IAClC,QAAQ,QAAQ,EAAE,CAAC;QACjB,KAAK,QAAQ;YACX,QAAQ,GAAG,oBAAoB,CAAC;YAChC,MAA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CAAC,CAAC;IAC1C,CAAC;AACH,CAAC,CACF,CAAC","sourcesContent":["import AppError from \"../error-handler/utils/app-error\";\nimport {\n FileUploaderService,\n getFileUploaderServices,\n} from \"./file-uploader.service\";\nimport path from \"path\";\nimport fs from \"fs\";\nimport { NextFunction, Request, Response } from \"express\";\nimport catchAsync from \"../error-handler/utils/catch-async\";\nimport { promisify } from \"util\";\nimport { getArkosConfig } from \"../../server\";\nimport {\n processFile,\n processImage,\n} from \"./utils/helpers/file-uploader.helpers\";\nimport {\n accessAsync,\n mkdirAsync,\n statAsync,\n} from \"../../utils/helpers/fs.helpers\";\n\n/**\n * Handles file upload requests, processes images if needed, and returns URLs\n * Supports paths outside of the project directory with '../' prefix\n * @param {Request} req - Express request object\n * @param {Response} res - Express response object\n * @param {NextFunction} next - Express next middleware function\n */\nexport const uploadFile = catchAsync(\n async (req: Request, res: Response, next: NextFunction) => {\n const { fileType } = req.params;\n const { format, width, height, resizeTo } = req.query;\n const options = { format, width, height, resizeTo };\n\n const {\n documentUploaderService,\n fileUploaderService,\n imageUploaderService,\n videoUploaderService,\n } = getFileUploaderServices();\n\n const { fileUpload } = getArkosConfig();\n const baseUploadDir = fileUpload?.baseUploadDir || \"/uploads\";\n\n // Ensure upload directory exists\n const uploadPath = path.resolve(process.cwd(), baseUploadDir, fileType);\n try {\n await accessAsync(uploadPath);\n } catch (err) {\n // Create directory if it doesn't exist\n await mkdirAsync(uploadPath, { recursive: true });\n }\n\n // Select the appropriate uploader service based on file type\n let uploader: FileUploaderService;\n switch (fileType) {\n case \"images\":\n uploader = imageUploaderService;\n break;\n case \"videos\":\n uploader = videoUploaderService;\n break;\n case \"documents\":\n uploader = documentUploaderService;\n break;\n case \"files\":\n uploader = fileUploaderService;\n break;\n default:\n return next(new AppError(\"Invalid file type\", 400));\n }\n\n // Handle the file upload\n uploader.handleMultipleUpload()(req, res, async (err) => {\n if (err) return next(err);\n\n // Process all uploaded files\n let data;\n if (req.files && Array.isArray(req.files)) {\n if (fileType === \"images\") {\n // Process multiple image files with image transformations\n data = await Promise.all(\n req.files.map((file) => processImage(req, file.path, options))\n );\n } else {\n // Just store other file types without processing\n data = await Promise.all(\n req.files.map((file) => processFile(req, file.path))\n );\n }\n // Filter out any null values from failed processing\n data = data.filter((url) => url !== null);\n } else if (req.file) {\n // Process a single file\n if (fileType === \"images\") {\n data = await processImage(req, req.file.path, options);\n } else {\n data = await processFile(req, req.file.path);\n }\n } else {\n return next(new AppError(\"No file uploaded\", 400));\n }\n\n res.status(200).json({\n success: true,\n data,\n message: Array.isArray(data)\n ? `${data.length} files uploaded successfully`\n : \"File uploaded successfully\",\n });\n });\n }\n);\n\n/**\n * Handles file deletion requests\n * Supports paths outside of the project directory with '../' prefix\n * @param {Request} req - Express request object\n * @param {Response} res - Express response object\n * @param {NextFunction} next - Express next middleware function\n */\nexport const deleteFile = catchAsync(\n async (req: Request, res: Response, next: NextFunction) => {\n const { fileType, fileName } = req.params;\n\n // if (!fileName) {\n // return next(new AppError(\"File name is required\", 400));\n // }\n\n // if (!fileType) {\n // return next(new AppError(\"File type is required\", 400));\n // }\n\n // // Get the base upload directory from config\n // const { fileUpload } = getArkosConfig();\n // const baseUploadDir = fileUpload?.baseUploadDir || \"/uploads\";\n\n // // Construct the actual file path using path.resolve to handle '../' paths\n // const actualFilePath = path.resolve(\n // process.cwd(),\n // baseUploadDir,\n // fileType,\n // fileName\n // );\n\n const {\n documentUploaderService,\n fileUploaderService,\n imageUploaderService,\n videoUploaderService,\n } = getFileUploaderServices();\n\n let uploader: FileUploaderService;\n switch (fileType) {\n case \"images\":\n uploader = imageUploaderService;\n break;\n case \"videos\":\n uploader = videoUploaderService;\n break;\n case \"documents\":\n uploader = documentUploaderService;\n break;\n case \"files\":\n uploader = fileUploaderService;\n break;\n default:\n return next(new AppError(\"Invalid file type\", 400));\n }\n\n try {\n // // Check if file exists\n // await access(actualFilePath, fs.constants.F_OK);\n\n // // Delete the file\n // await unlink(actualFilePath);\n\n const fullUrl = `${req.protocol}://${req.get(\"host\")}${req.originalUrl}`;\n await uploader.deleteFileByUrl(fullUrl);\n\n res.status(200).json({\n success: true,\n message: \"File deleted successfully\",\n });\n } catch (error) {\n // File doesn't exist\n return next(new AppError(\"File not found\", 404));\n }\n }\n);\n\nexport const streamFile = catchAsync(\n async (req: Request, res: Response, next: NextFunction) => {\n const { fileName, fileType } = req.params;\n\n const filePath = path.join(\".\", \"uploads\", fileType, fileName);\n try {\n await accessAsync(filePath);\n } catch (err) {\n throw new AppError(\"File not found\", 404);\n }\n\n const fileStat = await statAsync(filePath);\n const fileSize = fileStat.size;\n const range = req.headers.range;\n\n if (range) {\n const [partialStart, partialEnd] = range.replace(/bytes=/, \"\").split(\"-\");\n const start = parseInt(partialStart, 10) || 0;\n const end = partialEnd ? parseInt(partialEnd, 10) : fileSize - 1;\n\n if (start >= fileSize || end >= fileSize) {\n res.status(416).json({ error: \"Range Not Satisfiable\" });\n return;\n }\n\n res.writeHead(206, {\n \"Content-Range\": `bytes ${start}-${end}/${fileSize}`,\n \"Accept-Ranges\": \"bytes\",\n \"Content-Length\": end - start + 1,\n \"Content-Type\": \"application/octet-stream\",\n \"Content-Disposition\": `inline; filename=\"${fileName}\"`,\n });\n\n fs.createReadStream(filePath, { start, end }).pipe(res);\n } else {\n res.writeHead(200, {\n \"Content-Length\": fileSize,\n \"Content-Type\": \"application/octet-stream\",\n \"Content-Disposition\": `inline; filename=\"${fileName}\"`,\n });\n fs.createReadStream(filePath).pipe(res);\n }\n }\n);\n"]}
|
|
@@ -1,13 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
4
|
};
|
|
@@ -21,30 +12,28 @@ const path_1 = __importDefault(require("path"));
|
|
|
21
12
|
const express_2 = __importDefault(require("express"));
|
|
22
13
|
const deepmerge_helper_1 = __importDefault(require("../../utils/helpers/deepmerge.helper"));
|
|
23
14
|
const router = (0, express_1.Router)();
|
|
24
|
-
function getFileUploaderRouter(
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
return router;
|
|
48
|
-
});
|
|
15
|
+
async function getFileUploaderRouter({ fileUpload }) {
|
|
16
|
+
const modelModules = await (0, models_helpers_1.importPrismaModelModules)("file-upload");
|
|
17
|
+
let { middlewares = {}, authConfigs = {} } = {};
|
|
18
|
+
if (modelModules) {
|
|
19
|
+
({ middlewares = {}, authConfigs = {} } = modelModules);
|
|
20
|
+
}
|
|
21
|
+
let basePathname = fileUpload?.baseRoute || "/api/uploads/";
|
|
22
|
+
if (!basePathname.startsWith("/"))
|
|
23
|
+
basePathname = "/" + basePathname;
|
|
24
|
+
if (!basePathname.endsWith("/"))
|
|
25
|
+
basePathname = basePathname + "/";
|
|
26
|
+
router.use(basePathname, auth_service_1.default.handleAuthenticationControl("view", authConfigs), auth_service_1.default.handleAccessControl("view", "file-upload", authConfigs), express_2.default.static(path_1.default.resolve(process.cwd(), fileUpload?.baseUploadDir || "uploads"), (0, deepmerge_helper_1.default)({
|
|
27
|
+
maxAge: "1y",
|
|
28
|
+
etag: true,
|
|
29
|
+
lastModified: true,
|
|
30
|
+
dotfiles: "ignore",
|
|
31
|
+
fallthrough: true,
|
|
32
|
+
index: false,
|
|
33
|
+
cacheControl: true,
|
|
34
|
+
}, fileUpload?.expressStaticOptions || {})));
|
|
35
|
+
router.post(`${basePathname}:fileType`, auth_service_1.default.handleAuthenticationControl("create", authConfigs), auth_service_1.default.handleAccessControl("create", "file-upload", authConfigs), file_uploader_controller_1.uploadFile);
|
|
36
|
+
router.delete(`${basePathname}:fileType/:fileName`, auth_service_1.default.handleAuthenticationControl("delete", authConfigs), auth_service_1.default.handleAccessControl("create", "file-upload", authConfigs), file_uploader_controller_1.deleteFile);
|
|
37
|
+
return router;
|
|
49
38
|
}
|
|
50
39
|
//# sourceMappingURL=file-uploader.router.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"file-uploader.router.js","sourceRoot":"","sources":["../../../../src/modules/file-uploader/file-uploader.router.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"file-uploader.router.js","sourceRoot":"","sources":["../../../../src/modules/file-uploader/file-uploader.router.ts"],"names":[],"mappings":";;;;;AAWA,sDAiDC;AA5DD,qCAAiC;AACjC,uEAA8E;AAC9E,wEAA+C;AAC/C,yEAAoE;AAEpE,gDAAwB;AACxB,sDAA8B;AAC9B,4FAA6D;AAE7D,MAAM,MAAM,GAAW,IAAA,gBAAM,GAAE,CAAC;AAEzB,KAAK,UAAU,qBAAqB,CAAC,EAAE,UAAU,EAAe;IACrE,MAAM,YAAY,GAAG,MAAM,IAAA,yCAAwB,EAAC,aAAa,CAAC,CAAC;IACnE,IAAI,EAAE,WAAW,GAAG,EAAE,EAAE,WAAW,GAAG,EAAE,EAAE,GAAG,EAAE,CAAC;IAEhD,IAAI,YAAY,EAAE,CAA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AC,mBAAmB,CAAC,QAAQ,EAAE,aAAa,EAAE,WAAW,CAAC,EACrE,qCAAU,CACX,CAAC;IAEF,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["import { Router } from \"express\";\nimport { importPrismaModelModules } from \"../../utils/helpers/models.helpers\";\nimport authService from \"../auth/auth.service\";\nimport { deleteFile, uploadFile } from \"./file-uploader.controller\";\nimport { ArkosConfig } from \"../../types/arkos-config\";\nimport path from \"path\";\nimport express from \"express\";\nimport deepmerge from \"../../utils/helpers/deepmerge.helper\";\n\nconst router: Router = Router();\n\nexport async function getFileUploaderRouter({ fileUpload }: ArkosConfig) {\n const modelModules = await importPrismaModelModules(\"file-upload\");\n let { middlewares = {}, authConfigs = {} } = {};\n\n if (modelModules) {\n ({ middlewares = {}, authConfigs = {} } = modelModules);\n }\n\n let basePathname = fileUpload?.baseRoute || \"/api/uploads/\";\n\n if (!basePathname.startsWith(\"/\")) basePathname = \"/\" + basePathname;\n if (!basePathname.endsWith(\"/\")) basePathname = basePathname + \"/\";\n\n router.use(\n basePathname,\n authService.handleAuthenticationControl(\"view\", authConfigs),\n authService.handleAccessControl(\"view\", \"file-upload\", authConfigs),\n express.static(\n path.resolve(process.cwd(), fileUpload?.baseUploadDir || \"uploads\"),\n deepmerge(\n {\n maxAge: \"1y\",\n etag: true,\n lastModified: true,\n dotfiles: \"ignore\",\n fallthrough: true,\n index: false,\n cacheControl: true,\n },\n fileUpload?.expressStaticOptions || {}\n )\n )\n );\n\n router.post(\n `${basePathname}:fileType`,\n authService.handleAuthenticationControl(\"create\", authConfigs),\n authService.handleAccessControl(\"create\", \"file-upload\", authConfigs),\n uploadFile\n );\n\n router.delete(\n `${basePathname}:fileType/:fileName`,\n authService.handleAuthenticationControl(\"delete\", authConfigs),\n authService.handleAccessControl(\"create\", \"file-upload\", authConfigs),\n deleteFile\n );\n\n return router;\n}\n"]}
|