badmfck-api-server 1.7.7 → 1.8.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -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.2";
51
55
  options;
52
56
  monitor;
53
57
  monitorIndexFile;
@@ -92,6 +96,19 @@ 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
+ }));
95
112
  app.use(async (err, req, resp, next) => {
96
113
  if (!err) {
97
114
  next();
@@ -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 {
@@ -12,7 +12,7 @@ export declare class DataProvider<T> {
12
12
  data: T | null | undefined;
13
13
  error?: boolean;
14
14
  }>, cacheTime?: number, name?: string);
15
- forceUpdate(): void;
15
+ forceUpdate(): Promise<void>;
16
16
  localUpdate(data: T): void;
17
17
  getData(): Promise<T | null | undefined>;
18
18
  }
@@ -24,12 +24,12 @@ class DataProvider {
24
24
  if (!this.name)
25
25
  this.name = "DataProvider " + (DataProvider.nextID++);
26
26
  }
27
- forceUpdate() {
27
+ async forceUpdate() {
28
28
  if (this.busy)
29
29
  return;
30
30
  this.wasError = false;
31
31
  this.lastRequestTime = 0;
32
- this.getData();
32
+ await this.getData();
33
33
  }
34
34
  localUpdate(data) {
35
35
  if (this.busy)
@@ -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) {
@@ -12,14 +12,16 @@ export interface TransferPacketVO<T> {
12
12
  [key: string]: string;
13
13
  };
14
14
  }
15
- export interface HTTPRequestVO {
15
+ export interface HTTPRequestVO<T = any> {
16
16
  raw: any;
17
17
  method: string;
18
- data: any;
18
+ data: T;
19
19
  params: {
20
20
  [key: string]: string;
21
21
  };
22
- headers: any;
22
+ headers: {
23
+ [key: string]: string;
24
+ };
23
25
  endpoint: string;
24
26
  interceptorResult?: TransferPacketVO<any>;
25
27
  precheck?: TransferPacketVO<any> | null;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "badmfck-api-server",
3
- "version": "1.7.7",
3
+ "version": "1.8.2",
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"