midway-fatcms 0.0.1-beta.4 → 0.0.1-beta.41
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.
- package/.eslintrc.json +14 -0
- package/.prettierrc.js +4 -0
- package/README.md +7 -0
- package/dist/config/config.default.js +58 -15
- package/dist/config/seed/aeskey.txt +1 -1
- package/dist/configuration.d.ts +1 -0
- package/dist/configuration.js +33 -9
- package/dist/controller/base/BaseApiController.d.ts +7 -1
- package/dist/controller/base/BaseApiController.js +32 -6
- package/dist/controller/gateway/AsyncTaskController.d.ts +20 -0
- package/dist/controller/gateway/AsyncTaskController.js +181 -0
- package/dist/controller/gateway/CrudMtdGatewayController.d.ts +3 -3
- package/dist/controller/gateway/CrudMtdGatewayController.js +9 -6
- package/dist/controller/gateway/DocGatewayController.js +14 -9
- package/dist/controller/gateway/FileController.d.ts +3 -2
- package/dist/controller/gateway/PublicApiController.js +4 -6
- package/dist/controller/gateway/StaticController.d.ts +0 -1
- package/dist/controller/gateway/StaticController.js +40 -39
- package/dist/controller/helpers.controller.d.ts +1 -1
- package/dist/controller/home.controller.js +4 -3
- package/dist/controller/manage/AnyApiMangeApi.js +2 -2
- package/dist/controller/manage/AppLogMangeApi.js +2 -2
- package/dist/controller/manage/AppMangeApi.js +2 -2
- package/dist/controller/manage/AppPageMangeApi.js +2 -2
- package/dist/controller/manage/AppSchemaHistoryApi.js +2 -2
- package/dist/controller/manage/CrudMethodsMangeApi.js +2 -2
- package/dist/controller/manage/CrudStandardDesignApi.d.ts +1 -1
- package/dist/controller/manage/CrudStandardDesignApi.js +86 -83
- package/dist/controller/manage/DataDictManageApi.d.ts +1 -1
- package/dist/controller/manage/DataDictManageApi.js +1 -1
- package/dist/controller/manage/DeployManageApi.d.ts +1 -1
- package/dist/controller/manage/DeployManageApi.js +38 -34
- package/dist/controller/manage/DocLibManageApi.js +2 -2
- package/dist/controller/manage/DocManageApi.js +2 -2
- package/dist/controller/manage/FileManageApi.js +1 -1
- package/dist/controller/manage/LowCodeTplManageApi.js +2 -2
- package/dist/controller/manage/MenuManageApi.js +2 -2
- package/dist/controller/manage/ProxyApiMangeApi.js +2 -2
- package/dist/controller/manage/SuperAdminManageApi.d.ts +2 -2
- package/dist/controller/manage/SuperAdminManageApi.js +12 -8
- package/dist/controller/manage/SysConfigMangeApi.d.ts +1 -1
- package/dist/controller/manage/SysConfigMangeApi.js +8 -6
- package/dist/controller/manage/SystemInfoManageApi.d.ts +1 -1
- package/dist/controller/manage/SystemInfoManageApi.js +7 -1
- package/dist/controller/manage/UserAccountManageApi.d.ts +2 -2
- package/dist/controller/manage/UserAccountManageApi.js +7 -2
- package/dist/controller/manage/WorkbenchMangeApi.js +3 -3
- package/dist/controller/myinfo/AuthController.d.ts +0 -4
- package/dist/controller/myinfo/AuthController.js +1 -54
- package/dist/controller/render/AppRenderController.js +12 -5
- package/dist/controller/test.controller.d.ts +1 -1
- package/dist/controller/test.controller.js +5 -5
- package/dist/index.d.ts +35 -4
- package/dist/index.js +35 -4
- package/dist/libs/crud-pro/CrudPro.d.ts +1 -0
- package/dist/libs/crud-pro/CrudPro.js +5 -0
- package/dist/libs/crud-pro/defaultConfigs.js +2 -0
- package/dist/libs/crud-pro/interfaces.d.ts +7 -1
- package/dist/libs/crud-pro/models/ExecuteContext.d.ts +12 -5
- package/dist/libs/crud-pro/models/ExecuteContextFunc.d.ts +8 -1
- package/dist/libs/crud-pro/models/ExecuteContextFunc.js +8 -0
- package/dist/libs/crud-pro/models/RequestCfgModel.d.ts +1 -1
- package/dist/libs/crud-pro/models/ResModel.d.ts +16 -0
- package/dist/libs/crud-pro/models/ResModel.js +2 -0
- package/dist/libs/crud-pro/models/SqlCfgModel.d.ts +1 -1
- package/dist/libs/crud-pro/models/Transaction.d.ts +1 -0
- package/dist/libs/crud-pro/models/Transaction.js +7 -0
- package/dist/libs/crud-pro/models/TransactionSqlServer.js +1 -1
- package/dist/libs/crud-pro/services/CrudProCachedCfgService.d.ts +1 -0
- package/dist/libs/crud-pro/services/CrudProCachedCfgService.js +27 -15
- package/dist/libs/crud-pro/services/CrudProExecuteSqlService.js +17 -19
- package/dist/libs/crud-pro/services/CrudProGenSqlCondition.d.ts +1 -1
- package/dist/libs/crud-pro/services/CrudProGenSqlCondition.js +10 -12
- package/dist/libs/crud-pro/services/CrudProGenSqlService.js +14 -23
- package/dist/libs/crud-pro/services/CrudProOriginToExecuteSql.js +7 -6
- package/dist/libs/crud-pro/services/CrudProServiceBase.d.ts +2 -6
- package/dist/libs/crud-pro/services/CrudProServiceBase.js +15 -3
- package/dist/libs/crud-pro/services/CrudProTableMetaService.d.ts +1 -0
- package/dist/libs/crud-pro/services/CrudProTableMetaService.js +32 -7
- package/dist/libs/crud-pro/sql.txt +120 -120
- package/dist/libs/crud-pro/utils/DatabaseName.js +24 -3
- package/dist/libs/crud-pro/utils/MixinUtils.js +1 -1
- package/dist/libs/crud-pro/utils/ValidateUtils.js +1 -1
- package/dist/libs/crud-pro/utils/sqlConvert/convertColumnName.js +2 -2
- package/dist/libs/crud-pro/utils/sqlConvert/convertMix.d.ts +3 -0
- package/dist/libs/crud-pro/utils/sqlConvert/convertMix.js +22 -0
- package/dist/libs/global-config/global-config.d.ts +45 -0
- package/dist/libs/global-config/global-config.js +33 -0
- package/dist/libs/utils/base64.d.ts +9 -0
- package/dist/libs/utils/base64.js +42 -0
- package/dist/libs/utils/errorToString.d.ts +2 -0
- package/dist/libs/utils/errorToString.js +57 -0
- package/dist/libs/utils/fatcms-request.js +2 -2
- package/dist/libs/utils/functions.d.ts +2 -1
- package/dist/libs/utils/functions.js +6 -1
- package/dist/middleware/forbidden.middleware.js +4 -20
- package/dist/middleware/global.middleware.js +30 -10
- package/dist/middleware/permission.middleware.js +1 -1
- package/dist/models/AsyncTaskModel.d.ts +74 -0
- package/dist/models/AsyncTaskModel.js +31 -0
- package/dist/models/RedisKeys.d.ts +14 -0
- package/dist/models/RedisKeys.js +17 -0
- package/dist/models/SystemEntities.d.ts +8 -1
- package/dist/models/SystemEntities.js +7 -0
- package/dist/models/SystemTables.d.ts +1 -3
- package/dist/models/SystemTables.js +2 -4
- package/dist/models/bizmodels.d.ts +28 -0
- package/dist/models/bizmodels.js +6 -1
- package/dist/schedule/anonymousContext.d.ts +14 -0
- package/dist/schedule/anonymousContext.js +59 -0
- package/dist/schedule/index.d.ts +4 -3
- package/dist/schedule/index.js +8 -67
- package/dist/schedule/runSchedule.d.ts +12 -0
- package/dist/schedule/runSchedule.js +68 -0
- package/dist/schedule/scheduleNames.d.ts +13 -0
- package/dist/schedule/scheduleNames.js +17 -0
- package/dist/service/AuthService.js +8 -5
- package/dist/service/EnumInfoService.js +9 -5
- package/dist/service/FileCenterService.js +13 -9
- package/dist/service/SysConfigService.d.ts +1 -1
- package/dist/service/SysConfigService.js +4 -2
- package/dist/service/UserAccountService.js +10 -6
- package/dist/service/UserSessionService.d.ts +21 -0
- package/dist/service/UserSessionService.js +73 -2
- package/dist/service/VisitStatService.d.ts +1 -1
- package/dist/service/VisitStatService.js +20 -27
- package/dist/service/WorkbenchService.d.ts +33 -0
- package/dist/service/WorkbenchService.js +70 -12
- package/dist/service/anyapi/AnyApiSandboxService.js +12 -12
- package/dist/service/anyapi/AnyApiService.js +4 -2
- package/dist/service/asyncTask/AsyncTaskRunnerService.d.ts +50 -0
- package/dist/service/asyncTask/AsyncTaskRunnerService.js +287 -0
- package/dist/service/asyncTask/AsyncTaskService.d.ts +7 -0
- package/dist/service/asyncTask/AsyncTaskService.js +34 -0
- package/dist/service/asyncTask/handler/ExcelInfoModel.d.ts +10 -0
- package/dist/service/asyncTask/handler/ExcelInfoModel.js +2 -0
- package/dist/service/asyncTask/handler/ExportExcelAsyncTaskHandler.d.ts +7 -0
- package/dist/service/asyncTask/handler/ExportExcelAsyncTaskHandler.js +216 -0
- package/dist/service/asyncTask/handler/ExportExcelByInnerHttpHandler.d.ts +36 -0
- package/dist/service/asyncTask/handler/ExportExcelByInnerHttpHandler.js +139 -0
- package/dist/service/asyncTask/handler/ExportExcelByStdCrudHandler.d.ts +46 -0
- package/dist/service/asyncTask/handler/ExportExcelByStdCrudHandler.js +121 -0
- package/dist/service/base/BaseService.d.ts +12 -0
- package/dist/service/base/BaseService.js +22 -0
- package/dist/service/base/RedisCacheService.d.ts +7 -0
- package/dist/service/base/RedisCacheService.js +7 -0
- package/dist/service/crudstd/CrudStdService.d.ts +8 -1
- package/dist/service/crudstd/CrudStdService.js +63 -6
- package/dist/service/curd/CrudProQuick.d.ts +44 -0
- package/dist/service/curd/CrudProQuick.js +147 -0
- package/dist/service/curd/CurdMixByAccountService.d.ts +4 -4
- package/dist/service/curd/CurdMixByAccountService.js +12 -6
- package/dist/service/curd/CurdMixByDictService.d.ts +4 -4
- package/dist/service/curd/CurdMixByDictService.js +10 -7
- package/dist/service/curd/CurdMixByLinkToCustomService.d.ts +13 -4
- package/dist/service/curd/CurdMixByLinkToCustomService.js +73 -24
- package/dist/service/curd/CurdMixBySysConfigService.d.ts +3 -3
- package/dist/service/curd/CurdMixBySysConfigService.js +4 -2
- package/dist/service/curd/CurdMixByWorkbenchService.d.ts +3 -3
- package/dist/service/curd/CurdMixByWorkbenchService.js +4 -2
- package/dist/service/curd/CurdMixService.d.ts +13 -3
- package/dist/service/curd/CurdMixService.js +26 -2
- package/dist/service/curd/CurdMixUtils.d.ts +27 -4
- package/dist/service/curd/CurdMixUtils.js +115 -41
- package/dist/service/curd/CurdProService.d.ts +3 -10
- package/dist/service/curd/CurdProService.js +36 -148
- package/dist/service/curd/fixCfgModel.d.ts +3 -0
- package/dist/service/curd/fixCfgModel.js +107 -0
- package/dist/service/proxyapi/ProxyApiLoadService.js +7 -4
- package/dist/service/proxyapi/ProxyApiService.d.ts +1 -0
- package/dist/service/proxyapi/ProxyApiService.js +43 -9
- package/dist/views/404_app.html +31 -31
- package/dist/views/404_workbench.html +34 -34
- package/package.json +28 -24
- package/tsconfig.json +32 -0
- package/dist/controller/medstatistic/MedAdminController.d.ts +0 -35
- package/dist/controller/medstatistic/MedAdminController.js +0 -205
- package/dist/controller/medstatistic/MedClientController.d.ts +0 -28
- package/dist/controller/medstatistic/MedClientController.js +0 -188
- package/dist/controller/medstatistic/MedMessageService.d.ts +0 -19
- package/dist/controller/medstatistic/MedMessageService.js +0 -95
- package/dist/controller/medstatistic/MedScoreService.d.ts +0 -21
- package/dist/controller/medstatistic/MedScoreService.js +0 -107
- package/dist/controller/medstatistic/constants.d.ts +0 -32
- package/dist/controller/medstatistic/constants.js +0 -43
- package/src/config/config.default.ts +0 -172
- package/src/config/seed/aeskey.txt +0 -1
- package/src/config/utils.ts +0 -23
- package/src/configuration.ts +0 -83
- package/src/controller/base/BaseApiController.ts +0 -145
- package/src/controller/gateway/AnyApiGatewayController.ts +0 -33
- package/src/controller/gateway/CrudMtdGatewayController.ts +0 -107
- package/src/controller/gateway/CrudStdGatewayController.ts +0 -101
- package/src/controller/gateway/DocGatewayController.ts +0 -165
- package/src/controller/gateway/FileController.ts +0 -110
- package/src/controller/gateway/ProxyApiGatewayController.ts +0 -47
- package/src/controller/gateway/PublicApiController.ts +0 -145
- package/src/controller/gateway/StaticController.ts +0 -328
- package/src/controller/helpers.controller.ts +0 -161
- package/src/controller/home.controller.ts +0 -71
- package/src/controller/manage/AnyApiMangeApi.ts +0 -66
- package/src/controller/manage/AppLogMangeApi.ts +0 -53
- package/src/controller/manage/AppMangeApi.ts +0 -53
- package/src/controller/manage/AppPageMangeApi.ts +0 -52
- package/src/controller/manage/AppSchemaHistoryApi.ts +0 -49
- package/src/controller/manage/CrudMethodsMangeApi.ts +0 -49
- package/src/controller/manage/CrudStandardDesignApi.ts +0 -353
- package/src/controller/manage/DataDictManageApi.ts +0 -78
- package/src/controller/manage/DeployManageApi.ts +0 -179
- package/src/controller/manage/DocLibManageApi.ts +0 -69
- package/src/controller/manage/DocManageApi.ts +0 -99
- package/src/controller/manage/FileManageApi.ts +0 -45
- package/src/controller/manage/LowCodeTplManageApi.ts +0 -52
- package/src/controller/manage/MenuManageApi.ts +0 -63
- package/src/controller/manage/ProxyApiMangeApi.ts +0 -52
- package/src/controller/manage/SuperAdminManageApi.ts +0 -138
- package/src/controller/manage/SysConfigMangeApi.ts +0 -95
- package/src/controller/manage/SystemInfoManageApi.ts +0 -48
- package/src/controller/manage/UserAccountManageApi.ts +0 -88
- package/src/controller/manage/WorkbenchMangeApi.ts +0 -72
- package/src/controller/medstatistic/MedAdminController.ts +0 -221
- package/src/controller/medstatistic/MedClientController.ts +0 -188
- package/src/controller/medstatistic/MedMessageService.ts +0 -89
- package/src/controller/medstatistic/MedScoreService.ts +0 -108
- package/src/controller/medstatistic/constants.ts +0 -63
- package/src/controller/myinfo/AuthController.ts +0 -174
- package/src/controller/myinfo/MyInfoController.ts +0 -32
- package/src/controller/render/AppRenderController.ts +0 -76
- package/src/controller/test.controller.ts +0 -37
- package/src/filter/default.filter.ts +0 -13
- package/src/filter/notfound.filter.ts +0 -10
- package/src/index.ts +0 -71
- package/src/interface.ts +0 -31
- package/src/libs/crud-pro/CrudPro.ts +0 -158
- package/src/libs/crud-pro/defaultConfigs.ts +0 -13
- package/src/libs/crud-pro/exceptions.ts +0 -124
- package/src/libs/crud-pro/interfaces.ts +0 -183
- package/src/libs/crud-pro/models/ExecuteContext.ts +0 -111
- package/src/libs/crud-pro/models/ExecuteContextFunc.ts +0 -86
- package/src/libs/crud-pro/models/FuncContext.ts +0 -21
- package/src/libs/crud-pro/models/RequestCfgModel.ts +0 -141
- package/src/libs/crud-pro/models/RequestModel.ts +0 -141
- package/src/libs/crud-pro/models/ServiceHub.ts +0 -32
- package/src/libs/crud-pro/models/SqlCfgModel.ts +0 -52
- package/src/libs/crud-pro/models/SqlSegArg.ts +0 -13
- package/src/libs/crud-pro/models/Transaction.ts +0 -74
- package/src/libs/crud-pro/models/TransactionMySQL.ts +0 -79
- package/src/libs/crud-pro/models/TransactionPostgres.ts +0 -91
- package/src/libs/crud-pro/models/TransactionSqlServer.ts +0 -107
- package/src/libs/crud-pro/models/keys.ts +0 -159
- package/src/libs/crud-pro/services/CrudProCachedCfgService.ts +0 -75
- package/src/libs/crud-pro/services/CrudProExecuteFuncService.ts +0 -128
- package/src/libs/crud-pro/services/CrudProExecuteSqlService.ts +0 -279
- package/src/libs/crud-pro/services/CrudProFieldUpdateService.ts +0 -60
- package/src/libs/crud-pro/services/CrudProFieldValidateService.ts +0 -180
- package/src/libs/crud-pro/services/CrudProGenSqlCondition.ts +0 -373
- package/src/libs/crud-pro/services/CrudProGenSqlService.ts +0 -202
- package/src/libs/crud-pro/services/CrudProOriginToExecuteSql.ts +0 -397
- package/src/libs/crud-pro/services/CrudProServiceBase.ts +0 -98
- package/src/libs/crud-pro/services/CrudProTableMetaService.ts +0 -59
- package/src/libs/crud-pro/services/CurdProServiceHub.ts +0 -92
- package/src/libs/crud-pro/sql.txt +0 -120
- package/src/libs/crud-pro/utils/CompareUtils.ts +0 -23
- package/src/libs/crud-pro/utils/DatabaseName.ts +0 -40
- package/src/libs/crud-pro/utils/DateTimeUtils.ts +0 -20
- package/src/libs/crud-pro/utils/MemoryRefreshCache.ts +0 -64
- package/src/libs/crud-pro/utils/MessageParseUtils.ts +0 -33
- package/src/libs/crud-pro/utils/MixinUtils.ts +0 -285
- package/src/libs/crud-pro/utils/ModelUtils.ts +0 -55
- package/src/libs/crud-pro/utils/MultiKeyMap.ts +0 -72
- package/src/libs/crud-pro/utils/SqlFuncUtils.ts +0 -29
- package/src/libs/crud-pro/utils/TypeUtils.ts +0 -188
- package/src/libs/crud-pro/utils/ValidateUtils.ts +0 -167
- package/src/libs/crud-pro/utils/pool/MySQLUtils.ts +0 -20
- package/src/libs/crud-pro/utils/pool/PostgresUtils.ts +0 -22
- package/src/libs/crud-pro/utils/pool/SqlServerUtils.ts +0 -22
- package/src/libs/crud-pro/utils/sqlConvert/convertColumnName.ts +0 -26
- package/src/libs/crud-pro/utils/sqlConvert/convertMsSql.ts +0 -11
- package/src/libs/crud-pro/utils/sqlConvert/convertPgSql.ts +0 -11
- package/src/libs/crud-pro/utils/sqlConvert/convertPgType.ts +0 -129
- package/src/libs/utils/common-dto.ts +0 -52
- package/src/libs/utils/crypto-utils.ts +0 -52
- package/src/libs/utils/fatcms-request.ts +0 -115
- package/src/libs/utils/functions.ts +0 -67
- package/src/libs/utils/ordernum-utils.ts +0 -18
- package/src/libs/utils/parseConfig.ts +0 -62
- package/src/libs/utils/parseCreateSql.ts +0 -91
- package/src/libs/utils/render-utils.ts +0 -184
- package/src/middleware/forbidden.middleware.ts +0 -71
- package/src/middleware/global.middleware.ts +0 -278
- package/src/middleware/permission.middleware.ts +0 -81
- package/src/middleware/tx.middleware.ts +0 -30
- package/src/models/SystemEntities.ts +0 -115
- package/src/models/SystemPerm.ts +0 -105
- package/src/models/SystemTables.ts +0 -30
- package/src/models/bizmodels.ts +0 -89
- package/src/models/contextLogger.ts +0 -132
- package/src/models/devops.ts +0 -17
- package/src/models/userSession.ts +0 -216
- package/src/schedule/index.ts +0 -73
- package/src/service/AuthService.ts +0 -270
- package/src/service/EnumInfoService.ts +0 -129
- package/src/service/FileCenterService.ts +0 -394
- package/src/service/SysConfigService.ts +0 -34
- package/src/service/UserAccountService.ts +0 -100
- package/src/service/UserSessionService.ts +0 -81
- package/src/service/VisitStatService.ts +0 -179
- package/src/service/WorkbenchService.ts +0 -160
- package/src/service/anyapi/AnyApiSandboxService.ts +0 -121
- package/src/service/anyapi/AnyApiService.ts +0 -184
- package/src/service/base/ApiBaseService.ts +0 -42
- package/src/service/base/ApiRateLimiter.ts +0 -59
- package/src/service/base/BaseService.ts +0 -74
- package/src/service/base/RedisCacheService.ts +0 -38
- package/src/service/crudstd/CrudStdActionService.ts +0 -27
- package/src/service/crudstd/CrudStdConstant.ts +0 -62
- package/src/service/crudstd/CrudStdRelationService.ts +0 -78
- package/src/service/crudstd/CrudStdService.ts +0 -188
- package/src/service/curd/CurdMixByAccountService.ts +0 -83
- package/src/service/curd/CurdMixByDictService.ts +0 -113
- package/src/service/curd/CurdMixByLinkToCustomService.ts +0 -167
- package/src/service/curd/CurdMixBySysConfigService.ts +0 -78
- package/src/service/curd/CurdMixByWorkbenchService.ts +0 -68
- package/src/service/curd/CurdMixService.ts +0 -65
- package/src/service/curd/CurdMixUtils.ts +0 -248
- package/src/service/curd/CurdProService.ts +0 -379
- package/src/service/proxyapi/ProxyApiLoadService.ts +0 -165
- package/src/service/proxyapi/ProxyApiService.ts +0 -262
- package/src/service/proxyapi/ProxyApiUtils.ts +0 -32
- package/src/service/proxyapi/RouteHandler.ts +0 -8
- package/src/service/proxyapi/RouteTrie.ts +0 -74
- package/src/service/proxyapi/WeightedRandom.ts +0 -37
- package/src/service/proxyapi/WeightedRoundRobin.ts +0 -44
- package/src/views/404_app.html +0 -31
- package/src/views/404_workbench.html +0 -34
- package/src/views/static/favicon.ico +0 -0
|
@@ -1,167 +0,0 @@
|
|
|
1
|
-
import * as moment from 'moment';
|
|
2
|
-
import { KeysOfValidators } from '../models/keys';
|
|
3
|
-
import { CommonException, Exceptions } from '../exceptions';
|
|
4
|
-
import { MixinUtils } from './MixinUtils';
|
|
5
|
-
import { TypeUtils } from './TypeUtils';
|
|
6
|
-
const { isEmpty } = MixinUtils;
|
|
7
|
-
|
|
8
|
-
const validatorUtils = {
|
|
9
|
-
/**
|
|
10
|
-
* 字符串长度
|
|
11
|
-
* @param itemCfg
|
|
12
|
-
* @param itemValue
|
|
13
|
-
*/
|
|
14
|
-
isLengthValid(itemCfg: string, itemValue: any): boolean {
|
|
15
|
-
if (typeof itemValue === 'string') {
|
|
16
|
-
const cfgPart = itemCfg.substring(KeysOfValidators.LENGTH.length);
|
|
17
|
-
return TypeUtils.isNumberScaleValid(cfgPart, itemValue.length);
|
|
18
|
-
}
|
|
19
|
-
return false;
|
|
20
|
-
},
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* 数字范围
|
|
24
|
-
* @param itemCfg
|
|
25
|
-
* @param itemValue
|
|
26
|
-
*/
|
|
27
|
-
isNumberScaleValid(itemCfg: string, itemValue: any) {
|
|
28
|
-
if (typeof itemValue === 'number') {
|
|
29
|
-
const cfgPart = itemCfg.substring(KeysOfValidators.SCALE.length).trim();
|
|
30
|
-
return TypeUtils.isNumberScaleValid(cfgPart, itemValue);
|
|
31
|
-
} else if (TypeUtils.isNumeric(itemValue)) {
|
|
32
|
-
const cfgPart = itemCfg.substring(KeysOfValidators.SCALE.length).trim();
|
|
33
|
-
return TypeUtils.isNumberScaleValid(cfgPart, Number(itemValue));
|
|
34
|
-
}
|
|
35
|
-
return false;
|
|
36
|
-
},
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* 正则表达式
|
|
40
|
-
* @param itemCfg
|
|
41
|
-
* @param itemValue
|
|
42
|
-
*/
|
|
43
|
-
isRegExpValid(itemCfg: string, itemValue: any): boolean {
|
|
44
|
-
if (typeof itemValue === 'string') {
|
|
45
|
-
const cfgPart = itemCfg.substring(KeysOfValidators.REG_EXP.length);
|
|
46
|
-
const regexp = new RegExp(cfgPart);
|
|
47
|
-
return regexp.test(itemValue);
|
|
48
|
-
}
|
|
49
|
-
return false;
|
|
50
|
-
},
|
|
51
|
-
|
|
52
|
-
isMomentValid(itemCfg: string, itemValue: any): boolean {
|
|
53
|
-
const cfgPart = itemCfg.substring(KeysOfValidators.ENUM.length).trim();
|
|
54
|
-
return moment(itemValue, cfgPart, true).isValid();
|
|
55
|
-
},
|
|
56
|
-
|
|
57
|
-
isEnumValid(itemCfg: string, itemValue: any): boolean {
|
|
58
|
-
const cfgPart = itemCfg.substring(KeysOfValidators.ENUM.length).trim();
|
|
59
|
-
const cfgArr = cfgPart.split(','); // 1,2,3,4
|
|
60
|
-
const enumStrArr = cfgArr.map(s => s.trim()).filter(s => !!s);
|
|
61
|
-
|
|
62
|
-
// 枚举值的配置不能为空
|
|
63
|
-
if (isEmpty(enumStrArr)) {
|
|
64
|
-
throw new CommonException(Exceptions.CFG_VALIDATE_ENUM_ERROR, itemCfg);
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
// 值:不能为空
|
|
68
|
-
if (itemValue == null) {
|
|
69
|
-
return false;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
// 值:不能为空
|
|
73
|
-
const itemValueString = itemValue.toString();
|
|
74
|
-
if (isEmpty(itemValueString)) {
|
|
75
|
-
return false;
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
for (let i = 0; i < enumStrArr.length; i++) {
|
|
79
|
-
const enumStr = enumStrArr[i];
|
|
80
|
-
if (enumStr === itemValueString) {
|
|
81
|
-
return true;
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
return false;
|
|
86
|
-
},
|
|
87
|
-
};
|
|
88
|
-
|
|
89
|
-
function validateByCfgStringInner(validateCfg: KeysOfValidators | string, itemValue: any): boolean {
|
|
90
|
-
if (KeysOfValidators.ARRAY === validateCfg) {
|
|
91
|
-
return itemValue !== null && Array.isArray(itemValue);
|
|
92
|
-
} else if (KeysOfValidators.ARRAY_STRING === validateCfg) {
|
|
93
|
-
return (
|
|
94
|
-
itemValue !== null &&
|
|
95
|
-
Array.isArray(itemValue) &&
|
|
96
|
-
MixinUtils.isElementAllMatch(itemValue, e => {
|
|
97
|
-
return typeof e === 'string';
|
|
98
|
-
})
|
|
99
|
-
);
|
|
100
|
-
} else if (KeysOfValidators.ARRAY_NUMBER === validateCfg) {
|
|
101
|
-
return (
|
|
102
|
-
itemValue !== null &&
|
|
103
|
-
Array.isArray(itemValue) &&
|
|
104
|
-
MixinUtils.isElementAllMatch(itemValue, e => {
|
|
105
|
-
return typeof e === 'number';
|
|
106
|
-
})
|
|
107
|
-
);
|
|
108
|
-
} else if (KeysOfValidators.OBJECT === validateCfg) {
|
|
109
|
-
return itemValue !== null && typeof itemValue === 'object';
|
|
110
|
-
} else if (KeysOfValidators.BOOLEAN === validateCfg) {
|
|
111
|
-
return TypeUtils.isBoolean(itemValue);
|
|
112
|
-
} else if (KeysOfValidators.STRING === validateCfg) {
|
|
113
|
-
return TypeUtils.isString(itemValue);
|
|
114
|
-
} else if (KeysOfValidators.INTEGER === validateCfg) {
|
|
115
|
-
return TypeUtils.isInteger(itemValue);
|
|
116
|
-
} else if (KeysOfValidators.NUMBER === validateCfg) {
|
|
117
|
-
return TypeUtils.isNumber(itemValue);
|
|
118
|
-
} else if (KeysOfValidators.NUMERIC === validateCfg) {
|
|
119
|
-
return TypeUtils.isNumeric(itemValue);
|
|
120
|
-
} else if (KeysOfValidators.NAME === validateCfg) {
|
|
121
|
-
return TypeUtils.isValidName(itemValue);
|
|
122
|
-
} else if (KeysOfValidators.PHONE_CN === validateCfg) {
|
|
123
|
-
return TypeUtils.isChinesePhone(itemValue.toString());
|
|
124
|
-
} else if (KeysOfValidators.EMAIL === validateCfg) {
|
|
125
|
-
return TypeUtils.isEmailStrValid(itemValue);
|
|
126
|
-
} else if (validateCfg.startsWith(KeysOfValidators.LENGTH)) {
|
|
127
|
-
return validatorUtils.isLengthValid(validateCfg, itemValue);
|
|
128
|
-
} else if (validateCfg.startsWith(KeysOfValidators.REG_EXP)) {
|
|
129
|
-
return validatorUtils.isRegExpValid(validateCfg, itemValue);
|
|
130
|
-
} else if (validateCfg.startsWith(KeysOfValidators.SCALE)) {
|
|
131
|
-
return validatorUtils.isNumberScaleValid(validateCfg, itemValue);
|
|
132
|
-
} else if (validateCfg.startsWith(KeysOfValidators.ENUM)) {
|
|
133
|
-
return validatorUtils.isEnumValid(validateCfg, itemValue);
|
|
134
|
-
} else if (validateCfg.startsWith(KeysOfValidators.MOMENT)) {
|
|
135
|
-
return validatorUtils.isMomentValid(validateCfg, itemValue);
|
|
136
|
-
}
|
|
137
|
-
throw new CommonException(Exceptions.CFG_VALIDATE_NOT_SUPPORT, validateCfg);
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
function validateByCfgString(validateCfg: KeysOfValidators | string, itemValue: any, errPath: string) {
|
|
141
|
-
if (isEmpty(validateCfg)) {
|
|
142
|
-
// 没有配置,不需要校验
|
|
143
|
-
return;
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
// 必填
|
|
148
|
-
if ("required" === validateCfg) {
|
|
149
|
-
if (isEmpty(itemValue)) {
|
|
150
|
-
throw new CommonException(Exceptions.VALIDATE_ERR, "'参数校验错误,字段 " + errPath + ' 不满足校验配置:' + validateCfg);
|
|
151
|
-
}
|
|
152
|
-
return;
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
// 没有填写的话,不需要校验。
|
|
156
|
-
if (isEmpty(itemValue)) {
|
|
157
|
-
return;
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
// 校验失败
|
|
162
|
-
if (!validateByCfgStringInner(validateCfg, itemValue)) {
|
|
163
|
-
throw new CommonException(Exceptions.VALIDATE_ERR, "'参数校验错误,字段 " + errPath + ' 不满足校验配置:' + validateCfg);
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
export { validateByCfgString };
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { createPool } from 'mysql2/promise';
|
|
2
|
-
import { IConnectionPool } from '../../interfaces';
|
|
3
|
-
import {SqlDbType} from "../../models/keys";
|
|
4
|
-
|
|
5
|
-
const POOL_CACHE_MAP: Record<string, IConnectionPool> = {};
|
|
6
|
-
|
|
7
|
-
function getConnectionPool(poolName: string, poolOptions: any): IConnectionPool {
|
|
8
|
-
let pool = POOL_CACHE_MAP[poolName];
|
|
9
|
-
if (!pool) {
|
|
10
|
-
pool = {
|
|
11
|
-
dbType: SqlDbType.mysql,
|
|
12
|
-
poolName: poolName,
|
|
13
|
-
poolInstance: createPool(poolOptions),
|
|
14
|
-
};
|
|
15
|
-
POOL_CACHE_MAP[poolName] = pool;
|
|
16
|
-
}
|
|
17
|
-
return pool;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export { getConnectionPool };
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import {Pool} from 'pg';
|
|
2
|
-
import {IConnectionPool} from '../../interfaces';
|
|
3
|
-
import {SqlDbType} from "../../models/keys";
|
|
4
|
-
|
|
5
|
-
const POOL_CACHE_MAP: Record<string, IConnectionPool> = {};
|
|
6
|
-
|
|
7
|
-
function getConnectionPool(poolName: string, poolOptions: any): IConnectionPool {
|
|
8
|
-
let pool = POOL_CACHE_MAP[poolName];
|
|
9
|
-
if (!pool) {
|
|
10
|
-
const poolObj = new Pool(poolOptions);
|
|
11
|
-
|
|
12
|
-
pool = {
|
|
13
|
-
dbType: SqlDbType.postgres,
|
|
14
|
-
poolName: poolName,
|
|
15
|
-
poolInstance: poolObj,
|
|
16
|
-
};
|
|
17
|
-
POOL_CACHE_MAP[poolName] = pool;
|
|
18
|
-
}
|
|
19
|
-
return pool;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export { getConnectionPool };
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import {ConnectionPool} from 'mssql';
|
|
2
|
-
import {IConnectionPool} from '../../interfaces';
|
|
3
|
-
import {SqlDbType} from "../../models/keys";
|
|
4
|
-
|
|
5
|
-
const POOL_CACHE_MAP: Record<string, IConnectionPool> = {};
|
|
6
|
-
|
|
7
|
-
function getConnectionPool(poolName: string, poolOptions: any): IConnectionPool {
|
|
8
|
-
let pool = POOL_CACHE_MAP[poolName];
|
|
9
|
-
if (!pool) {
|
|
10
|
-
const poolObj = new ConnectionPool(poolOptions);
|
|
11
|
-
|
|
12
|
-
pool = {
|
|
13
|
-
dbType: SqlDbType.sqlserver,
|
|
14
|
-
poolName: poolName,
|
|
15
|
-
poolInstance: poolObj,
|
|
16
|
-
};
|
|
17
|
-
POOL_CACHE_MAP[poolName] = pool;
|
|
18
|
-
}
|
|
19
|
-
return pool;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export { getConnectionPool };
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import {SqlCfgModel} from "../../models/SqlCfgModel";
|
|
2
|
-
import {SqlDbType} from "../../models/keys";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
function toSqlColumnName(columnName: string, sqlCfgModel: SqlCfgModel): string {
|
|
6
|
-
if (sqlCfgModel.sqlDdType === SqlDbType.postgres) {
|
|
7
|
-
return '"' + columnName + '"';
|
|
8
|
-
}
|
|
9
|
-
if (sqlCfgModel.sqlDdType === SqlDbType.sqlserver) {
|
|
10
|
-
return '[' + columnName + ']';
|
|
11
|
-
}
|
|
12
|
-
return '`' + columnName + '`';
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
function toSqlColumnNamesJoin(columns: string[], sqlCfgModel: SqlCfgModel): string {
|
|
16
|
-
const columns2 = columns.map(col => {
|
|
17
|
-
return toSqlColumnName(col.trim(), sqlCfgModel);
|
|
18
|
-
});
|
|
19
|
-
return columns2.join(',');
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
export {
|
|
24
|
-
toSqlColumnName,
|
|
25
|
-
toSqlColumnNamesJoin
|
|
26
|
-
}
|
|
@@ -1,129 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// // 定义 PostgreSQL 数据类型 OID 映射
|
|
3
|
-
// const PG_TYPE_OIDS = {
|
|
4
|
-
// INT2: 21, // smallint
|
|
5
|
-
// INT4: 23, // integer
|
|
6
|
-
// INT8: 20, // bigint
|
|
7
|
-
// FLOAT4: 700, // real
|
|
8
|
-
// FLOAT8: 701, // double precision
|
|
9
|
-
// NUMERIC: 1700, // numeric
|
|
10
|
-
// MONEY: 790, // money
|
|
11
|
-
// BOOL: 16, // boolean
|
|
12
|
-
// DATE: 1082, // date
|
|
13
|
-
// TIMESTAMP: 1114, // timestamp without time zone
|
|
14
|
-
// TIMESTAMPTZ: 1184, // timestamp with time zone
|
|
15
|
-
// JSON: 114, // json
|
|
16
|
-
// JSONB: 3802, // jsonb
|
|
17
|
-
// };
|
|
18
|
-
//
|
|
19
|
-
//
|
|
20
|
-
//
|
|
21
|
-
// /**
|
|
22
|
-
// * 将 PostgreSQL 数据类型转换为 JavaScript 类型
|
|
23
|
-
// * @param {any} value - 原始值
|
|
24
|
-
// * @param {number} oid - 数据类型 OID
|
|
25
|
-
// * @returns {any} 转换后的值
|
|
26
|
-
// */
|
|
27
|
-
// function convertPgType(value: any, oid: any) {
|
|
28
|
-
// // 如果值为 null,直接返回
|
|
29
|
-
// if (value === null) {
|
|
30
|
-
// return null;
|
|
31
|
-
// }
|
|
32
|
-
//
|
|
33
|
-
// const typeOfValue = typeof value;
|
|
34
|
-
// if (typeOfValue === 'undefined') {
|
|
35
|
-
// return null;
|
|
36
|
-
// }
|
|
37
|
-
// if (typeOfValue === 'number' || typeOfValue === "boolean" || typeOfValue === "object") {
|
|
38
|
-
// return value;
|
|
39
|
-
// }
|
|
40
|
-
// if (typeOfValue === 'bigint') {
|
|
41
|
-
// return value.toString()
|
|
42
|
-
// }
|
|
43
|
-
//
|
|
44
|
-
// switch (oid) {
|
|
45
|
-
// // 整数类型(全部转为 Number)
|
|
46
|
-
// case PG_TYPE_OIDS.INT2: // smallint
|
|
47
|
-
// case PG_TYPE_OIDS.INT4: // integer
|
|
48
|
-
// return Number(value);
|
|
49
|
-
// case PG_TYPE_OIDS.INT8: // bigint
|
|
50
|
-
// return value;
|
|
51
|
-
//
|
|
52
|
-
// // 浮点类型
|
|
53
|
-
// case PG_TYPE_OIDS.FLOAT4: // real
|
|
54
|
-
// case PG_TYPE_OIDS.FLOAT8: // double precision
|
|
55
|
-
// case PG_TYPE_OIDS.NUMERIC: // numeric
|
|
56
|
-
// case PG_TYPE_OIDS.MONEY: // money
|
|
57
|
-
// return Number(value);
|
|
58
|
-
//
|
|
59
|
-
// // 布尔类型
|
|
60
|
-
// case PG_TYPE_OIDS.BOOL:
|
|
61
|
-
// if (typeof value === 'boolean') {
|
|
62
|
-
// return value;
|
|
63
|
-
// }
|
|
64
|
-
// return value === 't' || value === 'true' || value === true;
|
|
65
|
-
//
|
|
66
|
-
// // 日期/时间类型
|
|
67
|
-
// case PG_TYPE_OIDS.DATE:
|
|
68
|
-
// return new Date(value).toISOString().split('T')[0];
|
|
69
|
-
//
|
|
70
|
-
// case PG_TYPE_OIDS.TIMESTAMP:
|
|
71
|
-
// case PG_TYPE_OIDS.TIMESTAMPTZ:
|
|
72
|
-
// return new Date(value).toISOString();
|
|
73
|
-
//
|
|
74
|
-
// // JSON 类型
|
|
75
|
-
// case PG_TYPE_OIDS.JSON:
|
|
76
|
-
// case PG_TYPE_OIDS.JSONB:
|
|
77
|
-
// // try {
|
|
78
|
-
// // return JSON.parse(value);
|
|
79
|
-
// // } catch (e) {
|
|
80
|
-
// // return value; // 解析失败时返回原始值
|
|
81
|
-
// // }
|
|
82
|
-
//
|
|
83
|
-
// // 默认不转换
|
|
84
|
-
// default:
|
|
85
|
-
// return value;
|
|
86
|
-
// }
|
|
87
|
-
// }
|
|
88
|
-
//
|
|
89
|
-
//
|
|
90
|
-
// /**
|
|
91
|
-
// * 获取并转换PG查询结果的数据类型
|
|
92
|
-
// * @param result
|
|
93
|
-
// */
|
|
94
|
-
// function pickAndConvertPgRows(result: any): any[] {
|
|
95
|
-
// if (!result || !Array.isArray(result.rows)) {
|
|
96
|
-
// return [];
|
|
97
|
-
// }
|
|
98
|
-
//
|
|
99
|
-
// console.log('',convertPgType)
|
|
100
|
-
// try {
|
|
101
|
-
// // 获取字段类型 OID
|
|
102
|
-
// const fieldTypes = result.fields.map((field: any) => field.dataTypeID);
|
|
103
|
-
//
|
|
104
|
-
// // 转换每一行的数据类型
|
|
105
|
-
// return result.rows.map((row:any) => {
|
|
106
|
-
// const convertedRow = {};
|
|
107
|
-
// Object.keys(row).forEach((key, index) => {
|
|
108
|
-
// const value = row[key];
|
|
109
|
-
// const oid = fieldTypes[index];
|
|
110
|
-
// convertedRow[key] = convertPgType(value, oid);
|
|
111
|
-
// });
|
|
112
|
-
// return convertedRow;
|
|
113
|
-
// });
|
|
114
|
-
// } catch (e) {
|
|
115
|
-
// console.error('pickAndConvertPgRows', e);
|
|
116
|
-
// }
|
|
117
|
-
// return [];
|
|
118
|
-
// }
|
|
119
|
-
|
|
120
|
-
function pickAndConvertPgRows(result: any): any[] {
|
|
121
|
-
if (!result || !Array.isArray(result.rows)) {
|
|
122
|
-
return [];
|
|
123
|
-
}
|
|
124
|
-
return result.rows;
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
export {
|
|
128
|
-
pickAndConvertPgRows
|
|
129
|
-
}
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
export interface ICommonResult {
|
|
2
|
-
success: boolean;
|
|
3
|
-
data?: any;
|
|
4
|
-
message?: string;
|
|
5
|
-
code?: string;
|
|
6
|
-
debugInfo?: any;
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
export class CommonResult implements ICommonResult {
|
|
10
|
-
code: string;
|
|
11
|
-
data: any;
|
|
12
|
-
message: string;
|
|
13
|
-
success: boolean;
|
|
14
|
-
debugInfo: any;
|
|
15
|
-
|
|
16
|
-
public static successNotNull(data?: any): CommonResult {
|
|
17
|
-
const res = new CommonResult();
|
|
18
|
-
if (data) {
|
|
19
|
-
res.success = true;
|
|
20
|
-
res.data = data;
|
|
21
|
-
} else {
|
|
22
|
-
res.success = false;
|
|
23
|
-
res.message = '对象找不到';
|
|
24
|
-
}
|
|
25
|
-
return res;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
public static successRes(data?: any): CommonResult {
|
|
29
|
-
const res = new CommonResult();
|
|
30
|
-
res.success = true;
|
|
31
|
-
res.data = data;
|
|
32
|
-
return res;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
public static successMsg(message: string, data?: any): CommonResult {
|
|
36
|
-
const res = new CommonResult();
|
|
37
|
-
res.success = true;
|
|
38
|
-
res.message = message;
|
|
39
|
-
res.data = data;
|
|
40
|
-
return res;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
public static errorRes(message: string, errorCode = '', debugInfo: any = null): CommonResult {
|
|
44
|
-
const res = new CommonResult();
|
|
45
|
-
res.success = false;
|
|
46
|
-
res.data = null;
|
|
47
|
-
res.message = message;
|
|
48
|
-
res.code = errorCode;
|
|
49
|
-
res.debugInfo = debugInfo;
|
|
50
|
-
return res;
|
|
51
|
-
}
|
|
52
|
-
}
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
import * as crypto from 'crypto';
|
|
2
|
-
import * as path from 'path';
|
|
3
|
-
import * as fs from 'fs';
|
|
4
|
-
import * as md5 from 'md5';
|
|
5
|
-
import { Aes128CBC } from 'aes-128-cbc';
|
|
6
|
-
|
|
7
|
-
function hashUtf8Hex(data: string): string {
|
|
8
|
-
const hash = crypto.createHash('sha256');
|
|
9
|
-
const chunkSize = 1024; // 每次处理 1MB 数据
|
|
10
|
-
for (let i = 0; i < data.length; i += chunkSize) {
|
|
11
|
-
const chunk = data.slice(i, i + chunkSize);
|
|
12
|
-
const inputBuffer = Buffer.from(chunk, 'utf8');
|
|
13
|
-
hash.update(inputBuffer);
|
|
14
|
-
}
|
|
15
|
-
return hash.digest('hex');
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
function readSeed1() {
|
|
19
|
-
// 这个文件肯定存在
|
|
20
|
-
const t = path.join(__dirname, '../../config/seed/aeskey.txt');
|
|
21
|
-
return fs.readFileSync(t, 'utf-8');
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
function readSeed2(): string {
|
|
25
|
-
const filePath = path.join(__dirname, '../../../config/seed/aeskey.txt');
|
|
26
|
-
if (!fs.existsSync(filePath)) {
|
|
27
|
-
return null;
|
|
28
|
-
}
|
|
29
|
-
return fs.readFileSync(filePath, 'utf-8');
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
function createAes128BySeedContent(seedContent:string){
|
|
34
|
-
const hash1 = hashUtf8Hex(seedContent.trim());
|
|
35
|
-
const key = md5(hash1);
|
|
36
|
-
const iv = md5(key + hash1);
|
|
37
|
-
return new Aes128CBC(key, iv);
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
function createAes128BySeedFile() {
|
|
41
|
-
const seed2 = readSeed2();
|
|
42
|
-
if (seed2) {
|
|
43
|
-
return createAes128BySeedContent(seed2);
|
|
44
|
-
}
|
|
45
|
-
const seed1 = readSeed1();
|
|
46
|
-
return createAes128BySeedContent(seed1);
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
const privateAES = createAes128BySeedFile();
|
|
51
|
-
|
|
52
|
-
export { privateAES };
|
|
@@ -1,115 +0,0 @@
|
|
|
1
|
-
import { Context } from '@midwayjs/koa';
|
|
2
|
-
import * as _ from 'lodash';
|
|
3
|
-
import {privateAES} from "./crypto-utils";
|
|
4
|
-
import {CommonException} from "../crud-pro/exceptions";
|
|
5
|
-
|
|
6
|
-
function isEnableByHeaderKey(ctx: Context, configName: string){
|
|
7
|
-
const fatcmsDebug = ctx.app.getConfig(configName);
|
|
8
|
-
const headerKey = _.get(fatcmsDebug, 'headerKey');
|
|
9
|
-
const headerSecret = _.get(fatcmsDebug, 'headerSecret');
|
|
10
|
-
if (!headerSecret || !headerKey) {
|
|
11
|
-
return false;
|
|
12
|
-
}
|
|
13
|
-
const headers = _.get(ctx, 'request.headers') || {};
|
|
14
|
-
return headers[headerKey] === headerSecret;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* 是否开启调试能力
|
|
20
|
-
* @param ctx
|
|
21
|
-
*/
|
|
22
|
-
export function isEnableDebug(ctx: Context): boolean {
|
|
23
|
-
return isEnableByHeaderKey(ctx, 'fatcmsDebug');
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* 是否开启SA账号。只有账号密码没有用,必须通过ModHeader插件设置如下字段
|
|
29
|
-
* @param ctx
|
|
30
|
-
*/
|
|
31
|
-
export function isEnableSuperAdmin(ctx: Context): boolean {
|
|
32
|
-
return isEnableByHeaderKey(ctx, 'fatcmsSAEnable');
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
export function isLocalEnv(ctx: Context): boolean {
|
|
37
|
-
// 系统内部调用。如定时任务,没有request对象。
|
|
38
|
-
if (!ctx.request) {
|
|
39
|
-
return true;
|
|
40
|
-
}
|
|
41
|
-
const host = ctx.request.host;
|
|
42
|
-
return host.startsWith('127.0.0.1') || host.startsWith('localhost:');
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
/**
|
|
48
|
-
* 获取调试时专用的站点code
|
|
49
|
-
* @param ctx
|
|
50
|
-
*/
|
|
51
|
-
export function getDebugWorkbenchCode(ctx: Context) {
|
|
52
|
-
const headers = _.get(ctx, 'request.headers') || {};
|
|
53
|
-
return headers['fatcmsworkbench'];
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
/**
|
|
57
|
-
* 代理转发服务专用
|
|
58
|
-
* @param ctx
|
|
59
|
-
*/
|
|
60
|
-
export function getDebugProxyTarget(ctx: Context): string {
|
|
61
|
-
const headers = _.get(ctx, 'request.headers') || {};
|
|
62
|
-
return headers['fatcmsdebugproxytarget'];
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
export function getCsrfToken(ctx: Context): string{
|
|
67
|
-
const headers = _.get(ctx, 'request.headers') || {};
|
|
68
|
-
return headers['fatcmscsrftoken'];
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
/**
|
|
73
|
-
* 扩展的源码应用:本地开发调试时加载本地的js脚本
|
|
74
|
-
* @param ctx
|
|
75
|
-
*/
|
|
76
|
-
export function getExtLocalLoaderPort(ctx: Context) : string {
|
|
77
|
-
const headers = _.get(ctx, 'request.headers') || {};
|
|
78
|
-
return headers['fatcmsextlocalloaderport'];
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
export async function isCsrfTokenValid(ctx: Context): Promise<boolean> {
|
|
84
|
-
|
|
85
|
-
// 本地开发,不需要校验
|
|
86
|
-
if (isLocalEnv(ctx) || isEnableDebug(ctx)) {
|
|
87
|
-
return true;
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
const fatcmscsrftoken = getCsrfToken(ctx);
|
|
92
|
-
if (!fatcmscsrftoken) {
|
|
93
|
-
return false;
|
|
94
|
-
}
|
|
95
|
-
try {
|
|
96
|
-
const depryptToken = await privateAES.time_decrypt_base64_utf8(fatcmscsrftoken);
|
|
97
|
-
if (depryptToken) {
|
|
98
|
-
const num = Number(depryptToken);
|
|
99
|
-
if (num && ((num + 6 * 3600 * 1000) > Date.now())) {
|
|
100
|
-
return true;
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
} catch (e) {
|
|
104
|
-
console.info('isCsrfTokenValid验证失败')
|
|
105
|
-
}
|
|
106
|
-
return false;
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
export async function assertCsrfToken(ctx: Context) {
|
|
111
|
-
const isOK = await isCsrfTokenValid(ctx);
|
|
112
|
-
if (!isOK) {
|
|
113
|
-
throw new CommonException("ASSERT_CSRF_TOKEN_ERROR", "CSRF_TOKEN 验证失败")
|
|
114
|
-
}
|
|
115
|
-
}
|