cgserver 9.2.1 → 9.2.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.
@@ -4,14 +4,13 @@ exports.Config = void 0;
4
4
  const fs = require("fs");
5
5
  const jsonc_1 = require("jsonc");
6
6
  class Config {
7
- _suffix = "";
8
7
  _is_init = false;
9
8
  _file_name = "";
10
9
  /**
11
10
  * 是否是debug调试模式,主要区别于读取数据档,debug默认读取file_d文件,release默认读取file_r文件,如果不存在都会读取file文件
12
11
  */
13
12
  static debug = false;
14
- static rootDataDir = "data/";
13
+ static rootDataDir = "data";
15
14
  constructor(filename) {
16
15
  this._file_name = filename;
17
16
  }
@@ -19,27 +18,18 @@ class Config {
19
18
  if (this._is_init) {
20
19
  return false;
21
20
  }
22
- let suffix2 = "_r";
21
+ if (Config.rootDataDir.endsWith("/")) {
22
+ Config.rootDataDir = Config.rootDataDir.substring(0, Config.rootDataDir.length - 1);
23
+ }
24
+ let suffix2 = "/";
23
25
  if (Config.debug) {
24
- suffix2 = "_d";
26
+ suffix2 = "_d/";
25
27
  }
26
- let path = Config.rootDataDir + this._file_name + "_" + this._suffix + suffix2 + ".json";
28
+ let path = Config.rootDataDir + suffix2 + this._file_name + ".json";
27
29
  path = path.toLowerCase();
28
30
  if (!fs.existsSync(path)) {
29
- path = Config.rootDataDir + this._file_name + "_" + this._suffix + ".json";
30
- path = path.toLowerCase();
31
- if (!fs.existsSync(path)) {
32
- path = Config.rootDataDir + this._file_name + suffix2 + ".json";
33
- path = path.toLowerCase();
34
- if (!fs.existsSync(path)) {
35
- path = Config.rootDataDir + this._file_name + ".json";
36
- path = path.toLowerCase();
37
- if (!fs.existsSync(path)) {
38
- console.error(path + " not exist!");
39
- return true;
40
- }
41
- }
42
- }
31
+ console.error(path + " not exist!");
32
+ return false;
43
33
  }
44
34
  let content = fs.readFileSync(path).toString();
45
35
  let jsonData = jsonc_1.jsonc.parse(content);
@@ -11,7 +11,6 @@ class IServerConfig extends FrameworkConfig_1.FrameworkConfig {
11
11
  }
12
12
  constructor(server_name) {
13
13
  super();
14
- this._suffix = server_name;
15
14
  this._server_name = server_name;
16
15
  }
17
16
  init() {
@@ -5,7 +5,6 @@ const Property_1 = require("./Decorator/Property");
5
5
  const MysqlManager_1 = require("./MysqlManager");
6
6
  const Log_1 = require("../Logic/Log");
7
7
  const DBCache_1 = require("./Decorator/DBCache");
8
- const IServerConfig_1 = require("../Config/IServerConfig");
9
8
  class BaseModel {
10
9
  }
11
10
  exports.BaseModel = BaseModel;
@@ -42,7 +41,7 @@ class MysqlBaseService {
42
41
  throw new Error("数据表的类必须要具有Table装饰器");
43
42
  }
44
43
  this._table = "`" + table.table + "`";
45
- if (!IServerConfig_1.GServerCfg.db.mysql.auto) {
44
+ if (!MysqlManager_1.GMysqlMgr.cfg.auto) {
46
45
  //未开启自动创建数据表
47
46
  return;
48
47
  }
@@ -34,6 +34,10 @@ class MysqlManager {
34
34
  get isValid() {
35
35
  return !!this._pool;
36
36
  }
37
+ _cfg = null;
38
+ get cfg() {
39
+ return this._cfg;
40
+ }
37
41
  constructor() {
38
42
  }
39
43
  async init(cfg) {
@@ -42,6 +46,7 @@ class MysqlManager {
42
46
  || !cfg.open) {
43
47
  return;
44
48
  }
49
+ this._cfg = cfg;
45
50
  this._pool = mysql2.createPool(cfg.poolcfg);
46
51
  console.log("mysql config=" + JSON.stringify(cfg));
47
52
  //这个的初始化位置不能变,必须位于cbs前,pool后
@@ -1,5 +1,4 @@
1
1
  export declare class Config {
2
- protected _suffix: string;
3
2
  protected _is_init: boolean;
4
3
  protected _file_name: string;
5
4
  /**
@@ -20,6 +20,8 @@ declare class MysqlManager {
20
20
  protected _init_cbs: any[];
21
21
  protected _pool: mysql2.Pool;
22
22
  get isValid(): boolean;
23
+ protected _cfg: MysqlConfig;
24
+ get cfg(): MysqlConfig;
23
25
  constructor();
24
26
  init(cfg: MysqlConfig): Promise<void>;
25
27
  registerInitCb(cb: Function): void;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cgserver",
3
- "version": "9.2.1",
3
+ "version": "9.2.3",
4
4
  "author": "trojan",
5
5
  "type": "commonjs",
6
6
  "description": "free for all.Websocket or Http",