midway-fatcms 0.0.1-beta.18 → 0.0.1-beta.19

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.
Files changed (121) hide show
  1. package/.eslintrc.json +3 -1
  2. package/dist/controller/gateway/AsyncTaskController.js +3 -3
  3. package/dist/controller/gateway/DocGatewayController.js +1 -1
  4. package/dist/controller/gateway/PublicApiController.js +4 -6
  5. package/dist/controller/gateway/StaticController.js +25 -22
  6. package/dist/controller/helpers.controller.d.ts +1 -1
  7. package/dist/controller/manage/CrudStandardDesignApi.d.ts +1 -1
  8. package/dist/controller/manage/CrudStandardDesignApi.js +4 -16
  9. package/dist/controller/manage/DataDictManageApi.d.ts +1 -1
  10. package/dist/controller/manage/DeployManageApi.d.ts +1 -1
  11. package/dist/controller/manage/DeployManageApi.js +32 -30
  12. package/dist/controller/manage/MenuManageApi.js +1 -1
  13. package/dist/controller/manage/SuperAdminManageApi.d.ts +2 -2
  14. package/dist/controller/manage/SysConfigMangeApi.d.ts +1 -1
  15. package/dist/controller/manage/SysConfigMangeApi.js +3 -3
  16. package/dist/controller/manage/SystemInfoManageApi.d.ts +1 -1
  17. package/dist/controller/manage/SystemInfoManageApi.js +7 -1
  18. package/dist/controller/manage/UserAccountManageApi.d.ts +1 -1
  19. package/dist/controller/manage/WorkbenchMangeApi.js +1 -1
  20. package/dist/controller/myinfo/AuthController.js +1 -1
  21. package/dist/controller/render/AppRenderController.js +6 -2
  22. package/dist/controller/test.controller.d.ts +1 -1
  23. package/dist/controller/test.controller.js +4 -4
  24. package/dist/libs/crud-pro/models/ExecuteContext.d.ts +1 -1
  25. package/dist/libs/crud-pro/models/TransactionSqlServer.js +1 -1
  26. package/dist/libs/crud-pro/services/CrudProCachedCfgService.js +1 -1
  27. package/dist/libs/crud-pro/services/CrudProExecuteSqlService.js +7 -6
  28. package/dist/libs/crud-pro/services/CrudProGenSqlCondition.d.ts +1 -1
  29. package/dist/libs/crud-pro/services/CrudProGenSqlCondition.js +2 -4
  30. package/dist/libs/crud-pro/services/CrudProGenSqlService.js +6 -15
  31. package/dist/libs/crud-pro/services/CrudProOriginToExecuteSql.js +5 -4
  32. package/dist/libs/crud-pro/services/CrudProTableMetaService.js +2 -2
  33. package/dist/libs/crud-pro/utils/MixinUtils.js +1 -1
  34. package/dist/libs/crud-pro/utils/ValidateUtils.js +1 -1
  35. package/dist/libs/utils/fatcms-request.js +2 -2
  36. package/dist/middleware/forbidden.middleware.js +4 -20
  37. package/dist/middleware/global.middleware.js +1 -4
  38. package/dist/models/AsyncTaskModel.d.ts +2 -1
  39. package/dist/models/RedisKeys.d.ts +8 -0
  40. package/dist/models/RedisKeys.js +11 -0
  41. package/dist/schedule/runSchedule.d.ts +1 -0
  42. package/dist/schedule/runSchedule.js +9 -6
  43. package/dist/service/UserSessionService.js +2 -1
  44. package/dist/service/VisitStatService.d.ts +1 -1
  45. package/dist/service/VisitStatService.js +16 -25
  46. package/dist/service/asyncTask/AsyncTaskRunnerService.d.ts +9 -3
  47. package/dist/service/asyncTask/AsyncTaskRunnerService.js +57 -21
  48. package/dist/service/asyncTask/AsyncTaskService.d.ts +1 -1
  49. package/dist/service/asyncTask/AsyncTaskService.js +3 -2
  50. package/package.json +1 -1
  51. package/src/controller/base/BaseApiController.ts +6 -6
  52. package/src/controller/gateway/AsyncTaskController.ts +17 -22
  53. package/src/controller/gateway/CrudMtdGatewayController.ts +7 -7
  54. package/src/controller/gateway/CrudStdGatewayController.ts +4 -4
  55. package/src/controller/gateway/DocGatewayController.ts +17 -17
  56. package/src/controller/gateway/FileController.ts +8 -9
  57. package/src/controller/gateway/ProxyApiGatewayController.ts +4 -4
  58. package/src/controller/gateway/PublicApiController.ts +19 -22
  59. package/src/controller/gateway/StaticController.ts +234 -264
  60. package/src/controller/helpers.controller.ts +1 -1
  61. package/src/controller/home.controller.ts +0 -5
  62. package/src/controller/manage/AnyApiMangeApi.ts +4 -4
  63. package/src/controller/manage/AppLogMangeApi.ts +3 -3
  64. package/src/controller/manage/AppMangeApi.ts +5 -5
  65. package/src/controller/manage/AppPageMangeApi.ts +3 -3
  66. package/src/controller/manage/AppSchemaHistoryApi.ts +1 -1
  67. package/src/controller/manage/CrudMethodsMangeApi.ts +3 -3
  68. package/src/controller/manage/CrudStandardDesignApi.ts +25 -77
  69. package/src/controller/manage/DataDictManageApi.ts +4 -4
  70. package/src/controller/manage/DeployManageApi.ts +84 -91
  71. package/src/controller/manage/DocLibManageApi.ts +3 -3
  72. package/src/controller/manage/DocManageApi.ts +3 -3
  73. package/src/controller/manage/MenuManageApi.ts +9 -14
  74. package/src/controller/manage/SuperAdminManageApi.ts +2 -10
  75. package/src/controller/manage/SysConfigMangeApi.ts +8 -11
  76. package/src/controller/manage/SystemInfoManageApi.ts +11 -6
  77. package/src/controller/manage/UserAccountManageApi.ts +2 -2
  78. package/src/controller/manage/WorkbenchMangeApi.ts +6 -6
  79. package/src/controller/myinfo/AuthController.ts +4 -8
  80. package/src/controller/render/AppRenderController.ts +8 -8
  81. package/src/controller/test.controller.ts +17 -17
  82. package/src/index.ts +0 -1
  83. package/src/libs/crud-pro/CrudPro.ts +0 -1
  84. package/src/libs/crud-pro/interfaces.ts +1 -3
  85. package/src/libs/crud-pro/models/ExecuteContext.ts +1 -4
  86. package/src/libs/crud-pro/models/ExecuteContextFunc.ts +1 -2
  87. package/src/libs/crud-pro/models/RequestModel.ts +1 -1
  88. package/src/libs/crud-pro/models/ResModel.ts +7 -12
  89. package/src/libs/crud-pro/models/SqlCfgModel.ts +1 -1
  90. package/src/libs/crud-pro/models/Transaction.ts +8 -9
  91. package/src/libs/crud-pro/models/TransactionPostgres.ts +1 -1
  92. package/src/libs/crud-pro/models/TransactionSqlServer.ts +8 -13
  93. package/src/libs/crud-pro/services/CrudProCachedCfgService.ts +1 -3
  94. package/src/libs/crud-pro/services/CrudProExecuteSqlService.ts +36 -48
  95. package/src/libs/crud-pro/services/CrudProGenSqlCondition.ts +19 -38
  96. package/src/libs/crud-pro/services/CrudProGenSqlService.ts +15 -32
  97. package/src/libs/crud-pro/services/CrudProOriginToExecuteSql.ts +23 -27
  98. package/src/libs/crud-pro/services/CrudProServiceBase.ts +1 -2
  99. package/src/libs/crud-pro/services/CrudProTableMetaService.ts +6 -14
  100. package/src/libs/crud-pro/utils/DateTimeUtils.ts +2 -2
  101. package/src/libs/crud-pro/utils/MixinUtils.ts +1 -1
  102. package/src/libs/crud-pro/utils/ValidateUtils.ts +1 -3
  103. package/src/libs/crud-pro/utils/pool/MySQLUtils.ts +1 -1
  104. package/src/libs/crud-pro/utils/pool/PostgresUtils.ts +3 -3
  105. package/src/libs/crud-pro/utils/pool/SqlServerUtils.ts +3 -3
  106. package/src/libs/global-config/global-config.ts +0 -5
  107. package/src/libs/utils/crypto-utils.ts +2 -4
  108. package/src/libs/utils/errorToString.ts +3 -8
  109. package/src/libs/utils/fatcms-request.ts +9 -21
  110. package/src/libs/utils/ordernum-utils.ts +2 -6
  111. package/src/libs/utils/parseConfig.ts +7 -15
  112. package/src/middleware/forbidden.middleware.ts +6 -25
  113. package/src/middleware/global.middleware.ts +10 -21
  114. package/src/models/AsyncTaskModel.ts +3 -2
  115. package/src/models/RedisKeys.ts +13 -0
  116. package/src/models/bizmodels.ts +1 -2
  117. package/src/schedule/runSchedule.ts +16 -11
  118. package/src/service/UserSessionService.ts +5 -4
  119. package/src/service/VisitStatService.ts +55 -71
  120. package/src/service/asyncTask/AsyncTaskRunnerService.ts +119 -88
  121. package/src/service/asyncTask/AsyncTaskService.ts +9 -9
@@ -15,7 +15,7 @@ function hashUtf8Hex(data: string): string {
15
15
  return hash.digest('hex');
16
16
  }
17
17
 
18
- function readSeed1() {
18
+ function readSeed1() {
19
19
  // 这个文件肯定存在
20
20
  const t = path.join(__dirname, '../../config/seed/aeskey.txt');
21
21
  return fs.readFileSync(t, 'utf-8');
@@ -29,8 +29,7 @@ function readSeed2(): string {
29
29
  return fs.readFileSync(filePath, 'utf-8');
30
30
  }
31
31
 
32
-
33
- function createAes128BySeedContent(seedContent:string){
32
+ function createAes128BySeedContent(seedContent: string) {
34
33
  const hash1 = hashUtf8Hex(seedContent.trim());
35
34
  const key = md5(hash1);
36
35
  const iv = md5(key + hash1);
@@ -46,7 +45,6 @@ function createAes128BySeedFile() {
46
45
  return createAes128BySeedContent(seed1);
47
46
  }
48
47
 
49
-
50
48
  const privateAES = createAes128BySeedFile();
51
49
 
52
50
  export { privateAES };
@@ -1,4 +1,4 @@
1
- function errorToString(error:any): string {
1
+ function errorToString(error: any): string {
2
2
  // 处理非错误对象的情况
3
3
  if (typeof error === 'undefined') {
4
4
  return 'Error: undefined was thrown';
@@ -32,9 +32,7 @@ function errorToString(error:any): string {
32
32
  }
33
33
  });
34
34
 
35
- const customProps = Object.keys(error).filter(
36
- key => !['name', 'message', 'stack', ...extraProperties].includes(key)
37
- );
35
+ const customProps = Object.keys(error).filter(key => !['name', 'message', 'stack', ...extraProperties].includes(key));
38
36
 
39
37
  if (customProps.length > 0) {
40
38
  errorDetails.push('Custom Properties:');
@@ -60,7 +58,4 @@ function errorToString(error:any): string {
60
58
  }
61
59
  }
62
60
 
63
-
64
- export {
65
- errorToString
66
- }
61
+ export { errorToString };
@@ -1,9 +1,9 @@
1
1
  import { Context } from '@midwayjs/koa';
2
2
  import * as _ from 'lodash';
3
- import {privateAES} from "./crypto-utils";
4
- import {CommonException} from "../crud-pro/exceptions";
3
+ import { privateAES } from './crypto-utils';
4
+ import { CommonException } from '../crud-pro/exceptions';
5
5
 
6
- function isEnableByHeaderKey(ctx: Context, configName: string){
6
+ function isEnableByHeaderKey(ctx: Context, configName: string) {
7
7
  const fatcmsDebug = ctx.app.getConfig(configName);
8
8
  const headerKey = _.get(fatcmsDebug, 'headerKey');
9
9
  const headerSecret = _.get(fatcmsDebug, 'headerSecret');
@@ -14,7 +14,6 @@ function isEnableByHeaderKey(ctx: Context, configName: string){
14
14
  return headers[headerKey] === headerSecret;
15
15
  }
16
16
 
17
-
18
17
  /**
19
18
  * 是否开启调试能力
20
19
  * @param ctx
@@ -23,7 +22,6 @@ export function isEnableDebug(ctx: Context): boolean {
23
22
  return isEnableByHeaderKey(ctx, 'fatcmsDebug');
24
23
  }
25
24
 
26
-
27
25
  /**
28
26
  * 是否开启SA账号。只有账号密码没有用,必须通过ModHeader插件设置如下字段
29
27
  * @param ctx
@@ -32,7 +30,6 @@ export function isEnableSuperAdmin(ctx: Context): boolean {
32
30
  return isEnableByHeaderKey(ctx, 'fatcmsSAEnable');
33
31
  }
34
32
 
35
-
36
33
  export function isLocalEnv(ctx: Context): boolean {
37
34
  // 系统内部调用。如定时任务,没有request对象。
38
35
  if (!ctx.request) {
@@ -42,8 +39,6 @@ export function isLocalEnv(ctx: Context): boolean {
42
39
  return host.startsWith('127.0.0.1') || host.startsWith('localhost:');
43
40
  }
44
41
 
45
-
46
-
47
42
  /**
48
43
  * 获取调试时专用的站点code
49
44
  * @param ctx
@@ -62,32 +57,26 @@ export function getDebugProxyTarget(ctx: Context): string {
62
57
  return headers['fatcmsdebugproxytarget'];
63
58
  }
64
59
 
65
-
66
- export function getCsrfToken(ctx: Context): string{
60
+ export function getCsrfToken(ctx: Context): string {
67
61
  const headers = _.get(ctx, 'request.headers') || {};
68
62
  return headers['fatcmscsrftoken'];
69
63
  }
70
64
 
71
-
72
65
  /**
73
66
  * 扩展的源码应用:本地开发调试时加载本地的js脚本
74
67
  * @param ctx
75
68
  */
76
- export function getExtLocalLoaderPort(ctx: Context) : string {
69
+ export function getExtLocalLoaderPort(ctx: Context): string {
77
70
  const headers = _.get(ctx, 'request.headers') || {};
78
71
  return headers['fatcmsextlocalloaderport'];
79
72
  }
80
73
 
81
-
82
-
83
74
  export async function isCsrfTokenValid(ctx: Context): Promise<boolean> {
84
-
85
75
  // 本地开发,不需要校验
86
76
  if (isLocalEnv(ctx) || isEnableDebug(ctx)) {
87
77
  return true;
88
78
  }
89
79
 
90
-
91
80
  const fatcmscsrftoken = getCsrfToken(ctx);
92
81
  if (!fatcmscsrftoken) {
93
82
  return false;
@@ -96,20 +85,19 @@ export async function isCsrfTokenValid(ctx: Context): Promise<boolean> {
96
85
  const depryptToken = await privateAES.time_decrypt_base64_utf8(fatcmscsrftoken);
97
86
  if (depryptToken) {
98
87
  const num = Number(depryptToken);
99
- if (num && ((num + 6 * 3600 * 1000) > Date.now())) {
88
+ if (num && num + 6 * 3600 * 1000 > Date.now()) {
100
89
  return true;
101
90
  }
102
91
  }
103
92
  } catch (e) {
104
- console.info('isCsrfTokenValid验证失败')
93
+ console.info('isCsrfTokenValid验证失败');
105
94
  }
106
95
  return false;
107
96
  }
108
97
 
109
-
110
98
  export async function assertCsrfToken(ctx: Context) {
111
- const isOK = await isCsrfTokenValid(ctx);
99
+ const isOK = await isCsrfTokenValid(ctx);
112
100
  if (!isOK) {
113
- throw new CommonException("ASSERT_CSRF_TOKEN_ERROR", "CSRF_TOKEN 验证失败")
101
+ throw new CommonException('ASSERT_CSRF_TOKEN_ERROR', 'CSRF_TOKEN 验证失败');
114
102
  }
115
103
  }
@@ -1,7 +1,6 @@
1
1
  import * as moment from 'moment';
2
2
 
3
-
4
- function generateOrderNumber(prefix:string = 'NO'): string {
3
+ function generateOrderNumber(prefix = 'NO'): string {
5
4
  // 获取当前时间并格式化为YYYYMMDDHHmmss
6
5
  const timestamp = moment().format('YYYYMMDDHHmmss');
7
6
 
@@ -12,7 +11,4 @@ function generateOrderNumber(prefix:string = 'NO'): string {
12
11
  return prefix + timestamp + randomDigits;
13
12
  }
14
13
 
15
-
16
- export {
17
- generateOrderNumber
18
- }
14
+ export { generateOrderNumber };
@@ -1,7 +1,5 @@
1
1
  import * as _ from 'lodash';
2
- import {parseJsonObject} from "./functions";
3
-
4
-
2
+ import { parseJsonObject } from './functions';
5
3
 
6
4
  interface IEnumInfo {
7
5
  label: string;
@@ -9,14 +7,14 @@ interface IEnumInfo {
9
7
  children?: IEnumInfo[];
10
8
  }
11
9
 
12
- function parseTreeTableToIEnumInfo(dataSource:any[]): IEnumInfo[]{
10
+ function parseTreeTableToIEnumInfo(dataSource: any[]): IEnumInfo[] {
13
11
  if (!dataSource || !Array.isArray(dataSource)) {
14
12
  return undefined;
15
13
  }
16
- return dataSource.map((item: any) => {
17
- const {key, nodeName, value, label } = item;
14
+ return dataSource.map((item: any) => {
15
+ const { key, nodeName, value, label } = item;
18
16
  const children = parseTreeTableToIEnumInfo(item.children);
19
- const enumInfo: IEnumInfo = {
17
+ const enumInfo: IEnumInfo = {
20
18
  label: label || nodeName,
21
19
  value: value || key,
22
20
  };
@@ -27,9 +25,7 @@ function parseTreeTableToIEnumInfo(dataSource:any[]): IEnumInfo[]{
27
25
  });
28
26
  }
29
27
 
30
-
31
28
  function parseConfigContentToEnumInfo(configEntity: any): IEnumInfo[] {
32
-
33
29
  const { config_content, config_type } = configEntity;
34
30
 
35
31
  const configObj = parseJsonObject(config_content);
@@ -52,11 +48,7 @@ function parseConfigContentToEnumInfo(configEntity: any): IEnumInfo[] {
52
48
  if (Array.isArray(configObj)) {
53
49
  return configObj;
54
50
  }
55
- return []
51
+ return [];
56
52
  }
57
53
 
58
-
59
- export {
60
- parseConfigContentToEnumInfo,
61
- IEnumInfo
62
- }
54
+ export { parseConfigContentToEnumInfo, IEnumInfo };
@@ -1,36 +1,18 @@
1
1
  import { Middleware, IMiddleware } from '@midwayjs/core';
2
2
  import { NextFunction, Context } from '@midwayjs/koa';
3
3
 
4
-
5
4
  // 一些爬虫/漏洞分析工具会来请求这玩意。
6
- const blackEqualList = [
7
- '/config.json',
8
- '/backend/.env',
9
- '/application.yml',
10
- '/db.ini',
11
- '/.well-known/security.txt',
12
- ];
5
+ const blackEqualList = ['/config.json', '/backend/.env', '/application.yml', '/db.ini', '/.well-known/security.txt'];
13
6
 
14
- const blackPrefixList = [
15
- '/.aws/',
16
- '/.git/',
17
- '/.svn/',
18
- '/.env/',
19
- '/src/',
20
- '/var/logs/',
21
- '/var/log/',
22
- '/cgi-bin/',
23
- '/php-cgi/',
24
- ];
7
+ const blackPrefixList = ['/.aws/', '/.git/', '/.svn/', '/.env/', '/src/', '/var/logs/', '/var/log/', '/cgi-bin/', '/php-cgi/'];
25
8
 
26
9
  /**
27
10
  * 针对一些路径禁止访问。避免一些爬虫抓取网站内容,实际上这里枚举的路径,本身就是不存在的。只是为了提前拦截,为了服务器性能考虑。
28
11
  */
29
12
  @Middleware()
30
13
  export class ForbiddenMiddleware implements IMiddleware<Context, NextFunction> {
31
-
32
14
  match(ctx: Context): boolean {
33
- const path = ctx.path ;
15
+ const path = ctx.path;
34
16
  if (path === '/') {
35
17
  return false;
36
18
  }
@@ -53,15 +35,14 @@ export class ForbiddenMiddleware implements IMiddleware<Context, NextFunction> {
53
35
  }
54
36
  }
55
37
 
56
- return !!(path.includes('/wp-includes/') || path.endsWith('.php') || path.endsWith('/.git/config'));
38
+ return !!(path.includes('/wp-includes/') || path.endsWith('.php') || path.endsWith('/.git/config'));
57
39
  }
58
40
 
59
-
60
41
  resolve() {
61
42
  return async (ctx: Context, next: NextFunction) => {
62
- ctx.set({"content-type": "text/html; charset=utf-8"});
43
+ ctx.set({ 'content-type': 'text/html; charset=utf-8' });
63
44
  ctx.status = 404;
64
- ctx.body = "404!404!404!重要的事情说三遍!"
45
+ ctx.body = '404!404!404!重要的事情说三遍!';
65
46
  };
66
47
  }
67
48
 
@@ -1,15 +1,15 @@
1
1
  import { Middleware, IMiddleware } from '@midwayjs/core';
2
2
  import { NextFunction, Context } from '@midwayjs/koa';
3
3
  import * as _ from 'lodash';
4
- import { Transaction } from '../libs/crud-pro/models/Transaction';
5
- import { UserSessionService } from '../service/UserSessionService';
6
- import { WorkbenchService } from '../service/WorkbenchService';
7
- import { ISessionInfo, UserSessionInfo } from '../models/userSession';
8
- import { ICommonResult, CommonResult } from '../libs/utils/common-dto';
9
- import {isEnableDebug, isEnableSuperAdmin} from '../libs/utils/fatcms-request';
10
- import { ContextLogger } from '../models/contextLogger';
4
+ import { Transaction } from '@/libs/crud-pro/models/Transaction';
5
+ import { UserSessionService } from '@/service/UserSessionService';
6
+ import { WorkbenchService } from '@/service/WorkbenchService';
7
+ import { ISessionInfo, UserSessionInfo } from '@/models/userSession';
8
+ import { ICommonResult, CommonResult } from '@/libs/utils/common-dto';
9
+ import { isEnableDebug, isEnableSuperAdmin } from '@/libs/utils/fatcms-request';
10
+ import { ContextLogger } from '@/models/contextLogger';
11
11
  import { Stream } from 'node:stream';
12
- import {VisitStatService} from "../service/VisitStatService";
12
+ import { VisitStatService } from '@/service/VisitStatService';
13
13
 
14
14
  function isFunction(fun: any): boolean {
15
15
  return typeof fun === 'function';
@@ -141,8 +141,6 @@ async function getVisitStatService(ctx: Context): Promise<VisitStatService> {
141
141
  return ctx.requestContext.getAsync(VisitStatService);
142
142
  }
143
143
 
144
-
145
-
146
144
  /**
147
145
  * 检查是否是超级管理员
148
146
  * @param ctx
@@ -199,7 +197,6 @@ function handleDebugError(e: any, ctx: Context): ICommonResult {
199
197
  return res;
200
198
  }
201
199
 
202
-
203
200
  async function trackRequest(ctx: Context) {
204
201
  try {
205
202
  const visitStatService = await getVisitStatService(ctx);
@@ -209,19 +206,13 @@ async function trackRequest(ctx: Context) {
209
206
  }
210
207
  }
211
208
 
212
-
213
- const excludePathPrefix = [
214
- '/ns/static/',
215
- '/ns/api/helpers'
216
- ];
217
-
209
+ const excludePathPrefix = ['/ns/static/', '/ns/api/helpers'];
218
210
 
219
211
  /**
220
212
  * 全局中间件
221
213
  */
222
214
  @Middleware()
223
215
  export class GlobalMiddleware implements IMiddleware<Context, NextFunction> {
224
-
225
216
  match(ctx: Context): boolean {
226
217
  const path: string = ctx.path;
227
218
  for (let i = 0; i < excludePathPrefix.length; i++) {
@@ -239,7 +230,6 @@ export class GlobalMiddleware implements IMiddleware<Context, NextFunction> {
239
230
  ctx.transaction = new Transaction();
240
231
 
241
232
  try {
242
-
243
233
  // 支持的站点
244
234
  const workbenchService = await getWorkbenchService(ctx);
245
235
  const isSupportTheHost = await workbenchService.isSupportCurrentHostForForMiddleware();
@@ -255,7 +245,7 @@ export class GlobalMiddleware implements IMiddleware<Context, NextFunction> {
255
245
  ctx.workbenchInfo = await workbenchService.getCurrentHostWorkbenchInfo();
256
246
 
257
247
  // 数据埋点
258
- await trackRequest(ctx)
248
+ await trackRequest(ctx);
259
249
 
260
250
  const res0 = await next();
261
251
 
@@ -269,7 +259,6 @@ export class GlobalMiddleware implements IMiddleware<Context, NextFunction> {
269
259
  return res0;
270
260
  }
271
261
 
272
-
273
262
  // 其他:普通的JSON数据
274
263
  let res = handleExecuteSqlContext(res0);
275
264
  res = handleNullRes(res);
@@ -36,6 +36,8 @@ export interface SysAsyncTaskEntity {
36
36
  created_user_session: string;
37
37
  }
38
38
 
39
+ export type SysAsyncTaskPartial = Partial<SysAsyncTaskEntity>;
40
+
39
41
  export enum SysAsyncTaskStatus {
40
42
  PENDING = 'PENDING', // 等待中,还未进入排队
41
43
  RUNNING = 'RUNNING', // 运行中
@@ -58,14 +60,13 @@ export enum SysAsyncFileFormat {
58
60
  JPG = 'jpg',
59
61
  }
60
62
 
61
-
62
63
  export interface ISysAsyncTaskHandler {
63
64
  execute(asyncTaskContext: SysAsyncTaskContext): Promise<void>;
64
65
  }
65
66
 
66
67
  export interface SysAsyncTaskContext {
67
68
  task: SysAsyncTaskEntity;
68
- updateTaskStatus: ()=>any;
69
+ updateTaskStatus: (sysAsyncTaskPartial: SysAsyncTaskPartial) => any;
69
70
  }
70
71
 
71
72
  export interface SysAsyncTaskHandlerConfig {
@@ -0,0 +1,13 @@
1
+
2
+
3
+ const RedisKeys = {
4
+ ASYNC_TASK_LOCK : "FatAsyncTaskLock",
5
+ ASYNC_TASK_UPDATE_TIME : "FatAsyncTaskUpdateTime",
6
+ USER_SESSION_PREFIX : "FatUserSession_",
7
+ VISIT_STAT_LOCK_PREFIX : "FatVsLock_",
8
+ VISIT_STAT_DATE_PREFIX : "FatVsDate_",
9
+ }
10
+
11
+ export {
12
+ RedisKeys
13
+ }
@@ -85,5 +85,4 @@ export interface IVisitorExt extends IVisitor {
85
85
  accountType: string;
86
86
  }
87
87
 
88
-
89
- export const FILE_GET_TYPES = ['thumbnail','preview', 'download'];
88
+ export const FILE_GET_TYPES = ['thumbnail', 'preview', 'download'];
@@ -9,8 +9,8 @@ const lastExecuteTimeMap = {};
9
9
  const DEFAULT_SCHEDULE_INTERVAL = 2 * 60 * 1000;
10
10
 
11
11
 
12
-
13
12
  async function runScheduleTaskOnce(serviceName: string) {
13
+
14
14
  return await ANONYMOUS_CONTEXT.runServiceAtAnonymousContext(async (ctx: koa.IMidwayKoaContext) => {
15
15
  const serviceObject: IScheduleService = await ctx.requestContext.getAsync(serviceName);
16
16
  if (serviceObject && serviceObject.runBySchedule) {
@@ -21,12 +21,15 @@ async function runScheduleTaskOnce(serviceName: string) {
21
21
  });
22
22
  }
23
23
 
24
+
24
25
  class ScheduleQueue {
25
26
  private scheduleIntervalMap: Map<string, number> = new Map();
26
- public setScheduleTask(serviceName: string, intervalTime: number){
27
+
28
+ public setScheduleTask(serviceName: string, intervalTime: number) {
27
29
  this.scheduleIntervalMap.set(serviceName, intervalTime);
28
30
  }
29
- public removeScheduleTask(serviceName: string){
31
+
32
+ public removeScheduleTask(serviceName: string) {
30
33
  this.scheduleIntervalMap.delete(serviceName);
31
34
  }
32
35
 
@@ -41,20 +44,22 @@ class ScheduleQueue {
41
44
  }
42
45
 
43
46
 
47
+ private async runScheduleTaskOnceCheckTime(serviceName: string) {
48
+ // 还没有到可以执行时间
49
+ if (!this.isAlreadyTimeToExecute(serviceName)) {
50
+ return;
51
+ }
52
+ lastExecuteTimeMap[serviceName] = Date.now();
53
+ await runScheduleTaskOnce(serviceName);
54
+ }
55
+
44
56
  private async runScheduleServiceList() {
45
57
  const serviceListKeys = this.scheduleIntervalMap.keys();
46
58
  const serviceList = [...serviceListKeys];
47
59
  for (let i = 0; i < serviceList.length; i++) {
48
60
  const serviceName = serviceList[i];
49
-
50
- // 还没有到可以执行时间
51
- if (!this.isAlreadyTimeToExecute(serviceName)) {
52
- return;
53
- }
54
- lastExecuteTimeMap[serviceName] = Date.now();
55
-
56
61
  try {
57
- await runScheduleTaskOnce(serviceName);
62
+ await this.runScheduleTaskOnceCheckTime(serviceName);
58
63
  } catch (e) {
59
64
  ANONYMOUS_CONTEXT.getApp().getCoreLogger().error(`runSchedule error , serviceName = ${serviceName}`, e);
60
65
  }
@@ -1,8 +1,9 @@
1
1
  import {Inject, Provide} from '@midwayjs/core';
2
2
  import {Context} from '@midwayjs/koa';
3
- import {parseJsonObject} from '../libs/utils/functions';
4
- import {ISessionInfo, SESSION_ID_KEY, sessionCookieCfg} from '../models/userSession';
3
+ import {parseJsonObject} from '@/libs/utils/functions';
4
+ import {ISessionInfo, SESSION_ID_KEY, sessionCookieCfg} from '@/models/userSession';
5
5
  import {RedisCacheService} from "./base/RedisCacheService";
6
+ import {RedisKeys} from "@/models/RedisKeys";
6
7
 
7
8
 
8
9
  function pickUserAvatar(avatar: any): string {
@@ -35,8 +36,8 @@ function pickUserAvatar(avatar: any): string {
35
36
 
36
37
  const SESSION_KEEP_TIME_SECOND: number = 3600 * 24 * 30;
37
38
 
38
- const toCacheKey = (sessionId: string)=>{
39
- return `UserSession@@${sessionId}`;
39
+ const toCacheKey = (sessionId: string): string =>{
40
+ return `${RedisKeys.USER_SESSION_PREFIX}${sessionId}`;
40
41
  }
41
42
 
42
43
  @Provide()