midway-fatcms 0.0.1-beta.26 → 0.0.1-beta.28

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 (171) hide show
  1. package/dist/controller/home.controller.js +2 -1
  2. package/dist/controller/render/AppRenderController.js +2 -1
  3. package/dist/models/bizmodels.d.ts +1 -0
  4. package/dist/service/asyncTask/handler/ExportExcelAsyncTaskHandler.js +1 -1
  5. package/dist/service/crudstd/CrudStdService.d.ts +0 -6
  6. package/dist/service/crudstd/CrudStdService.js +13 -33
  7. package/package.json +1 -5
  8. package/src/config/config.default.ts +0 -207
  9. package/src/config/seed/aeskey.txt +0 -1
  10. package/src/config/utils.ts +0 -22
  11. package/src/configuration.ts +0 -109
  12. package/src/controller/base/BaseApiController.ts +0 -170
  13. package/src/controller/gateway/AnyApiGatewayController.ts +0 -33
  14. package/src/controller/gateway/AsyncTaskController.ts +0 -157
  15. package/src/controller/gateway/CrudMtdGatewayController.ts +0 -111
  16. package/src/controller/gateway/CrudStdGatewayController.ts +0 -101
  17. package/src/controller/gateway/DocGatewayController.ts +0 -173
  18. package/src/controller/gateway/FileController.ts +0 -109
  19. package/src/controller/gateway/ProxyApiGatewayController.ts +0 -47
  20. package/src/controller/gateway/PublicApiController.ts +0 -142
  21. package/src/controller/gateway/StaticController.ts +0 -298
  22. package/src/controller/helpers.controller.ts +0 -161
  23. package/src/controller/home.controller.ts +0 -64
  24. package/src/controller/manage/AnyApiMangeApi.ts +0 -66
  25. package/src/controller/manage/AppLogMangeApi.ts +0 -53
  26. package/src/controller/manage/AppMangeApi.ts +0 -53
  27. package/src/controller/manage/AppPageMangeApi.ts +0 -52
  28. package/src/controller/manage/AppSchemaHistoryApi.ts +0 -49
  29. package/src/controller/manage/CrudMethodsMangeApi.ts +0 -49
  30. package/src/controller/manage/CrudStandardDesignApi.ts +0 -346
  31. package/src/controller/manage/DataDictManageApi.ts +0 -78
  32. package/src/controller/manage/DeployManageApi.ts +0 -175
  33. package/src/controller/manage/DocLibManageApi.ts +0 -69
  34. package/src/controller/manage/DocManageApi.ts +0 -99
  35. package/src/controller/manage/FileManageApi.ts +0 -45
  36. package/src/controller/manage/LowCodeTplManageApi.ts +0 -52
  37. package/src/controller/manage/MenuManageApi.ts +0 -58
  38. package/src/controller/manage/ProxyApiMangeApi.ts +0 -52
  39. package/src/controller/manage/SuperAdminManageApi.ts +0 -139
  40. package/src/controller/manage/SysConfigMangeApi.ts +0 -95
  41. package/src/controller/manage/SystemInfoManageApi.ts +0 -53
  42. package/src/controller/manage/UserAccountManageApi.ts +0 -94
  43. package/src/controller/manage/WorkbenchMangeApi.ts +0 -72
  44. package/src/controller/myinfo/AuthController.ts +0 -108
  45. package/src/controller/myinfo/MyInfoController.ts +0 -32
  46. package/src/controller/render/AppRenderController.ts +0 -79
  47. package/src/controller/test.controller.ts +0 -37
  48. package/src/filter/default.filter.ts +0 -13
  49. package/src/filter/notfound.filter.ts +0 -10
  50. package/src/index.ts +0 -106
  51. package/src/interface.ts +0 -31
  52. package/src/libs/crud-pro/CrudPro.ts +0 -165
  53. package/src/libs/crud-pro/defaultConfigs.ts +0 -15
  54. package/src/libs/crud-pro/exceptions.ts +0 -124
  55. package/src/libs/crud-pro/interfaces.ts +0 -190
  56. package/src/libs/crud-pro/models/ExecuteContext.ts +0 -120
  57. package/src/libs/crud-pro/models/ExecuteContextFunc.ts +0 -96
  58. package/src/libs/crud-pro/models/FuncContext.ts +0 -21
  59. package/src/libs/crud-pro/models/RequestCfgModel.ts +0 -141
  60. package/src/libs/crud-pro/models/RequestModel.ts +0 -141
  61. package/src/libs/crud-pro/models/ResModel.ts +0 -19
  62. package/src/libs/crud-pro/models/ServiceHub.ts +0 -32
  63. package/src/libs/crud-pro/models/SqlCfgModel.ts +0 -52
  64. package/src/libs/crud-pro/models/SqlSegArg.ts +0 -13
  65. package/src/libs/crud-pro/models/Transaction.ts +0 -73
  66. package/src/libs/crud-pro/models/TransactionMySQL.ts +0 -79
  67. package/src/libs/crud-pro/models/TransactionPostgres.ts +0 -91
  68. package/src/libs/crud-pro/models/TransactionSqlServer.ts +0 -102
  69. package/src/libs/crud-pro/models/keys.ts +0 -159
  70. package/src/libs/crud-pro/services/CrudProCachedCfgService.ts +0 -83
  71. package/src/libs/crud-pro/services/CrudProExecuteFuncService.ts +0 -128
  72. package/src/libs/crud-pro/services/CrudProExecuteSqlService.ts +0 -262
  73. package/src/libs/crud-pro/services/CrudProFieldUpdateService.ts +0 -60
  74. package/src/libs/crud-pro/services/CrudProFieldValidateService.ts +0 -180
  75. package/src/libs/crud-pro/services/CrudProGenSqlCondition.ts +0 -354
  76. package/src/libs/crud-pro/services/CrudProGenSqlService.ts +0 -185
  77. package/src/libs/crud-pro/services/CrudProOriginToExecuteSql.ts +0 -393
  78. package/src/libs/crud-pro/services/CrudProServiceBase.ts +0 -94
  79. package/src/libs/crud-pro/services/CrudProTableMetaService.ts +0 -86
  80. package/src/libs/crud-pro/services/CurdProServiceHub.ts +0 -92
  81. package/src/libs/crud-pro/sql.txt +0 -120
  82. package/src/libs/crud-pro/utils/CompareUtils.ts +0 -23
  83. package/src/libs/crud-pro/utils/DatabaseName.ts +0 -60
  84. package/src/libs/crud-pro/utils/DateTimeUtils.ts +0 -20
  85. package/src/libs/crud-pro/utils/MemoryRefreshCache.ts +0 -64
  86. package/src/libs/crud-pro/utils/MessageParseUtils.ts +0 -33
  87. package/src/libs/crud-pro/utils/MixinUtils.ts +0 -285
  88. package/src/libs/crud-pro/utils/ModelUtils.ts +0 -55
  89. package/src/libs/crud-pro/utils/MultiKeyMap.ts +0 -72
  90. package/src/libs/crud-pro/utils/SqlFuncUtils.ts +0 -29
  91. package/src/libs/crud-pro/utils/TypeUtils.ts +0 -188
  92. package/src/libs/crud-pro/utils/ValidateUtils.ts +0 -165
  93. package/src/libs/crud-pro/utils/pool/MySQLUtils.ts +0 -20
  94. package/src/libs/crud-pro/utils/pool/PostgresUtils.ts +0 -22
  95. package/src/libs/crud-pro/utils/pool/SqlServerUtils.ts +0 -22
  96. package/src/libs/crud-pro/utils/sqlConvert/convertColumnName.ts +0 -26
  97. package/src/libs/crud-pro/utils/sqlConvert/convertMix.ts +0 -26
  98. package/src/libs/crud-pro/utils/sqlConvert/convertMsSql.ts +0 -11
  99. package/src/libs/crud-pro/utils/sqlConvert/convertPgSql.ts +0 -11
  100. package/src/libs/crud-pro/utils/sqlConvert/convertPgType.ts +0 -129
  101. package/src/libs/global-config/global-config.ts +0 -78
  102. package/src/libs/utils/common-dto.ts +0 -52
  103. package/src/libs/utils/crypto-utils.ts +0 -50
  104. package/src/libs/utils/errorToString.ts +0 -61
  105. package/src/libs/utils/fatcms-request.ts +0 -103
  106. package/src/libs/utils/functions.ts +0 -73
  107. package/src/libs/utils/ordernum-utils.ts +0 -14
  108. package/src/libs/utils/parseConfig.ts +0 -54
  109. package/src/libs/utils/parseCreateSql.ts +0 -91
  110. package/src/libs/utils/render-utils.ts +0 -184
  111. package/src/middleware/forbidden.middleware.ts +0 -52
  112. package/src/middleware/global.middleware.ts +0 -280
  113. package/src/middleware/permission.middleware.ts +0 -80
  114. package/src/middleware/tx.middleware.ts +0 -30
  115. package/src/models/AsyncTaskModel.ts +0 -82
  116. package/src/models/RedisKeys.ts +0 -13
  117. package/src/models/SystemEntities.ts +0 -115
  118. package/src/models/SystemPerm.ts +0 -105
  119. package/src/models/SystemTables.ts +0 -27
  120. package/src/models/bizmodels.ts +0 -120
  121. package/src/models/contextLogger.ts +0 -132
  122. package/src/models/devops.ts +0 -17
  123. package/src/models/userSession.ts +0 -216
  124. package/src/schedule/anonymousContext.ts +0 -73
  125. package/src/schedule/index.ts +0 -12
  126. package/src/schedule/runSchedule.ts +0 -82
  127. package/src/schedule/scheduleNames.ts +0 -21
  128. package/src/service/AuthService.ts +0 -272
  129. package/src/service/EnumInfoService.ts +0 -130
  130. package/src/service/FileCenterService.ts +0 -395
  131. package/src/service/SysConfigService.ts +0 -37
  132. package/src/service/UserAccountService.ts +0 -107
  133. package/src/service/UserSessionService.ts +0 -78
  134. package/src/service/VisitStatService.ts +0 -166
  135. package/src/service/WorkbenchService.ts +0 -165
  136. package/src/service/anyapi/AnyApiSandboxService.ts +0 -121
  137. package/src/service/anyapi/AnyApiService.ts +0 -186
  138. package/src/service/asyncTask/AsyncTaskRunnerService.ts +0 -266
  139. package/src/service/asyncTask/AsyncTaskService.ts +0 -21
  140. package/src/service/asyncTask/handler/ExcelInfoModel.ts +0 -11
  141. package/src/service/asyncTask/handler/ExportExcelAsyncTaskHandler.ts +0 -245
  142. package/src/service/asyncTask/handler/ExportExcelByInnerHttpHandler.ts +0 -147
  143. package/src/service/asyncTask/handler/ExportExcelByStdCrudHandler.ts +0 -138
  144. package/src/service/base/ApiBaseService.ts +0 -42
  145. package/src/service/base/ApiRateLimiter.ts +0 -59
  146. package/src/service/base/BaseService.ts +0 -100
  147. package/src/service/base/RedisCacheService.ts +0 -38
  148. package/src/service/crudstd/CrudStdActionService.ts +0 -27
  149. package/src/service/crudstd/CrudStdConstant.ts +0 -62
  150. package/src/service/crudstd/CrudStdRelationService.ts +0 -78
  151. package/src/service/crudstd/CrudStdService.ts +0 -283
  152. package/src/service/curd/CrudProQuick.ts +0 -131
  153. package/src/service/curd/CurdMixByAccountService.ts +0 -90
  154. package/src/service/curd/CurdMixByDictService.ts +0 -114
  155. package/src/service/curd/CurdMixByLinkToCustomService.ts +0 -219
  156. package/src/service/curd/CurdMixBySysConfigService.ts +0 -78
  157. package/src/service/curd/CurdMixByWorkbenchService.ts +0 -71
  158. package/src/service/curd/CurdMixService.ts +0 -97
  159. package/src/service/curd/CurdMixUtils.ts +0 -311
  160. package/src/service/curd/CurdProService.ts +0 -229
  161. package/src/service/curd/fixCfgModel.ts +0 -139
  162. package/src/service/proxyapi/ProxyApiLoadService.ts +0 -174
  163. package/src/service/proxyapi/ProxyApiService.ts +0 -262
  164. package/src/service/proxyapi/ProxyApiUtils.ts +0 -32
  165. package/src/service/proxyapi/RouteHandler.ts +0 -8
  166. package/src/service/proxyapi/RouteTrie.ts +0 -74
  167. package/src/service/proxyapi/WeightedRandom.ts +0 -37
  168. package/src/service/proxyapi/WeightedRoundRobin.ts +0 -44
  169. package/src/views/404_app.html +0 -31
  170. package/src/views/404_workbench.html +0 -34
  171. package/src/views/static/favicon.ico +0 -0
@@ -1,95 +0,0 @@
1
- import { Controller, Inject, Post } from '@midwayjs/core';
2
- import { Context } from '@midwayjs/koa';
3
- import { KeysOfSimpleSQL, KeysOfValidators } from '../../libs/crud-pro/models/keys';
4
- import { BaseApiController } from '../base/BaseApiController';
5
- import { checkPermission } from '../../middleware/permission.middleware';
6
- import { SystemFuncCode } from '../../models/SystemPerm';
7
- import { CTX_WORKBENCH_CODE } from '../../models/bizmodels';
8
- import { SystemTables } from '../../models/SystemTables';
9
- import { CommonResult } from '../../libs/utils/common-dto';
10
- import { GLOBAL_STATIC_CONFIG } from '@/libs/global-config/global-config';
11
-
12
- @Controller('/ns/api/manage/sysconfig', { middleware: [checkPermission(SystemFuncCode.SysConfigMangeRead)] })
13
- export class SysConfigMangeApi extends BaseApiController {
14
- @Inject()
15
- ctx: Context;
16
-
17
- @Post('/getSysConfigList')
18
- async getSysConfigList() {
19
- return this.executeSysSimpleSQL('sys_configs', KeysOfSimpleSQL.SIMPLE_QUERY_PAGE, {
20
- updateCfg: {
21
- 'condition.workbench_code': { contextAsString: CTX_WORKBENCH_CODE },
22
- },
23
- });
24
- }
25
-
26
- @Post('/getSysConfigOne')
27
- async getSysConfigOne() {
28
- return this.executeSysSimpleSQL('sys_configs', KeysOfSimpleSQL.SIMPLE_QUERY_ONE, {
29
- updateCfg: {
30
- 'condition.workbench_code': { contextAsString: CTX_WORKBENCH_CODE },
31
- },
32
- });
33
- }
34
-
35
- @Post('/createSysConfig', { middleware: [checkPermission(SystemFuncCode.SysConfigMangeWrite)] })
36
- async createSysConfig() {
37
- return this.executeSysSimpleSQL('sys_configs', KeysOfSimpleSQL.SIMPLE_INSERT, {
38
- validateCfg: {
39
- 'data.workbench_code': [KeysOfValidators.REQUIRED, KeysOfValidators.STRING, 'length:1,64'],
40
- 'data.config_code': [KeysOfValidators.REQUIRED, KeysOfValidators.STRING],
41
- 'data.config_name': [KeysOfValidators.REQUIRED, KeysOfValidators.STRING],
42
- 'data.config_type': [KeysOfValidators.REQUIRED, KeysOfValidators.STRING],
43
- },
44
- updateCfg: {
45
- 'data.workbench_code': { contextAsString: CTX_WORKBENCH_CODE },
46
- },
47
- });
48
- }
49
-
50
- @Post('/updateSysConfig', { middleware: [checkPermission(SystemFuncCode.SysConfigMangeWrite)] })
51
- async updateSysConfig() {
52
- const { SystemDbName, SystemDbType } = GLOBAL_STATIC_CONFIG.getConfig();
53
-
54
- const body = this.ctx.request.body as any;
55
- const id = body.condition.id;
56
- if (!id) {
57
- return CommonResult.errorRes('id不能为空');
58
- }
59
-
60
- const sysConfig = await this.curdMixService.getBbUtil(SystemDbName, SystemDbType).getOne({ condition: body.condition }, SystemTables.sys_configs);
61
- if (!sysConfig) {
62
- return CommonResult.errorRes('配置项不存在');
63
- }
64
-
65
- const { edit_auth_type, edit_auth_config } = sysConfig;
66
- if (edit_auth_type) {
67
- const isOK = this.ctx.userSession.isAuthPass(edit_auth_type, edit_auth_config);
68
- if (!isOK) {
69
- return CommonResult.errorRes('编辑权限校验不通过:' + JSON.stringify({ edit_auth_type, edit_auth_config }));
70
- }
71
- }
72
-
73
- return this.executeSysSimpleSQL('sys_configs', KeysOfSimpleSQL.SIMPLE_UPDATE, {
74
- validateCfg: {
75
- 'data.workbench_code': [KeysOfValidators.REQUIRED, KeysOfValidators.STRING, 'length:1,64'],
76
- 'condition.id': [KeysOfValidators.REQUIRED, KeysOfValidators.NUMERIC],
77
- },
78
- updateCfg: {
79
- 'condition.workbench_code': { contextAsString: CTX_WORKBENCH_CODE },
80
- },
81
- });
82
- }
83
-
84
- @Post('/deleteSysConfig', { middleware: [checkPermission(SystemFuncCode.SysConfigMangeWrite)] })
85
- async deleteSysConfig() {
86
- return this.executeSysSimpleSQL('sys_configs', KeysOfSimpleSQL.SIMPLE_DELETE, {
87
- validateCfg: {
88
- 'condition.id': [KeysOfValidators.REQUIRED, KeysOfValidators.NUMERIC],
89
- },
90
- updateCfg: {
91
- 'condition.workbench_code': { contextAsString: CTX_WORKBENCH_CODE },
92
- },
93
- });
94
- }
95
- }
@@ -1,53 +0,0 @@
1
- import { Controller, Inject, Get } from '@midwayjs/core';
2
- import { InfoService } from '@midwayjs/info';
3
- import { Context } from '@midwayjs/koa';
4
- import { BaseApiController } from '../base/BaseApiController';
5
- import { checkPermission } from '../../middleware/permission.middleware';
6
- import { SystemFuncCode } from '../../models/SystemPerm';
7
- import { CommonResult } from '../../libs/utils/common-dto';
8
-
9
- @Controller('/ns/api/manage/systemInfo', { middleware: [checkPermission(SystemFuncCode.SystemInfoManageApiRead)] })
10
- export class SystemInfoManageApi extends BaseApiController {
11
- @Inject()
12
- protected ctx: Context;
13
-
14
- @Inject()
15
- protected infoService: InfoService;
16
-
17
- /**
18
- * 预设系统内置功能点数据
19
- */
20
- @Get('/getSystemInfo')
21
- async getSystemInfo() {
22
- // 应用信息,应用名等
23
- const projectInfo = this.infoService.projectInfo();
24
- // 系统信息
25
- const systemInfo = this.infoService.systemInfo();
26
- // 堆内存,cpu 等
27
- const resourceOccupationInfo = this.infoService.resourceOccupationInfo();
28
- // midway 框架的信息
29
- const softwareInfo = this.infoService.softwareInfo();
30
- // 当前使用的环境配置
31
- // const midwayConfig = this.infoService.midwayConfig();
32
- // 依赖注入容器中的服务
33
- // this.infoService.midwayService();
34
- // 系统时间,时区,启动时常
35
- const timeInfo = this.infoService.timeInfo();
36
- // 环境变量
37
- const envInfo = this.infoService.envInfo();
38
- // 依赖信息
39
- // this.infoService.dependenciesInfo();
40
- // 网络信息
41
- const networkInfo = this.infoService.networkInfo();
42
-
43
- return CommonResult.successRes({
44
- projectInfo,
45
- systemInfo,
46
- resourceOccupationInfo,
47
- softwareInfo,
48
- timeInfo,
49
- envInfo,
50
- networkInfo,
51
- });
52
- }
53
- }
@@ -1,94 +0,0 @@
1
- import { Controller, Inject, Post } from '@midwayjs/core';
2
- import { Context } from '@midwayjs/koa';
3
- import { KeysOfSimpleSQL, KeysOfValidators } from '../../libs/crud-pro/models/keys';
4
- import { BaseApiController } from '../base/BaseApiController';
5
- import { createUniqueId } from '../../libs/utils/functions';
6
- import { checkPermission } from '../../middleware/permission.middleware';
7
- import { SystemFuncCode } from '../../models/SystemPerm';
8
- import { CommonException, Exceptions } from '../../libs/crud-pro/exceptions';
9
- import { SystemTables } from '../../models/SystemTables';
10
- import { GLOBAL_STATIC_CONFIG } from '@/libs/global-config/global-config';
11
-
12
- const accountNameBlacklist = new Set(['sa', 'root', 'admin', 'superadmin', 'administrator', 'sys', 'sysop', 'schedule_user']);
13
- function checkAccountCreateBlacklist(value: string) {
14
- if (!value) {
15
- return;
16
- }
17
- if (accountNameBlacklist.has(value)) {
18
- throw new CommonException(Exceptions.VALIDATE_EXCEPTION, '用户名或昵称不能使用具有管理员歧义的词语');
19
- }
20
- }
21
-
22
- const LOGIN_NAME_VALIDATE = [KeysOfValidators.STRING, KeysOfValidators.NAME, 'length:6,50', checkAccountCreateBlacklist];
23
-
24
- @Controller('/ns/api/manage/userAccount', { middleware: [checkPermission(SystemFuncCode.UserAccountMangeRead)] })
25
- export class UserAccountManageApi extends BaseApiController {
26
- @Inject()
27
- protected ctx: Context;
28
-
29
- @Post('/getUserAccountList')
30
- async getUserAccountList() {
31
- return this.executeSysSimpleSQL(SystemTables.sys_user_account, KeysOfSimpleSQL.SIMPLE_QUERY_PAGE, {
32
- columns: '!pwd_md5,!pwd_salt',
33
- });
34
- }
35
-
36
- @Post('/getUserAccountOne')
37
- async getUserAccountOne() {
38
- return this.executeSysSimpleSQL(SystemTables.sys_user_account, KeysOfSimpleSQL.SIMPLE_QUERY_ONE, {
39
- columns: '!pwd_md5,!pwd_salt',
40
- });
41
- }
42
-
43
- @Post('/updateUserAccount', { middleware: [checkPermission(SystemFuncCode.UserAccountMangeWrite)] })
44
- async updateUserAccount() {
45
- return this.executeSysSimpleSQL(SystemTables.sys_user_account, KeysOfSimpleSQL.SIMPLE_UPDATE, {
46
- validateCfg: {
47
- 'condition.id': [KeysOfValidators.REQUIRED, KeysOfValidators.NUMERIC],
48
- 'data.login_name': LOGIN_NAME_VALIDATE,
49
- 'data.nick_name': [KeysOfValidators.STRING, 'length:3,20', checkAccountCreateBlacklist],
50
- },
51
- allowCfg: {
52
- data: ['login_name', 'nick_name', 'avatar', 'status'],
53
- },
54
- });
55
- }
56
-
57
- @Post('/createUserAccount', { middleware: [checkPermission(SystemFuncCode.UserAccountMangeWrite)] })
58
- async createUserAccount() {
59
- const body = this.ctx.request.body as any;
60
- body.data.account_id = createUniqueId();
61
-
62
- const { generateUserAccountId } = GLOBAL_STATIC_CONFIG.getConfig();
63
- if (typeof generateUserAccountId === 'function') {
64
- body.data.account_id = await generateUserAccountId(body.data);
65
- }
66
-
67
- return this.executeSysSimpleSQL(SystemTables.sys_user_account, KeysOfSimpleSQL.SIMPLE_INSERT, {
68
- validateCfg: {
69
- 'data.login_name': LOGIN_NAME_VALIDATE,
70
- 'data.nick_name': [KeysOfValidators.REQUIRED, KeysOfValidators.STRING, 'length:3,20', checkAccountCreateBlacklist],
71
- 'data.avatar': [KeysOfValidators.REQUIRED, KeysOfValidators.STRING],
72
- },
73
- });
74
- }
75
-
76
- @Post('/deleteUserAccount', { middleware: [checkPermission(SystemFuncCode.UserAccountMangeWrite)] })
77
- async deleteUserAccount() {
78
- return this.executeSysSimpleSQL(SystemTables.sys_user_account, KeysOfSimpleSQL.SIMPLE_DELETE, {
79
- validateCfg: {
80
- 'condition.id': [KeysOfValidators.REQUIRED, KeysOfValidators.NUMERIC],
81
- },
82
- });
83
- }
84
-
85
- /**
86
- * 重置密码
87
- */
88
- @Post('/chgUserPassword', { middleware: [checkPermission(SystemFuncCode.UserAccountMangeWrite)] })
89
- async chgUserPassword() {
90
- const body = this.ctx.request.body as any;
91
- const { loginName, unsaltedPwd } = body;
92
- return this.userAccountService.chgUserPassword(loginName, unsaltedPwd);
93
- }
94
- }
@@ -1,72 +0,0 @@
1
- import { Controller, Inject, Post } from '@midwayjs/core';
2
- import { Context } from '@midwayjs/koa';
3
- import { KeysOfSimpleSQL, KeysOfValidators } from '@/libs/crud-pro/models/keys';
4
- import { BaseApiController } from '../base/BaseApiController';
5
- import { checkPermission } from '@/middleware/permission.middleware';
6
- import { SystemFuncCode } from '@/models/SystemPerm';
7
- import { SystemTables } from '@/models/SystemTables';
8
- import { WorkbenchService } from '@/service/WorkbenchService';
9
-
10
- @Controller('/ns/api/manage/workbench', { middleware: [checkPermission(SystemFuncCode.WorkbenchMangeRead)] })
11
- export class WorkbenchMangeApi extends BaseApiController {
12
- @Inject()
13
- protected ctx: Context;
14
-
15
- @Inject()
16
- private workbenchService: WorkbenchService;
17
-
18
- @Post('/getWorkbenchList')
19
- async getWorkbenchList() {
20
- return this.executeSysSimpleSQL(SystemTables.sys_workbench, KeysOfSimpleSQL.SIMPLE_QUERY_PAGE);
21
- }
22
-
23
- @Post('/getWorkbenchOne')
24
- async getWorkbenchOne() {
25
- return this.executeSysSimpleSQL(SystemTables.sys_workbench, KeysOfSimpleSQL.SIMPLE_QUERY_ONE);
26
- }
27
-
28
- @Post('/createWorkbench', { middleware: [checkPermission(SystemFuncCode.WorkbenchMangeWrite)] })
29
- async createWorkbench() {
30
- // 清除运行时缓存
31
- this.workbenchService.clearCache();
32
-
33
- const body = this.ctx.request.body as any;
34
- const dataObj: any = body.data || {};
35
-
36
- dataObj.html_content = dataObj.html_content || '<html>hello</html>';
37
-
38
- return this.executeSysSimpleSQL(SystemTables.sys_workbench, KeysOfSimpleSQL.SIMPLE_INSERT, {
39
- validateCfg: {
40
- 'data.workbench_code': [KeysOfValidators.REQUIRED, KeysOfValidators.STRING],
41
- 'data.workbench_name': [KeysOfValidators.REQUIRED, KeysOfValidators.STRING],
42
- 'data.workbench_domain': [KeysOfValidators.REQUIRED, KeysOfValidators.STRING],
43
- },
44
- });
45
- }
46
-
47
- @Post('/updateWorkbench', { middleware: [checkPermission(SystemFuncCode.WorkbenchMangeWrite)] })
48
- async updateWorkbench() {
49
- // 清除运行时缓存
50
- this.workbenchService.clearCache();
51
-
52
- return this.executeSysSimpleSQL(SystemTables.sys_workbench, KeysOfSimpleSQL.SIMPLE_UPDATE, {
53
- validateCfg: {
54
- 'condition.id': [KeysOfValidators.REQUIRED, KeysOfValidators.NUMERIC],
55
- 'condition.workbench_code': [KeysOfValidators.REQUIRED, KeysOfValidators.STRING],
56
- },
57
- });
58
- }
59
-
60
- @Post('/deleteWorkbench', { middleware: [checkPermission(SystemFuncCode.WorkbenchMangeWrite)] })
61
- async deleteWorkbench() {
62
- // 清除运行时缓存
63
- this.workbenchService.clearCache();
64
-
65
- return this.executeSysSimpleSQL(SystemTables.sys_workbench, KeysOfSimpleSQL.SIMPLE_DELETE, {
66
- validateCfg: {
67
- 'condition.id': [KeysOfValidators.REQUIRED, KeysOfValidators.NUMERIC],
68
- 'condition.workbench_code': [KeysOfValidators.REQUIRED, KeysOfValidators.STRING],
69
- },
70
- });
71
- }
72
- }
@@ -1,108 +0,0 @@
1
- import { Controller, Inject, Post } from '@midwayjs/core';
2
- import { Context } from '@midwayjs/koa';
3
- import { BaseApiController } from '../base/BaseApiController';
4
- import { AuthService } from '../../service/AuthService';
5
- import { ISessionInfo, SESSION_ID_KEY, sessionCookieCfg } from '../../models/userSession';
6
- import { CommonResult } from '../../libs/utils/common-dto';
7
- import { checkLogin } from '../../middleware/permission.middleware';
8
- import { assertCsrfToken } from '../../libs/utils/fatcms-request';
9
- import { WorkbenchService } from '../../service/WorkbenchService';
10
- import { CommonException } from '../../libs/crud-pro/exceptions';
11
-
12
- /**
13
- * 支持使用明文密码和Hash后密码登录。
14
- * 1. 明文密码登录,所需字段:loginName, plainPwd,
15
- * 2. Hash后密码登录,所需字段:loginName, unsaltedPwd
16
- */
17
- @Controller('/ns/api/auth')
18
- export class AuthController extends BaseApiController {
19
- @Inject()
20
- protected ctx: Context;
21
-
22
- @Inject()
23
- private authService: AuthService;
24
-
25
- @Inject()
26
- private workbenchService: WorkbenchService;
27
-
28
- /**
29
- * 登录
30
- */
31
- @Post('/login')
32
- async login(): Promise<CommonResult> {
33
- await assertCsrfToken(this.ctx);
34
-
35
- // 先删除之前的SessionId
36
- const sessionId = this.ctx.cookies.get(SESSION_ID_KEY, sessionCookieCfg);
37
- await this.authService.removeUserSession(sessionId);
38
-
39
- // eslint-disable-next-line prefer-const
40
- let { loginName, unsaltedPwd, plainPwd } = this.ctx.request.body as any;
41
- if (!unsaltedPwd && plainPwd) {
42
- unsaltedPwd = this.authService.toUnsaltedPwd(plainPwd, loginName); // 使用明文密码登录时,转换成unsaltedPwd
43
- }
44
-
45
- const checkRes = await this.authService.checkLoginPassword(loginName, unsaltedPwd);
46
- if (!checkRes.success) {
47
- return checkRes;
48
- }
49
-
50
- const workbench = await this.workbenchService.getCurrentHostWorkbenchInfo();
51
- if (!workbench) {
52
- throw new CommonException('WORKBENCH_IS_NOT_FOUND', '站点未找到');
53
- }
54
-
55
- const userSessionInfo = await this.authService.createUserSession(loginName, workbench.workbench_code);
56
-
57
- this.ctx.cookies.set(SESSION_ID_KEY, userSessionInfo.sessionId, sessionCookieCfg);
58
-
59
- return CommonResult.successMsg('登录成功', userSessionInfo);
60
- }
61
-
62
- /**
63
- * 退出
64
- */
65
- @Post('/logout')
66
- async logout(): Promise<CommonResult> {
67
- const sessionId = this.ctx.cookies.get(SESSION_ID_KEY, sessionCookieCfg);
68
- await this.authService.removeUserSession(sessionId);
69
- this.ctx.cookies.set(SESSION_ID_KEY, '', sessionCookieCfg);
70
- return CommonResult.successMsg('退出成功');
71
- }
72
-
73
- /**
74
- * 避免Session过期,前端需要定时调用此接口刷新
75
- */
76
- @Post('/refreshSession', { middleware: [checkLogin()] })
77
- async refreshSession(): Promise<CommonResult> {
78
- const sessionInfo: ISessionInfo = this.ctx.userSession.getSessionInfo();
79
- const newSessionInfo: ISessionInfo = await this.authService.refreshSession(sessionInfo);
80
- this.ctx.cookies.set(SESSION_ID_KEY, newSessionInfo.sessionId, sessionCookieCfg);
81
- return CommonResult.successRes(newSessionInfo);
82
- }
83
-
84
- /**
85
- * 修改我自己的密码
86
- */
87
- @Post('/changeMyPassword', { middleware: [checkLogin()] })
88
- async changeMyPassword(): Promise<CommonResult> {
89
- const { unsaltedPwd } = this.ctx.request.body as any;
90
- const loginName = this.ctx.userSession.getSessionInfo().loginName;
91
-
92
- if (loginName === 'devopsviewer') {
93
- return CommonResult.errorRes('开放体验账号不支持修改密码');
94
- }
95
-
96
- return this.userAccountService.chgUserPassword(loginName, unsaltedPwd);
97
- }
98
-
99
- /**
100
- * 校验权限接口,给前端用的。用于界面按钮级权限控制
101
- */
102
- @Post('/batchCheckPermission', { middleware: [checkLogin()] })
103
- async batchCheckPermission(): Promise<CommonResult> {
104
- const { permissionCodeList, roleCodeList } = (this.ctx.request.body || {}) as any;
105
- const res = this.ctx.userSession.batchCheckPermission({ permissionCodeList, roleCodeList });
106
- return CommonResult.successRes(res);
107
- }
108
- }
@@ -1,32 +0,0 @@
1
- import * as _ from 'lodash';
2
- import { Controller, Inject, Post } from '@midwayjs/core';
3
- import { Context } from '@midwayjs/koa';
4
- import { BaseApiController } from '../base/BaseApiController';
5
- import { CommonResult } from '../../libs/utils/common-dto';
6
- import { SystemTables } from '../../models/SystemTables';
7
- import { KeysOfSimpleSQL } from '../../libs/crud-pro/models/keys';
8
- import { checkLogin } from '../../middleware/permission.middleware';
9
-
10
- /**
11
- * 用户个人数据查询
12
- */
13
- @Controller('/ns/api/myinfo', { middleware: [checkLogin()] })
14
- export class MyInfoController extends BaseApiController {
15
- @Inject()
16
- protected ctx: Context;
17
-
18
- /**
19
- * 我的角色列表:getMyRoleList
20
- */
21
- @Post('/getMyRoleList')
22
- async getMyRoleList() {
23
- // eslint-disable-next-line prefer-const
24
- const body = this.ctx.request.body as any;
25
- const roleCodes = this.ctx.userSession.getSessionInfo().roleCodes;
26
- if (!roleCodes || !roleCodes.length) {
27
- return CommonResult.successRes([]);
28
- }
29
- _.set(body, 'condition.role_code', { $in: roleCodes });
30
- return this.executeSysSimpleSQL(SystemTables.sys_perm_role, KeysOfSimpleSQL.SIMPLE_QUERY_PAGE);
31
- }
32
- }
@@ -1,79 +0,0 @@
1
- import { Inject, Controller, Get, Param } from '@midwayjs/core';
2
- import { Context } from '@midwayjs/koa';
3
- import { BaseApiController } from '../base/BaseApiController';
4
- import { KeysOfSimpleSQL } from '../../libs/crud-pro/models/keys';
5
- import { SystemTables } from '../../models/SystemTables';
6
- import { WorkbenchService } from '../../service/WorkbenchService';
7
- import { createRenderUtils } from '../../libs/utils/render-utils';
8
- import { privateAES } from '../../libs/utils/crypto-utils';
9
- import { GLOBAL_STATIC_CONFIG } from '@/libs/global-config/global-config';
10
-
11
- /**
12
- * 渲染独立外部应用
13
- */
14
- @Controller('/ns/app')
15
- export class AppRenderController extends BaseApiController {
16
- @Inject()
17
- protected ctx: Context;
18
-
19
- @Inject()
20
- private workbenchService: WorkbenchService;
21
-
22
- @Get('/:appPath+')
23
- async home(@Param('appPath') appPath: string): Promise<string> {
24
- const { SystemDbName, SystemDbType } = GLOBAL_STATIC_CONFIG.getConfig();
25
-
26
- const appPathArr = appPath.split('/');
27
- const appCode = appPathArr[0];
28
-
29
- const res = await this.curdMixService.executeCrudByCfg(
30
- { condition: { app_code: appCode } },
31
- {
32
- sqlTable: SystemTables.sys_app,
33
- sqlSimpleName: KeysOfSimpleSQL.SIMPLE_QUERY_ONE,
34
- sqlDatabase: SystemDbName,
35
- sqlDbType: SystemDbType,
36
- }
37
- );
38
-
39
- const { row: appInfo } = res.getResModel();
40
- if (!appInfo) {
41
- this.ctx.status = 404;
42
- return this.ctx.render('404_app', { appCode, errorMsg: ' 应用不存在' });
43
- }
44
-
45
- if (appInfo.status !== 1) {
46
- this.ctx.status = 404;
47
- return this.ctx.render('404_app', { appCode, errorMsg: ' 应用已下线' });
48
- }
49
-
50
- const isSupportWorkbench = await this.isSupportCurrentWorkbench(appInfo);
51
- if (!isSupportWorkbench) {
52
- this.ctx.status = 404;
53
- return this.ctx.render('404_app', { appCode, errorMsg: ' 应用没有绑定此站点' });
54
- }
55
-
56
- const workbenchInfo = await this.workbenchService.getCurrentHostWorkbenchInfo();
57
-
58
- const html_content = appInfo.html_content || '<b style="color: red">错误:未配置HTML模版,请检查!!</b>';
59
- const userInfo = this.getUserSessionInfo();
60
- const fatcmscsrftoken = await privateAES.time_encrypt_utf8_base64('' + Date.now());
61
-
62
- const utils = createRenderUtils({
63
- ctx: this.ctx,
64
- appInfo,
65
- workbenchInfo,
66
- userInfo,
67
- package_assets: appInfo.package_assets,
68
- fatcmscsrftoken,
69
- });
70
- return this.ctx.renderString(html_content, { appInfo, workbenchInfo, userInfo, utils }, { viewEngine: 'ejs' });
71
- }
72
-
73
- private async isSupportCurrentWorkbench(appInfo: any): Promise<boolean> {
74
- if (this.isLocalEnv()) {
75
- return true;
76
- }
77
- return this.workbenchService.isSupportCurrentWorkbench(appInfo.workbench_code_array);
78
- }
79
- }
@@ -1,37 +0,0 @@
1
- import { Controller, Get, Inject } from '@midwayjs/core';
2
- import { Context } from '@midwayjs/koa';
3
- import { CurdMixService } from '../service/curd/CurdMixService';
4
- import { BaseApiController } from './base/BaseApiController';
5
- import { IRequestCfgModel } from '../libs/crud-pro/interfaces';
6
- import { KeysOfSimpleSQL, SqlDbType } from '../libs/crud-pro/models/keys';
7
-
8
- // http://127.0.0.1:7002/ns/api/test/testPgQuery
9
-
10
- @Controller('/ns/api/test')
11
- export class TestApiController extends BaseApiController {
12
- @Inject()
13
- protected ctx: Context;
14
-
15
- @Inject()
16
- protected curdMixService: CurdMixService;
17
-
18
- @Get('/testPgQuery')
19
- async testPgQuery() {
20
- const cfgModel: IRequestCfgModel = {
21
- sqlTable: 'test_table1',
22
- sqlSimpleName: KeysOfSimpleSQL.SIMPLE_QUERY,
23
- sqlDatabase: 'postgres_test1',
24
- sqlDbType: SqlDbType.postgres,
25
- updateCfg: {},
26
- };
27
-
28
- return this.curdMixService.executeCrudByCfg(
29
- {
30
- condition: {
31
- int4: '222',
32
- },
33
- },
34
- cfgModel
35
- );
36
- }
37
- }
@@ -1,13 +0,0 @@
1
- import { Catch } from '@midwayjs/core';
2
- import { Context } from '@midwayjs/koa';
3
-
4
- @Catch()
5
- export class DefaultErrorFilter {
6
- async catch(err: Error, ctx: Context) {
7
- // 所有的未分类错误会到这里
8
- return {
9
- success: false,
10
- message: err.message,
11
- };
12
- }
13
- }
@@ -1,10 +0,0 @@
1
- import { Catch, httpError, MidwayHttpError } from '@midwayjs/core';
2
- import { Context } from '@midwayjs/koa';
3
-
4
- @Catch(httpError.NotFoundError)
5
- export class NotFoundFilter {
6
- async catch(err: MidwayHttpError, ctx: Context) {
7
- // 404 错误会到这里
8
- ctx.redirect('/404.html');
9
- }
10
- }