badmfck-api-server 2.1.1 → 2.1.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -83,7 +83,7 @@ async function Initializer(services) {
83
83
  exports.Initializer = Initializer;
84
84
  class APIService extends BaseService_1.BaseService {
85
85
  static nextLogID = 0;
86
- version = "2.1.1";
86
+ version = "2.1.2";
87
87
  options;
88
88
  monitor;
89
89
  monitorIndexFile;
@@ -365,6 +365,24 @@ class APIService extends BaseService_1.BaseService {
365
365
  }
366
366
  else {
367
367
  try {
368
+ if (data.file) {
369
+ res.sendFile(data.file, err => {
370
+ if (err) {
371
+ if (log)
372
+ log.error = "Can't send file: " + data.file;
373
+ if (this.options.onError)
374
+ this.options.onError("Can't send file: " + data.file, err);
375
+ if (this.monitor && data.endpoint)
376
+ this.monitor.registrateAPIError(data.endpoint);
377
+ this.sendResponse(res, {
378
+ error: DefaultErrors_1.default.CANT_SEND_FILE,
379
+ data: null,
380
+ httpStatus: 500
381
+ }, requestTime, data.endpoint);
382
+ }
383
+ });
384
+ return;
385
+ }
368
386
  if (data.redirect) {
369
387
  res.redirect(data.redirect);
370
388
  if (log)
@@ -4,6 +4,8 @@ declare class DefaultErrors {
4
4
  static UNKNOWN_REQUEST: IError;
5
5
  static JSON_MALFORMED: IError;
6
6
  static FILE_TOO_LARGE: IError;
7
+ static CANT_SEND_FILE: IError;
8
+ static FILE_NOT_EXISTS: IError;
7
9
  }
8
10
  export declare class ErrorUtils {
9
11
  static isError(obj: any): boolean;
@@ -7,6 +7,8 @@ class DefaultErrors {
7
7
  static UNKNOWN_REQUEST = { code: 2, message: "Unknown request" };
8
8
  static JSON_MALFORMED = { code: 3, message: "JSON malformed" };
9
9
  static FILE_TOO_LARGE = { code: 4, message: "File is too large" };
10
+ static CANT_SEND_FILE = { code: 5, message: "Can't send file" };
11
+ static FILE_NOT_EXISTS = { code: 5, message: "File not exists" };
10
12
  }
11
13
  class ErrorUtils {
12
14
  static isError(obj) {
@@ -12,6 +12,7 @@ export interface TransferPacketVO<T = any> {
12
12
  headers?: {
13
13
  [key: string]: string;
14
14
  };
15
+ file?: string;
15
16
  }
16
17
  export interface HTTPRequestVO<T = any> {
17
18
  raw: any;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "badmfck-api-server",
3
- "version": "2.1.1",
3
+ "version": "2.1.2",
4
4
  "description": "Simple API http server based on express",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",