zhejiushizhuce пре 1 година
родитељ
комит
7e3eddf0ef
8 измењених фајлова са 217 додато и 7 уклоњено
  1. 2 2
      .gitignore
  2. 1 1
      app/middleware/execption.ts
  3. 1 1
      app/queue/sys.ts
  4. 1 1
      app/service/admin/comm/oss.ts
  5. 105 0
      config/config.local.ts
  6. 105 0
      config/config.prod.ts
  7. 1 1
      package.json
  8. 1 1
      tsconfig.json

+ 2 - 2
.gitignore

@@ -20,8 +20,8 @@ app/**/*.map
 test/**/*.map
 config/**/*.map
 
-config/config.local.ts
-config/config.prod.ts
+#config/config.local.ts
+#config/config.prod.ts
 
 typings/app/*
 typings/config/*

+ 1 - 1
app/middleware/execption.ts

@@ -7,7 +7,7 @@ export default function Exception(): any {
   return async (ctx: Context, next: () => Promise<any>) => {
     try {
       await next();
-    } catch (err) {
+    } catch (err: any) {
       const { errors } = err;
       ctx.logger.error('[Exception]', err.message, errors);
       ctx.set('Content-Type', 'application/json');

+ 1 - 1
app/queue/sys.ts

@@ -15,7 +15,7 @@ export default (app: Application) => {
       id = await ctx.service.admin.sys.taskLog.record(job.data.id, 0);
       await ctx.service.admin.sys.task.callService(job.data.service, job.data.args);
       await ctx.service.admin.sys.taskLog.updateTaskStatus(id, 1);
-    } catch (e) {
+    } catch (e:any) {
       if (id !== -1) {
         await ctx.service.admin.sys.taskLog.updateTaskStatus(id, 2, `${e.message}`);
       }

+ 1 - 1
app/service/admin/comm/oss.ts

@@ -63,7 +63,7 @@ export default class OssService extends BaseService {
           } else {
             // 200 is success, 298 is part success
             if (parseInt(respInfo.statusCode) / 100 === 2) {
-              resolve();
+              resolve(true);
             } else {
               reject(respInfo.deleteusCode);
               console.log(respInfo.deleteusCode);

+ 105 - 0
config/config.local.ts

@@ -0,0 +1,105 @@
+import { EggAppConfig, PowerPartial } from 'egg';
+
+export default () => {
+  const config: PowerPartial<EggAppConfig> = {};
+
+  /**
+   * https://github.com/puppeteer/puppeteer
+   */
+  config.puppeteer = {
+    launchOptions: {
+      args: [ '--no-sandbox', '--disable-setuid-sandbox' ],
+      executablePath: '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome',
+      ignoreHTTPSErrors: true,
+    },
+  };
+
+  /**
+   * 邮件推送配置
+   */
+  config.mailer = {
+    host: 'xxxxxxxx',
+    port: 25,
+    user: 'xxxx',
+    pass: 'xxxx',
+    secure: false,
+  };
+
+  /**
+   * 七牛配置
+   */
+  config.qiniu = {
+    accessKey: 'xxxxx',
+    secretKey: 'xxxx',
+    bucket: 'xxxx',
+    cdnUrl: 'xxxx',
+    zone: 'xxx',
+  };
+
+  // bull config
+  config.bull = {
+    default: {
+      redis: {
+        port: 6379,
+        host: '127.0.0.1',
+        password: '123456',
+        db: 0,
+      },
+      prefix: 'admin:task',
+    },
+  };
+
+  /**
+   * typeorm 配置
+   * 文档:https://www.npmjs.com/package/egg-ts-typeorm
+   */
+  config.typeorm = {
+    client: {
+      type: 'mysql',
+      host: '127.0.0.1',
+      port: 3306,
+      username: 'root',
+      password: 'xdh192358',
+      database: 'tgbot',
+      synchronize: false,
+      logging: true,
+      // timezone: '+08:00',
+      /**
+       * JavaScript对数据库中int和bigint的区别对待:
+       * 刚开始开发中,线下测试数据库id字段采用int,数据库SELECT操作返回的结果是Number,但是使用bigint,数据库返回的为String,
+       * 初步猜想是因为bigint的值范围会超过Number,所以采用String。但是这样会对我们业务产生巨大影戏那个,一方面,DTO校验会无法通过,另一方面,问题1中的业务逻辑会受影响。
+       * 经过查找各方文档,解决方案是在数据库连接配置中配置:
+       * "supportBigNumbers": false
+       * 可以配置这个的原因是我们的业务ID距离Number的上线远远达不到,所以可以用这种方式让
+       * bigint也返回Number。
+       * 但是这样配置,TypeOrm插入操作的返回值中的identifiers字段中的id还是String,所以问题1中的处理方式也要对String进行parseInt操作。
+       */
+      supportBigNumbers: false,
+    },
+  };
+
+  /**
+   * redis 配置
+   * https://github.com/eggjs/egg-redis
+   */
+  config.redis = {
+    Redis: require('ioredis'),
+    clients: {
+      // instanceName. See below
+      admin: {
+        port: 6379,
+        host: '127.0.0.1',
+        password: '',
+        db: 0,
+      },
+      app: {
+        port: 6379,
+        host: '127.0.0.1',
+        password: '',
+        db: 1,
+      },
+    },
+  };
+
+  return config;
+};

+ 105 - 0
config/config.prod.ts

@@ -0,0 +1,105 @@
+import { EggAppConfig, PowerPartial } from 'egg';
+
+export default () => {
+  const config: PowerPartial<EggAppConfig> = {};
+
+  /**
+   * https://github.com/puppeteer/puppeteer
+   */
+  config.puppeteer = {
+    launchOptions: {
+      args: [ '--no-sandbox', '--disable-setuid-sandbox' ],
+      executablePath: '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome',
+      ignoreHTTPSErrors: true,
+    },
+  };
+
+  /**
+   * 邮件推送配置
+   */
+  config.mailer = {
+    host: 'xxxxxxxx',
+    port: 25,
+    user: 'xxxx',
+    pass: 'xxxx',
+    secure: false,
+  };
+
+  /**
+   * 七牛配置
+   */
+  config.qiniu = {
+    accessKey: 'xxxxx',
+    secretKey: 'xxxx',
+    bucket: 'xxxx',
+    cdnUrl: 'xxxx',
+    zone: 'xxx',
+  };
+
+  // bull config
+  config.bull = {
+    default: {
+      redis: {
+        port: 6379,
+        host: '127.0.0.1',
+        password: '123456',
+        db: 0,
+      },
+      prefix: 'admin:task',
+    },
+  };
+
+  /**
+   * typeorm 配置
+   * 文档:https://www.npmjs.com/package/egg-ts-typeorm
+   */
+  config.typeorm = {
+    client: {
+      type: 'mysql',
+      host: '127.0.0.1',
+      port: 3306,
+      username: 'root',
+      password: 'xdh192358',
+      database: 'tgbot',
+      synchronize: false,
+      logging: true,
+      // timezone: '+08:00',
+      /**
+       * JavaScript对数据库中int和bigint的区别对待:
+       * 刚开始开发中,线下测试数据库id字段采用int,数据库SELECT操作返回的结果是Number,但是使用bigint,数据库返回的为String,
+       * 初步猜想是因为bigint的值范围会超过Number,所以采用String。但是这样会对我们业务产生巨大影戏那个,一方面,DTO校验会无法通过,另一方面,问题1中的业务逻辑会受影响。
+       * 经过查找各方文档,解决方案是在数据库连接配置中配置:
+       * "supportBigNumbers": false
+       * 可以配置这个的原因是我们的业务ID距离Number的上线远远达不到,所以可以用这种方式让
+       * bigint也返回Number。
+       * 但是这样配置,TypeOrm插入操作的返回值中的identifiers字段中的id还是String,所以问题1中的处理方式也要对String进行parseInt操作。
+       */
+      supportBigNumbers: false,
+    },
+  };
+
+  /**
+   * redis 配置
+   * https://github.com/eggjs/egg-redis
+   */
+  config.redis = {
+    Redis: require('ioredis'),
+    clients: {
+      // instanceName. See below
+      admin: {
+        port: 6379,
+        host: '127.0.0.1',
+        password: '',
+        db: 0,
+      },
+      app: {
+        port: 6379,
+        host: '127.0.0.1',
+        password: '',
+        db: 1,
+      },
+    },
+  };
+
+  return config;
+};

+ 1 - 1
package.json

@@ -73,7 +73,7 @@
     "eslint": "^6.7.2",
     "eslint-config-egg": "^8.0.0",
     "tslib": "^1.9.0",
-    "typescript": "^3.0.0"
+    "typescript": "^5.8.3"
   },
   "engines": {
     "node": ">=8.9.0"

+ 1 - 1
tsconfig.json

@@ -7,7 +7,7 @@
     "noImplicitAny": false,
     "experimentalDecorators": true,
     "emitDecoratorMetadata": true,
-    "charset": "utf8",
+//    "charset": "utf8",
     "allowJs": false,
     "pretty": true,
     "noEmitOnError": false,