badmfck-api-server 1.7.8 → 1.8.3

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.
@@ -30,6 +30,8 @@ export interface APIServiceOptions {
30
30
  password: string;
31
31
  }[];
32
32
  appVersion?: string;
33
+ fileTempDir: string;
34
+ fileLimit: number;
33
35
  }
34
36
  export declare function getDefaultOptions(): APIServiceOptions;
35
37
  export declare const REQ_CREATE_NET_LOG: Req<void, APIServiceNetworkLogItem>;
@@ -15,6 +15,8 @@ const Monitor_1 = require("./monitor/Monitor");
15
15
  const path_1 = __importDefault(require("path"));
16
16
  const crypto_1 = __importDefault(require("crypto"));
17
17
  const fs_1 = __importDefault(require("fs"));
18
+ const express_fileupload_1 = __importDefault(require("express-fileupload"));
19
+ const os_1 = __importDefault(require("os"));
18
20
  function getDefaultOptions() {
19
21
  return {
20
22
  port: 8091,
@@ -30,12 +32,14 @@ function getDefaultOptions() {
30
32
  onError: function (err) {
31
33
  (0, LogService_1.logError)("${APIService.js}", err);
32
34
  },
33
- isProductionEnvironment: false
35
+ isProductionEnvironment: false,
36
+ fileLimit: 50 * 1024 * 1024,
37
+ fileTempDir: path_1.default.resolve(os_1.default.tmpdir(), "fileTempDir"),
34
38
  };
35
39
  }
36
40
  exports.getDefaultOptions = getDefaultOptions;
37
- exports.REQ_CREATE_NET_LOG = new badmfck_signal_1.Req("REQ_CREATE_NET_LOG");
38
- exports.REQ_HTTP_LOG = new badmfck_signal_1.Req("REQ_HTTP_LOG");
41
+ exports.REQ_CREATE_NET_LOG = new badmfck_signal_1.Req(undefined, "REQ_CREATE_NET_LOG");
42
+ exports.REQ_HTTP_LOG = new badmfck_signal_1.Req(undefined, "REQ_HTTP_LOG");
39
43
  async function Initializer(services) {
40
44
  for (let i of services) {
41
45
  await i.init();
@@ -47,7 +51,7 @@ async function Initializer(services) {
47
51
  exports.Initializer = Initializer;
48
52
  class APIService extends BaseService_1.BaseService {
49
53
  static nextLogID = 0;
50
- version = "1.6.9";
54
+ version = "1.8.3";
51
55
  options;
52
56
  monitor;
53
57
  monitorIndexFile;
@@ -92,6 +96,21 @@ class APIService extends BaseService_1.BaseService {
92
96
  app.set("env", 'production');
93
97
  app.use(express_1.default.json({ limit: '10mb' }));
94
98
  app.use(express_1.default.urlencoded({ limit: '10mb', extended: true }));
99
+ app.use((0, express_fileupload_1.default)({
100
+ limitHandler: (req, res, next) => {
101
+ this.sendResponse(res, {
102
+ error: DefaultErrors_1.default.FILE_TOO_LARGE,
103
+ data: null,
104
+ httpStatus: 413
105
+ }, +new Date(), req.path);
106
+ },
107
+ limits: { fileSize: this.options.fileLimit },
108
+ useTempFiles: true,
109
+ uriDecodeFileNames: true,
110
+ tempFileDir: this.options.fileTempDir,
111
+ safeFileNames: true,
112
+ abortOnLimit: true
113
+ }));
95
114
  app.use(async (err, req, resp, next) => {
96
115
  if (!err) {
97
116
  next();
@@ -155,6 +174,7 @@ class APIService extends BaseService_1.BaseService {
155
174
  params: req.params,
156
175
  headers: req.headers,
157
176
  endpoint: ep,
177
+ files: req.files ?? null
158
178
  };
159
179
  let result;
160
180
  try {
@@ -33,7 +33,7 @@ const badmfck_signal_1 = __importStar(require("badmfck-signal"));
33
33
  const crypto_1 = require("crypto");
34
34
  const LogService_1 = require("./LogService");
35
35
  exports.S_MYSQL_STARTED = new badmfck_signal_1.default();
36
- exports.REQ_MYSQL_QUERY = new badmfck_signal_1.Req("REQ_MYSQL_QUERY");
36
+ exports.REQ_MYSQL_QUERY = new badmfck_signal_1.Req(undefined, "REQ_MYSQL_QUERY");
37
37
  const executeQuery = async (query) => { return await exports.REQ_MYSQL_QUERY.request(query); };
38
38
  exports.executeQuery = executeQuery;
39
39
  class MysqlService extends BaseService_1.BaseService {
@@ -3,6 +3,7 @@ declare class DefaultErrors {
3
3
  static NOT_IMPLEMENTED: IError;
4
4
  static UNKNOWN_REQUEST: IError;
5
5
  static JSON_MALFORMED: IError;
6
+ static FILE_TOO_LARGE: IError;
6
7
  }
7
8
  export declare class ErrorUtils {
8
9
  static isError(obj: any): boolean;
@@ -6,6 +6,7 @@ class DefaultErrors {
6
6
  static NOT_IMPLEMENTED = { code: 1, message: "Not implemented" };
7
7
  static UNKNOWN_REQUEST = { code: 2, message: "Unknown request" };
8
8
  static JSON_MALFORMED = { code: 3, message: "JSON malformed" };
9
+ static FILE_TOO_LARGE = { code: 4, message: "File is too large" };
9
10
  }
10
11
  class ErrorUtils {
11
12
  static isError(obj) {
@@ -1,3 +1,4 @@
1
+ import { FileArray, UploadedFile } from "express-fileupload";
1
2
  export interface TransferPacketVO<T> {
2
3
  data?: T | null;
3
4
  error?: IError | null;
@@ -12,17 +13,20 @@ export interface TransferPacketVO<T> {
12
13
  [key: string]: string;
13
14
  };
14
15
  }
15
- export interface HTTPRequestVO {
16
+ export interface HTTPRequestVO<T = any> {
16
17
  raw: any;
17
18
  method: string;
18
- data: any;
19
+ data: T;
19
20
  params: {
20
21
  [key: string]: string;
21
22
  };
22
- headers: any;
23
+ headers: {
24
+ [key: string]: string;
25
+ };
23
26
  endpoint: string;
24
27
  interceptorResult?: TransferPacketVO<any>;
25
28
  precheck?: TransferPacketVO<any> | null;
29
+ files: FileArray | UploadedFile | null | undefined;
26
30
  }
27
31
  export interface IError {
28
32
  code: number;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "badmfck-api-server",
3
- "version": "1.7.8",
3
+ "version": "1.8.3",
4
4
  "description": "Simple API http server based on express",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -17,18 +17,20 @@
17
17
  "express"
18
18
  ],
19
19
  "dependencies": {
20
+ "@types/express-fileupload": "^1.5.0",
20
21
  "@types/mysql": "^2.15.21",
21
22
  "@types/ws": "^8.5.9",
22
- "axios": "^1.4.0",
23
- "badmfck-signal": "^1.2.7",
23
+ "axios": "^1.6.8",
24
+ "badmfck-signal": "^1.4.5",
24
25
  "cors": "^2.8.5",
25
- "express": "^4.18.2",
26
+ "express": "^4.19.2",
27
+ "express-fileupload": "^1.5.0",
26
28
  "mysql": "^2.18.1",
27
29
  "ws": "^8.14.2"
28
30
  },
29
31
  "devDependencies": {
30
32
  "@types/cors": "^2.8.13",
31
- "@types/express": "^4.17.17"
33
+ "@types/express": "^4.17.21"
32
34
  },
33
35
  "author": "Igor Bloom",
34
36
  "license": "MIT"