midway-fatcms 0.0.1-beta.1
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/README.md +1 -0
- package/dist/config/config.default.d.ts +3 -0
- package/dist/config/config.default.js +148 -0
- package/dist/config/seed/aeskey.txt +1 -0
- package/dist/config/utils.d.ts +1 -0
- package/dist/config/utils.js +23 -0
- package/dist/configuration.d.ts +6 -0
- package/dist/configuration.js +89 -0
- package/dist/controller/base/BaseApiController.d.ts +31 -0
- package/dist/controller/base/BaseApiController.js +138 -0
- package/dist/controller/gateway/AnyApiGatewayController.d.ts +13 -0
- package/dist/controller/gateway/AnyApiGatewayController.js +55 -0
- package/dist/controller/gateway/CrudMtdGatewayController.d.ts +21 -0
- package/dist/controller/gateway/CrudMtdGatewayController.js +116 -0
- package/dist/controller/gateway/CrudStdGatewayController.d.ts +38 -0
- package/dist/controller/gateway/CrudStdGatewayController.js +137 -0
- package/dist/controller/gateway/DocGatewayController.d.ts +27 -0
- package/dist/controller/gateway/DocGatewayController.js +174 -0
- package/dist/controller/gateway/FileController.d.ts +25 -0
- package/dist/controller/gateway/FileController.js +129 -0
- package/dist/controller/gateway/ProxyApiGatewayController.d.ts +18 -0
- package/dist/controller/gateway/ProxyApiGatewayController.js +78 -0
- package/dist/controller/gateway/PublicApiController.d.ts +27 -0
- package/dist/controller/gateway/PublicApiController.js +167 -0
- package/dist/controller/gateway/StaticController.d.ts +21 -0
- package/dist/controller/gateway/StaticController.js +265 -0
- package/dist/controller/helpers.controller.d.ts +39 -0
- package/dist/controller/helpers.controller.js +188 -0
- package/dist/controller/home.controller.d.ts +9 -0
- package/dist/controller/home.controller.js +71 -0
- package/dist/controller/manage/AnyApiMangeApi.d.ts +10 -0
- package/dist/controller/manage/AnyApiMangeApi.js +98 -0
- package/dist/controller/manage/AppLogMangeApi.d.ts +10 -0
- package/dist/controller/manage/AppLogMangeApi.js +88 -0
- package/dist/controller/manage/AppMangeApi.d.ts +10 -0
- package/dist/controller/manage/AppMangeApi.js +88 -0
- package/dist/controller/manage/AppPageMangeApi.d.ts +10 -0
- package/dist/controller/manage/AppPageMangeApi.js +87 -0
- package/dist/controller/manage/AppSchemaHistoryApi.d.ts +10 -0
- package/dist/controller/manage/AppSchemaHistoryApi.js +83 -0
- package/dist/controller/manage/CrudMethodsMangeApi.d.ts +10 -0
- package/dist/controller/manage/CrudMethodsMangeApi.js +84 -0
- package/dist/controller/manage/CrudStandardDesignApi.d.ts +38 -0
- package/dist/controller/manage/CrudStandardDesignApi.js +339 -0
- package/dist/controller/manage/DataDictManageApi.d.ts +15 -0
- package/dist/controller/manage/DataDictManageApi.js +133 -0
- package/dist/controller/manage/DeployManageApi.d.ts +19 -0
- package/dist/controller/manage/DeployManageApi.js +176 -0
- package/dist/controller/manage/DocLibManageApi.d.ts +10 -0
- package/dist/controller/manage/DocLibManageApi.js +104 -0
- package/dist/controller/manage/DocManageApi.d.ts +11 -0
- package/dist/controller/manage/DocManageApi.js +130 -0
- package/dist/controller/manage/FileManageApi.d.ts +13 -0
- package/dist/controller/manage/FileManageApi.js +77 -0
- package/dist/controller/manage/LowCodeTplManageApi.d.ts +13 -0
- package/dist/controller/manage/LowCodeTplManageApi.js +86 -0
- package/dist/controller/manage/MenuManageApi.d.ts +10 -0
- package/dist/controller/manage/MenuManageApi.js +93 -0
- package/dist/controller/manage/ProxyApiMangeApi.d.ts +10 -0
- package/dist/controller/manage/ProxyApiMangeApi.js +87 -0
- package/dist/controller/manage/SuperAdminManageApi.d.ts +24 -0
- package/dist/controller/manage/SuperAdminManageApi.js +149 -0
- package/dist/controller/manage/SysConfigMangeApi.d.ts +11 -0
- package/dist/controller/manage/SysConfigMangeApi.js +124 -0
- package/dist/controller/manage/SystemInfoManageApi.d.ts +12 -0
- package/dist/controller/manage/SystemInfoManageApi.js +66 -0
- package/dist/controller/manage/UserAccountManageApi.d.ts +14 -0
- package/dist/controller/manage/UserAccountManageApi.js +124 -0
- package/dist/controller/manage/WorkbenchMangeApi.d.ts +11 -0
- package/dist/controller/manage/WorkbenchMangeApi.js +103 -0
- package/dist/controller/medstatistic/MedAdminController.d.ts +35 -0
- package/dist/controller/medstatistic/MedAdminController.js +205 -0
- package/dist/controller/medstatistic/MedClientController.d.ts +28 -0
- package/dist/controller/medstatistic/MedClientController.js +188 -0
- package/dist/controller/medstatistic/MedMessageService.d.ts +19 -0
- package/dist/controller/medstatistic/MedMessageService.js +95 -0
- package/dist/controller/medstatistic/MedScoreService.d.ts +21 -0
- package/dist/controller/medstatistic/MedScoreService.js +107 -0
- package/dist/controller/medstatistic/constants.d.ts +32 -0
- package/dist/controller/medstatistic/constants.js +43 -0
- package/dist/controller/myinfo/AuthController.d.ts +37 -0
- package/dist/controller/myinfo/AuthController.js +189 -0
- package/dist/controller/myinfo/MyInfoController.d.ts +13 -0
- package/dist/controller/myinfo/MyInfoController.js +51 -0
- package/dist/controller/render/AppRenderController.d.ts +11 -0
- package/dist/controller/render/AppRenderController.js +85 -0
- package/dist/controller/test.controller.d.ts +8 -0
- package/dist/controller/test.controller.js +51 -0
- package/dist/filter/default.filter.d.ts +7 -0
- package/dist/filter/default.filter.js +23 -0
- package/dist/filter/notfound.filter.d.ts +5 -0
- package/dist/filter/notfound.filter.js +20 -0
- package/dist/index.d.ts +70 -0
- package/dist/index.js +88 -0
- package/dist/interface.d.ts +27 -0
- package/dist/interface.js +3 -0
- package/dist/libs/crud-pro/CrudPro.d.ts +36 -0
- package/dist/libs/crud-pro/CrudPro.js +131 -0
- package/dist/libs/crud-pro/defaultConfigs.d.ts +4 -0
- package/dist/libs/crud-pro/defaultConfigs.js +13 -0
- package/dist/libs/crud-pro/exceptions.d.ts +104 -0
- package/dist/libs/crud-pro/exceptions.js +117 -0
- package/dist/libs/crud-pro/interfaces.d.ts +157 -0
- package/dist/libs/crud-pro/interfaces.js +12 -0
- package/dist/libs/crud-pro/models/ExecuteContext.d.ts +42 -0
- package/dist/libs/crud-pro/models/ExecuteContext.js +79 -0
- package/dist/libs/crud-pro/models/ExecuteContextFunc.d.ts +31 -0
- package/dist/libs/crud-pro/models/ExecuteContextFunc.js +64 -0
- package/dist/libs/crud-pro/models/FuncContext.d.ts +18 -0
- package/dist/libs/crud-pro/models/FuncContext.js +6 -0
- package/dist/libs/crud-pro/models/RequestCfgModel.d.ts +65 -0
- package/dist/libs/crud-pro/models/RequestCfgModel.js +81 -0
- package/dist/libs/crud-pro/models/RequestModel.d.ts +25 -0
- package/dist/libs/crud-pro/models/RequestModel.js +113 -0
- package/dist/libs/crud-pro/models/ServiceHub.d.ts +20 -0
- package/dist/libs/crud-pro/models/ServiceHub.js +2 -0
- package/dist/libs/crud-pro/models/SqlCfgModel.d.ts +22 -0
- package/dist/libs/crud-pro/models/SqlCfgModel.js +40 -0
- package/dist/libs/crud-pro/models/SqlSegArg.d.ts +6 -0
- package/dist/libs/crud-pro/models/SqlSegArg.js +12 -0
- package/dist/libs/crud-pro/models/Transaction.d.ts +29 -0
- package/dist/libs/crud-pro/models/Transaction.js +67 -0
- package/dist/libs/crud-pro/models/TransactionMySQL.d.ts +28 -0
- package/dist/libs/crud-pro/models/TransactionMySQL.js +76 -0
- package/dist/libs/crud-pro/models/TransactionPostgres.d.ts +28 -0
- package/dist/libs/crud-pro/models/TransactionPostgres.js +85 -0
- package/dist/libs/crud-pro/models/TransactionSqlServer.d.ts +34 -0
- package/dist/libs/crud-pro/models/TransactionSqlServer.js +92 -0
- package/dist/libs/crud-pro/models/keys.d.ts +106 -0
- package/dist/libs/crud-pro/models/keys.js +149 -0
- package/dist/libs/crud-pro/services/CrudProCachedCfgService.d.ts +10 -0
- package/dist/libs/crud-pro/services/CrudProCachedCfgService.js +61 -0
- package/dist/libs/crud-pro/services/CrudProExecuteFuncService.d.ts +9 -0
- package/dist/libs/crud-pro/services/CrudProExecuteFuncService.js +112 -0
- package/dist/libs/crud-pro/services/CrudProExecuteSqlService.d.ts +17 -0
- package/dist/libs/crud-pro/services/CrudProExecuteSqlService.js +227 -0
- package/dist/libs/crud-pro/services/CrudProFieldUpdateService.d.ts +9 -0
- package/dist/libs/crud-pro/services/CrudProFieldUpdateService.js +51 -0
- package/dist/libs/crud-pro/services/CrudProFieldValidateService.d.ts +13 -0
- package/dist/libs/crud-pro/services/CrudProFieldValidateService.js +148 -0
- package/dist/libs/crud-pro/services/CrudProGenSqlCondition.d.ts +24 -0
- package/dist/libs/crud-pro/services/CrudProGenSqlCondition.js +342 -0
- package/dist/libs/crud-pro/services/CrudProGenSqlService.d.ts +25 -0
- package/dist/libs/crud-pro/services/CrudProGenSqlService.js +174 -0
- package/dist/libs/crud-pro/services/CrudProOriginToExecuteSql.d.ts +32 -0
- package/dist/libs/crud-pro/services/CrudProOriginToExecuteSql.js +333 -0
- package/dist/libs/crud-pro/services/CrudProServiceBase.d.ts +28 -0
- package/dist/libs/crud-pro/services/CrudProServiceBase.js +78 -0
- package/dist/libs/crud-pro/services/CrudProTableMetaService.d.ts +8 -0
- package/dist/libs/crud-pro/services/CrudProTableMetaService.js +53 -0
- package/dist/libs/crud-pro/services/CurdProServiceHub.d.ts +32 -0
- package/dist/libs/crud-pro/services/CurdProServiceHub.js +64 -0
- package/dist/libs/crud-pro/sql.txt +120 -0
- package/dist/libs/crud-pro/utils/CompareUtils.d.ts +9 -0
- package/dist/libs/crud-pro/utils/CompareUtils.js +25 -0
- package/dist/libs/crud-pro/utils/DatabaseName.d.ts +9 -0
- package/dist/libs/crud-pro/utils/DatabaseName.js +29 -0
- package/dist/libs/crud-pro/utils/DateTimeUtils.d.ts +7 -0
- package/dist/libs/crud-pro/utils/DateTimeUtils.js +21 -0
- package/dist/libs/crud-pro/utils/MemoryRefreshCache.d.ts +19 -0
- package/dist/libs/crud-pro/utils/MemoryRefreshCache.js +47 -0
- package/dist/libs/crud-pro/utils/MessageParseUtils.d.ts +5 -0
- package/dist/libs/crud-pro/utils/MessageParseUtils.js +33 -0
- package/dist/libs/crud-pro/utils/MixinUtils.d.ts +39 -0
- package/dist/libs/crud-pro/utils/MixinUtils.js +255 -0
- package/dist/libs/crud-pro/utils/ModelUtils.d.ts +11 -0
- package/dist/libs/crud-pro/utils/ModelUtils.js +49 -0
- package/dist/libs/crud-pro/utils/MultiKeyMap.d.ts +11 -0
- package/dist/libs/crud-pro/utils/MultiKeyMap.js +63 -0
- package/dist/libs/crud-pro/utils/SqlFuncUtils.d.ts +5 -0
- package/dist/libs/crud-pro/utils/SqlFuncUtils.js +29 -0
- package/dist/libs/crud-pro/utils/TypeUtils.d.ts +40 -0
- package/dist/libs/crud-pro/utils/TypeUtils.js +166 -0
- package/dist/libs/crud-pro/utils/ValidateUtils.d.ts +3 -0
- package/dist/libs/crud-pro/utils/ValidateUtils.js +165 -0
- package/dist/libs/crud-pro/utils/pool/MySQLUtils.d.ts +3 -0
- package/dist/libs/crud-pro/utils/pool/MySQLUtils.js +19 -0
- package/dist/libs/crud-pro/utils/pool/PostgresUtils.d.ts +3 -0
- package/dist/libs/crud-pro/utils/pool/PostgresUtils.js +20 -0
- package/dist/libs/crud-pro/utils/pool/SqlServerUtils.d.ts +3 -0
- package/dist/libs/crud-pro/utils/pool/SqlServerUtils.js +20 -0
- package/dist/libs/crud-pro/utils/sqlConvert/convertColumnName.d.ts +4 -0
- package/dist/libs/crud-pro/utils/sqlConvert/convertColumnName.js +21 -0
- package/dist/libs/crud-pro/utils/sqlConvert/convertMsSql.d.ts +2 -0
- package/dist/libs/crud-pro/utils/sqlConvert/convertMsSql.js +11 -0
- package/dist/libs/crud-pro/utils/sqlConvert/convertPgSql.d.ts +2 -0
- package/dist/libs/crud-pro/utils/sqlConvert/convertPgSql.js +11 -0
- package/dist/libs/crud-pro/utils/sqlConvert/convertPgType.d.ts +2 -0
- package/dist/libs/crud-pro/utils/sqlConvert/convertPgType.js +128 -0
- package/dist/libs/utils/common-dto.d.ts +18 -0
- package/dist/libs/utils/common-dto.js +40 -0
- package/dist/libs/utils/crypto-utils.d.ts +3 -0
- package/dist/libs/utils/crypto-utils.js +46 -0
- package/dist/libs/utils/fatcms-request.d.ts +30 -0
- package/dist/libs/utils/fatcms-request.js +104 -0
- package/dist/libs/utils/functions.d.ts +4 -0
- package/dist/libs/utils/functions.js +63 -0
- package/dist/libs/utils/ordernum-utils.d.ts +2 -0
- package/dist/libs/utils/ordernum-utils.js +13 -0
- package/dist/libs/utils/parseConfig.d.ts +7 -0
- package/dist/libs/utils/parseConfig.js +44 -0
- package/dist/libs/utils/parseCreateSql.d.ts +5 -0
- package/dist/libs/utils/parseCreateSql.js +86 -0
- package/dist/libs/utils/render-utils.d.ts +28 -0
- package/dist/libs/utils/render-utils.js +135 -0
- package/dist/middleware/forbidden.middleware.d.ts +10 -0
- package/dist/middleware/forbidden.middleware.js +70 -0
- package/dist/middleware/global.middleware.d.ts +10 -0
- package/dist/middleware/global.middleware.js +246 -0
- package/dist/middleware/permission.middleware.d.ts +18 -0
- package/dist/middleware/permission.middleware.js +74 -0
- package/dist/middleware/tx.middleware.d.ts +9 -0
- package/dist/middleware/tx.middleware.js +40 -0
- package/dist/models/SystemEntities.d.ts +98 -0
- package/dist/models/SystemEntities.js +2 -0
- package/dist/models/SystemPerm.d.ts +95 -0
- package/dist/models/SystemPerm.js +100 -0
- package/dist/models/SystemTables.d.ts +27 -0
- package/dist/models/SystemTables.js +30 -0
- package/dist/models/bizmodels.d.ts +69 -0
- package/dist/models/bizmodels.js +34 -0
- package/dist/models/contextLogger.d.ts +25 -0
- package/dist/models/contextLogger.js +112 -0
- package/dist/models/devops.d.ts +12 -0
- package/dist/models/devops.js +19 -0
- package/dist/models/userSession.d.ts +61 -0
- package/dist/models/userSession.js +165 -0
- package/dist/schedule/index.d.ts +3 -0
- package/dist/schedule/index.js +69 -0
- package/dist/service/AuthService.d.ts +70 -0
- package/dist/service/AuthService.js +248 -0
- package/dist/service/EnumInfoService.d.ts +30 -0
- package/dist/service/EnumInfoService.js +123 -0
- package/dist/service/FileCenterService.d.ts +43 -0
- package/dist/service/FileCenterService.js +347 -0
- package/dist/service/SysConfigService.d.ts +7 -0
- package/dist/service/SysConfigService.js +45 -0
- package/dist/service/UserAccountService.d.ts +23 -0
- package/dist/service/UserAccountService.js +103 -0
- package/dist/service/UserSessionService.d.ts +16 -0
- package/dist/service/UserSessionService.js +85 -0
- package/dist/service/VisitStatService.d.ts +14 -0
- package/dist/service/VisitStatService.js +165 -0
- package/dist/service/WorkbenchService.d.ts +20 -0
- package/dist/service/WorkbenchService.js +153 -0
- package/dist/service/anyapi/AnyApiSandboxService.d.ts +15 -0
- package/dist/service/anyapi/AnyApiSandboxService.js +122 -0
- package/dist/service/anyapi/AnyApiService.d.ts +27 -0
- package/dist/service/anyapi/AnyApiService.js +179 -0
- package/dist/service/base/ApiBaseService.d.ts +15 -0
- package/dist/service/base/ApiBaseService.js +50 -0
- package/dist/service/base/ApiRateLimiter.d.ts +10 -0
- package/dist/service/base/ApiRateLimiter.js +51 -0
- package/dist/service/base/BaseService.d.ts +29 -0
- package/dist/service/base/BaseService.js +79 -0
- package/dist/service/base/RedisCacheService.d.ts +13 -0
- package/dist/service/base/RedisCacheService.js +50 -0
- package/dist/service/crudstd/CrudStdActionService.d.ts +17 -0
- package/dist/service/crudstd/CrudStdActionService.js +32 -0
- package/dist/service/crudstd/CrudStdConstant.d.ts +58 -0
- package/dist/service/crudstd/CrudStdConstant.js +64 -0
- package/dist/service/crudstd/CrudStdRelationService.d.ts +10 -0
- package/dist/service/crudstd/CrudStdRelationService.js +85 -0
- package/dist/service/crudstd/CrudStdService.d.ts +50 -0
- package/dist/service/crudstd/CrudStdService.js +182 -0
- package/dist/service/curd/CurdMixByAccountService.d.ts +9 -0
- package/dist/service/curd/CurdMixByAccountService.js +87 -0
- package/dist/service/curd/CurdMixByDictService.d.ts +13 -0
- package/dist/service/curd/CurdMixByDictService.js +111 -0
- package/dist/service/curd/CurdMixByLinkToCustomService.d.ts +22 -0
- package/dist/service/curd/CurdMixByLinkToCustomService.js +154 -0
- package/dist/service/curd/CurdMixBySysConfigService.d.ts +9 -0
- package/dist/service/curd/CurdMixBySysConfigService.js +78 -0
- package/dist/service/curd/CurdMixByWorkbenchService.d.ts +10 -0
- package/dist/service/curd/CurdMixByWorkbenchService.js +76 -0
- package/dist/service/curd/CurdMixService.d.ts +17 -0
- package/dist/service/curd/CurdMixService.js +76 -0
- package/dist/service/curd/CurdMixUtils.d.ts +28 -0
- package/dist/service/curd/CurdMixUtils.js +201 -0
- package/dist/service/curd/CurdProService.d.ts +39 -0
- package/dist/service/curd/CurdProService.js +322 -0
- package/dist/service/proxyapi/ProxyApiLoadService.d.ts +21 -0
- package/dist/service/proxyapi/ProxyApiLoadService.js +164 -0
- package/dist/service/proxyapi/ProxyApiService.d.ts +60 -0
- package/dist/service/proxyapi/ProxyApiService.js +260 -0
- package/dist/service/proxyapi/ProxyApiUtils.d.ts +15 -0
- package/dist/service/proxyapi/ProxyApiUtils.js +34 -0
- package/dist/service/proxyapi/RouteHandler.d.ts +5 -0
- package/dist/service/proxyapi/RouteHandler.js +9 -0
- package/dist/service/proxyapi/RouteTrie.d.ts +12 -0
- package/dist/service/proxyapi/RouteTrie.js +63 -0
- package/dist/service/proxyapi/WeightedRandom.d.ts +9 -0
- package/dist/service/proxyapi/WeightedRandom.js +31 -0
- package/dist/service/proxyapi/WeightedRoundRobin.d.ts +8 -0
- package/dist/service/proxyapi/WeightedRoundRobin.js +32 -0
- package/index.d.ts +10 -0
- package/package.json +71 -0
- package/src/config/config.default.ts +172 -0
- package/src/config/seed/aeskey.txt +1 -0
- package/src/config/utils.ts +23 -0
- package/src/configuration.ts +83 -0
- package/src/controller/base/BaseApiController.ts +145 -0
- package/src/controller/gateway/AnyApiGatewayController.ts +33 -0
- package/src/controller/gateway/CrudMtdGatewayController.ts +107 -0
- package/src/controller/gateway/CrudStdGatewayController.ts +101 -0
- package/src/controller/gateway/DocGatewayController.ts +165 -0
- package/src/controller/gateway/FileController.ts +110 -0
- package/src/controller/gateway/ProxyApiGatewayController.ts +47 -0
- package/src/controller/gateway/PublicApiController.ts +145 -0
- package/src/controller/gateway/StaticController.ts +303 -0
- package/src/controller/helpers.controller.ts +161 -0
- package/src/controller/home.controller.ts +71 -0
- package/src/controller/manage/AnyApiMangeApi.ts +66 -0
- package/src/controller/manage/AppLogMangeApi.ts +53 -0
- package/src/controller/manage/AppMangeApi.ts +53 -0
- package/src/controller/manage/AppPageMangeApi.ts +52 -0
- package/src/controller/manage/AppSchemaHistoryApi.ts +49 -0
- package/src/controller/manage/CrudMethodsMangeApi.ts +49 -0
- package/src/controller/manage/CrudStandardDesignApi.ts +353 -0
- package/src/controller/manage/DataDictManageApi.ts +78 -0
- package/src/controller/manage/DeployManageApi.ts +179 -0
- package/src/controller/manage/DocLibManageApi.ts +69 -0
- package/src/controller/manage/DocManageApi.ts +99 -0
- package/src/controller/manage/FileManageApi.ts +45 -0
- package/src/controller/manage/LowCodeTplManageApi.ts +52 -0
- package/src/controller/manage/MenuManageApi.ts +63 -0
- package/src/controller/manage/ProxyApiMangeApi.ts +52 -0
- package/src/controller/manage/SuperAdminManageApi.ts +138 -0
- package/src/controller/manage/SysConfigMangeApi.ts +95 -0
- package/src/controller/manage/SystemInfoManageApi.ts +48 -0
- package/src/controller/manage/UserAccountManageApi.ts +88 -0
- package/src/controller/manage/WorkbenchMangeApi.ts +72 -0
- package/src/controller/medstatistic/MedAdminController.ts +221 -0
- package/src/controller/medstatistic/MedClientController.ts +188 -0
- package/src/controller/medstatistic/MedMessageService.ts +89 -0
- package/src/controller/medstatistic/MedScoreService.ts +108 -0
- package/src/controller/medstatistic/constants.ts +63 -0
- package/src/controller/myinfo/AuthController.ts +174 -0
- package/src/controller/myinfo/MyInfoController.ts +32 -0
- package/src/controller/render/AppRenderController.ts +76 -0
- package/src/controller/test.controller.ts +37 -0
- package/src/filter/default.filter.ts +13 -0
- package/src/filter/notfound.filter.ts +10 -0
- package/src/index.ts +70 -0
- package/src/interface.ts +31 -0
- package/src/libs/crud-pro/CrudPro.ts +158 -0
- package/src/libs/crud-pro/defaultConfigs.ts +13 -0
- package/src/libs/crud-pro/exceptions.ts +124 -0
- package/src/libs/crud-pro/interfaces.ts +183 -0
- package/src/libs/crud-pro/models/ExecuteContext.ts +111 -0
- package/src/libs/crud-pro/models/ExecuteContextFunc.ts +86 -0
- package/src/libs/crud-pro/models/FuncContext.ts +21 -0
- package/src/libs/crud-pro/models/RequestCfgModel.ts +141 -0
- package/src/libs/crud-pro/models/RequestModel.ts +141 -0
- package/src/libs/crud-pro/models/ServiceHub.ts +32 -0
- package/src/libs/crud-pro/models/SqlCfgModel.ts +52 -0
- package/src/libs/crud-pro/models/SqlSegArg.ts +13 -0
- package/src/libs/crud-pro/models/Transaction.ts +74 -0
- package/src/libs/crud-pro/models/TransactionMySQL.ts +79 -0
- package/src/libs/crud-pro/models/TransactionPostgres.ts +91 -0
- package/src/libs/crud-pro/models/TransactionSqlServer.ts +107 -0
- package/src/libs/crud-pro/models/keys.ts +159 -0
- package/src/libs/crud-pro/services/CrudProCachedCfgService.ts +75 -0
- package/src/libs/crud-pro/services/CrudProExecuteFuncService.ts +128 -0
- package/src/libs/crud-pro/services/CrudProExecuteSqlService.ts +279 -0
- package/src/libs/crud-pro/services/CrudProFieldUpdateService.ts +60 -0
- package/src/libs/crud-pro/services/CrudProFieldValidateService.ts +180 -0
- package/src/libs/crud-pro/services/CrudProGenSqlCondition.ts +373 -0
- package/src/libs/crud-pro/services/CrudProGenSqlService.ts +202 -0
- package/src/libs/crud-pro/services/CrudProOriginToExecuteSql.ts +397 -0
- package/src/libs/crud-pro/services/CrudProServiceBase.ts +98 -0
- package/src/libs/crud-pro/services/CrudProTableMetaService.ts +59 -0
- package/src/libs/crud-pro/services/CurdProServiceHub.ts +92 -0
- package/src/libs/crud-pro/sql.txt +120 -0
- package/src/libs/crud-pro/utils/CompareUtils.ts +23 -0
- package/src/libs/crud-pro/utils/DatabaseName.ts +40 -0
- package/src/libs/crud-pro/utils/DateTimeUtils.ts +20 -0
- package/src/libs/crud-pro/utils/MemoryRefreshCache.ts +64 -0
- package/src/libs/crud-pro/utils/MessageParseUtils.ts +33 -0
- package/src/libs/crud-pro/utils/MixinUtils.ts +285 -0
- package/src/libs/crud-pro/utils/ModelUtils.ts +55 -0
- package/src/libs/crud-pro/utils/MultiKeyMap.ts +72 -0
- package/src/libs/crud-pro/utils/SqlFuncUtils.ts +29 -0
- package/src/libs/crud-pro/utils/TypeUtils.ts +188 -0
- package/src/libs/crud-pro/utils/ValidateUtils.ts +167 -0
- package/src/libs/crud-pro/utils/pool/MySQLUtils.ts +20 -0
- package/src/libs/crud-pro/utils/pool/PostgresUtils.ts +22 -0
- package/src/libs/crud-pro/utils/pool/SqlServerUtils.ts +22 -0
- package/src/libs/crud-pro/utils/sqlConvert/convertColumnName.ts +26 -0
- package/src/libs/crud-pro/utils/sqlConvert/convertMsSql.ts +11 -0
- package/src/libs/crud-pro/utils/sqlConvert/convertPgSql.ts +11 -0
- package/src/libs/crud-pro/utils/sqlConvert/convertPgType.ts +129 -0
- package/src/libs/utils/common-dto.ts +52 -0
- package/src/libs/utils/crypto-utils.ts +52 -0
- package/src/libs/utils/fatcms-request.ts +115 -0
- package/src/libs/utils/functions.ts +67 -0
- package/src/libs/utils/ordernum-utils.ts +18 -0
- package/src/libs/utils/parseConfig.ts +62 -0
- package/src/libs/utils/parseCreateSql.ts +91 -0
- package/src/libs/utils/render-utils.ts +184 -0
- package/src/middleware/forbidden.middleware.ts +71 -0
- package/src/middleware/global.middleware.ts +278 -0
- package/src/middleware/permission.middleware.ts +81 -0
- package/src/middleware/tx.middleware.ts +30 -0
- package/src/models/SystemEntities.ts +115 -0
- package/src/models/SystemPerm.ts +105 -0
- package/src/models/SystemTables.ts +30 -0
- package/src/models/bizmodels.ts +89 -0
- package/src/models/contextLogger.ts +132 -0
- package/src/models/devops.ts +17 -0
- package/src/models/userSession.ts +216 -0
- package/src/schedule/index.ts +73 -0
- package/src/service/AuthService.ts +270 -0
- package/src/service/EnumInfoService.ts +129 -0
- package/src/service/FileCenterService.ts +394 -0
- package/src/service/SysConfigService.ts +34 -0
- package/src/service/UserAccountService.ts +100 -0
- package/src/service/UserSessionService.ts +81 -0
- package/src/service/VisitStatService.ts +179 -0
- package/src/service/WorkbenchService.ts +160 -0
- package/src/service/anyapi/AnyApiSandboxService.ts +121 -0
- package/src/service/anyapi/AnyApiService.ts +184 -0
- package/src/service/base/ApiBaseService.ts +42 -0
- package/src/service/base/ApiRateLimiter.ts +59 -0
- package/src/service/base/BaseService.ts +74 -0
- package/src/service/base/RedisCacheService.ts +38 -0
- package/src/service/crudstd/CrudStdActionService.ts +27 -0
- package/src/service/crudstd/CrudStdConstant.ts +62 -0
- package/src/service/crudstd/CrudStdRelationService.ts +78 -0
- package/src/service/crudstd/CrudStdService.ts +188 -0
- package/src/service/curd/CurdMixByAccountService.ts +83 -0
- package/src/service/curd/CurdMixByDictService.ts +113 -0
- package/src/service/curd/CurdMixByLinkToCustomService.ts +167 -0
- package/src/service/curd/CurdMixBySysConfigService.ts +78 -0
- package/src/service/curd/CurdMixByWorkbenchService.ts +68 -0
- package/src/service/curd/CurdMixService.ts +65 -0
- package/src/service/curd/CurdMixUtils.ts +248 -0
- package/src/service/curd/CurdProService.ts +379 -0
- package/src/service/proxyapi/ProxyApiLoadService.ts +165 -0
- package/src/service/proxyapi/ProxyApiService.ts +262 -0
- package/src/service/proxyapi/ProxyApiUtils.ts +32 -0
- package/src/service/proxyapi/RouteHandler.ts +8 -0
- package/src/service/proxyapi/RouteTrie.ts +74 -0
- package/src/service/proxyapi/WeightedRandom.ts +37 -0
- package/src/service/proxyapi/WeightedRoundRobin.ts +44 -0
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
import {Inject, Provide} from '@midwayjs/core';
|
|
2
|
+
import {Context} from '@midwayjs/koa';
|
|
3
|
+
import {IScheduleService} from '../interface';
|
|
4
|
+
import {BaseService} from "./base/BaseService";
|
|
5
|
+
import {CurdProService} from "./curd/CurdProService";
|
|
6
|
+
import {SystemDbName, SystemDbType, SystemTables} from "../models/SystemTables";
|
|
7
|
+
import {KeysOfSimpleSQL} from "../libs/crud-pro/models/keys";
|
|
8
|
+
import {FILE_GET_TYPES} from "../models/bizmodels";
|
|
9
|
+
import {CommonResult} from "../libs/utils/common-dto";
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
// 3天 的秒数
|
|
13
|
+
const EXPIRE_TIME = 3 * 24 * 60 * 60;
|
|
14
|
+
|
|
15
|
+
const STAT_TYPES = {
|
|
16
|
+
pv: 'pv',
|
|
17
|
+
uv_ip: 'uv_ip',
|
|
18
|
+
uv_uid: 'uv_uid',
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
@Provide()
|
|
23
|
+
export class VisitStatService extends BaseService implements IScheduleService {
|
|
24
|
+
@Inject()
|
|
25
|
+
protected ctx: Context;
|
|
26
|
+
|
|
27
|
+
@Inject()
|
|
28
|
+
private curdProService: CurdProService;
|
|
29
|
+
|
|
30
|
+
async runBySchedule(): Promise<any> {
|
|
31
|
+
const hours = new Date().getHours();
|
|
32
|
+
this.logInfo("[VisitStatService] runBySchedule called, hours = " + hours);
|
|
33
|
+
return this.flushVisitStatToDB();
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
async flushVisitStatToDB(): Promise<any> {
|
|
38
|
+
// 统计昨天的数据。
|
|
39
|
+
const stat_date = new Date(Date.now() - 24 * 3600 * 1000).toISOString().split('T')[0];
|
|
40
|
+
|
|
41
|
+
const lockKey = `vs_lock_${stat_date}`;
|
|
42
|
+
// 每天只能执行一次
|
|
43
|
+
const client = this.redisService;
|
|
44
|
+
const nxRes = await client.set(lockKey, 1, 'EX', EXPIRE_TIME, 'NX')
|
|
45
|
+
if (nxRes !== 'OK') {
|
|
46
|
+
this.logInfo("[VisitStatService] flushVisitStatToDB 每天只能执行一次 ");
|
|
47
|
+
return CommonResult.errorRes("每天只能执行一次")
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
this.logInfo("[VisitStatService] flushVisitStatToDB start ");
|
|
51
|
+
|
|
52
|
+
let totalCount = 0 ;
|
|
53
|
+
let successCount = 0;
|
|
54
|
+
|
|
55
|
+
try {
|
|
56
|
+
|
|
57
|
+
const keys = await client.keys(`vs_${stat_date}::*`);
|
|
58
|
+
// `vs_${date}::${req_host}::${resource_type}::${stat_type}::${resource}`;
|
|
59
|
+
totalCount = keys.length;
|
|
60
|
+
|
|
61
|
+
for (const key of keys) {
|
|
62
|
+
try {
|
|
63
|
+
const parts = key.split('::');
|
|
64
|
+
if (parts.length === 5) {
|
|
65
|
+
const req_host = parts[1];
|
|
66
|
+
const resource_type = parts[2];
|
|
67
|
+
const stat_type = parts[3];
|
|
68
|
+
const stat_resource = parts[4];
|
|
69
|
+
|
|
70
|
+
let stat_count: number;
|
|
71
|
+
if (stat_type === STAT_TYPES.uv_ip || stat_type == STAT_TYPES.uv_uid) {
|
|
72
|
+
stat_count = await client.scard(key);
|
|
73
|
+
} else {
|
|
74
|
+
stat_count = parseInt(await client.get(key)) || 0;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
await this.curdProService.executeCrudByCfg({
|
|
78
|
+
data: {
|
|
79
|
+
stat_date,
|
|
80
|
+
stat_resource,
|
|
81
|
+
stat_type,
|
|
82
|
+
resource_type,
|
|
83
|
+
stat_count,
|
|
84
|
+
req_host
|
|
85
|
+
}
|
|
86
|
+
}, {
|
|
87
|
+
sqlSimpleName: KeysOfSimpleSQL.SIMPLE_INSERT,
|
|
88
|
+
sqlDatabase: SystemDbName,
|
|
89
|
+
sqlDdType: SystemDbType,
|
|
90
|
+
sqlTable: SystemTables.sys_visit_stats,
|
|
91
|
+
})
|
|
92
|
+
|
|
93
|
+
await client.del(key);
|
|
94
|
+
successCount++;
|
|
95
|
+
}
|
|
96
|
+
} catch (e){
|
|
97
|
+
this.logError('[VisitStatService] flushVisitStatToDB: key = ' + key, e);
|
|
98
|
+
console.log('[VisitStatService] flushVisitStatToDB: key = ' + key, e);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
} catch (error) {
|
|
102
|
+
this.logError('[VisitStatService] flushVisitStatToDB' , error);
|
|
103
|
+
console.log('[VisitStatService] flushVisitStatToDB' , error);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
this.logInfo("[VisitStatService] flushVisitStatToDB end ");
|
|
107
|
+
|
|
108
|
+
return CommonResult.successRes({successCount, totalCount})
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* 统计请求数据
|
|
114
|
+
*/
|
|
115
|
+
async trackRequest(resource: string, resourceType: string) {
|
|
116
|
+
|
|
117
|
+
// 文件下载定制
|
|
118
|
+
if (resource.startsWith('/ns/gw/file/get/')) {
|
|
119
|
+
for (let i = 0; i < FILE_GET_TYPES.length; i++) {
|
|
120
|
+
const fileGetType = FILE_GET_TYPES[i];
|
|
121
|
+
const pathPrefix = `/ns/gw/file/get/${fileGetType}/`
|
|
122
|
+
if (resource.startsWith(pathPrefix)) {
|
|
123
|
+
const res2 = resource.substring(pathPrefix.length);
|
|
124
|
+
return this.trackRequestImpl(res2, fileGetType)
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
// 文档访问定制
|
|
130
|
+
if (resource.startsWith('/ns/app/doc-editor/libview')) {
|
|
131
|
+
const {docLibId,docId} = this.ctx.query || {};
|
|
132
|
+
return this.trackRequestImpl(`${docLibId},${docId}`, 'docLibView')
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
|
|
136
|
+
return this.trackRequestImpl(resource, resourceType)
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
private async trackRequestImpl(resource: string, resource_type: string) {
|
|
141
|
+
const client = this.redisService;
|
|
142
|
+
const ip = this.ctx.headers['x-real-ip'];
|
|
143
|
+
const userSession = this.ctx.userSession
|
|
144
|
+
const req_host = this.ctx?.request?.host || "null" // 域名
|
|
145
|
+
const date = new Date().toISOString().split('T')[0];
|
|
146
|
+
|
|
147
|
+
const toDateResourceKey = (stat_type: string): string => {
|
|
148
|
+
return `vs_${date}::${req_host}::${resource_type}::${stat_type}::${resource}`;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
const pv_key = toDateResourceKey(STAT_TYPES.pv);
|
|
152
|
+
const uv_ip_key = toDateResourceKey(STAT_TYPES.uv_ip);
|
|
153
|
+
const uv_uid_key = toDateResourceKey(STAT_TYPES.uv_uid);
|
|
154
|
+
|
|
155
|
+
|
|
156
|
+
// 统计 PV
|
|
157
|
+
await Promise.all([
|
|
158
|
+
client.incr(pv_key),
|
|
159
|
+
client.expire(pv_key, EXPIRE_TIME)
|
|
160
|
+
]);
|
|
161
|
+
|
|
162
|
+
// IP 访问 UV
|
|
163
|
+
await Promise.all([
|
|
164
|
+
client.sadd(uv_ip_key, `${ip}`),
|
|
165
|
+
client.expire(uv_ip_key, EXPIRE_TIME)
|
|
166
|
+
]);
|
|
167
|
+
|
|
168
|
+
if (userSession && userSession.isLogin()) {
|
|
169
|
+
const accountId = userSession.getSessionInfo().accountId;
|
|
170
|
+
// 统计 UV
|
|
171
|
+
await Promise.all([
|
|
172
|
+
client.sadd(uv_uid_key, accountId),
|
|
173
|
+
client.expire(uv_uid_key, EXPIRE_TIME)
|
|
174
|
+
]);
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
};
|
|
178
|
+
|
|
179
|
+
}
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
import { Inject, Provide } from '@midwayjs/core';
|
|
2
|
+
import { Context } from '@midwayjs/koa';
|
|
3
|
+
import { KeysOfSimpleSQL } from '../libs/crud-pro/models/keys';
|
|
4
|
+
import {SystemDbName, SystemDbType, SystemTables} from '../models/SystemTables';
|
|
5
|
+
import { BaseService } from './base/BaseService';
|
|
6
|
+
// import { LRUCache } from 'lru-cache';
|
|
7
|
+
import { CurdProService } from './curd/CurdProService';
|
|
8
|
+
import { CommonException } from '../libs/crud-pro/exceptions';
|
|
9
|
+
import { parseJsonObject } from '../libs/utils/functions';
|
|
10
|
+
import { IWorkbenchEntity } from '../models/SystemEntities';
|
|
11
|
+
import { IScheduleService } from '../interface';
|
|
12
|
+
import { getDebugWorkbenchCode } from '../libs/utils/fatcms-request';
|
|
13
|
+
import { MixinUtils } from '../libs/crud-pro/utils/MixinUtils';
|
|
14
|
+
//
|
|
15
|
+
// const lruCache = new LRUCache<string, any>({
|
|
16
|
+
// max: 500,
|
|
17
|
+
// ttl: 1000 * 60 * 60,
|
|
18
|
+
// ttlAutopurge: true,
|
|
19
|
+
// });
|
|
20
|
+
|
|
21
|
+
const lruCache = new Map<string, any>();
|
|
22
|
+
|
|
23
|
+
const CACHE_KEY_WORKBENCH_LIST = 'CACHE_KEY_WORKBENCH_LIST';
|
|
24
|
+
const CACHE_KEY_DOMAIN_MAP = 'CACHE_KEY_DOMAIN_MAP';
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
@Provide()
|
|
28
|
+
export class WorkbenchService extends BaseService implements IScheduleService {
|
|
29
|
+
@Inject()
|
|
30
|
+
ctx: Context;
|
|
31
|
+
|
|
32
|
+
@Inject()
|
|
33
|
+
private curdProService: CurdProService;
|
|
34
|
+
|
|
35
|
+
public clearCache() {
|
|
36
|
+
lruCache.set(CACHE_KEY_WORKBENCH_LIST, null);
|
|
37
|
+
lruCache.set(CACHE_KEY_DOMAIN_MAP, null);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
public async runBySchedule() {
|
|
41
|
+
await this.getAllWorkbenchInfoMap(true);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
public async getAllWorkbenchInfoList(isForceRefresh?: boolean): Promise<IWorkbenchEntity[]> {
|
|
45
|
+
let listData = lruCache.get(CACHE_KEY_WORKBENCH_LIST);
|
|
46
|
+
if (!listData || isForceRefresh === true) {
|
|
47
|
+
const reqJson = { condition: {}, pageSize: 1000, limit: 1000 };
|
|
48
|
+
const res = await this.curdProService.executeCrudByCfg(reqJson, {
|
|
49
|
+
sqlTable: SystemTables.sys_workbench,
|
|
50
|
+
sqlSimpleName: KeysOfSimpleSQL.SIMPLE_QUERY,
|
|
51
|
+
sqlDatabase: SystemDbName,
|
|
52
|
+
sqlDdType: SystemDbType,
|
|
53
|
+
});
|
|
54
|
+
listData = res.getResRows();
|
|
55
|
+
lruCache.set(CACHE_KEY_WORKBENCH_LIST, listData);
|
|
56
|
+
}
|
|
57
|
+
return listData;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
public async getAllWorkbenchInfoMap(isForceRefresh?: boolean): Promise<Record<any, IWorkbenchEntity>> {
|
|
61
|
+
let listData: any[];
|
|
62
|
+
let domainMap = lruCache.get(CACHE_KEY_DOMAIN_MAP);
|
|
63
|
+
if (!domainMap || isForceRefresh === true) {
|
|
64
|
+
listData = await this.getAllWorkbenchInfoList(isForceRefresh);
|
|
65
|
+
const domainMap1 = MixinUtils.toMap(listData, (e: any) => e.workbench_domain); // 主域名。其他两个域名。
|
|
66
|
+
const domainMap2 = MixinUtils.toMap(listData, (e: any) => e.workbench_domain2);
|
|
67
|
+
const domainMap3 = MixinUtils.toMap(listData, (e: any) => e.workbench_domain3);
|
|
68
|
+
domainMap = {...domainMap1, ...domainMap2, ...domainMap3};
|
|
69
|
+
lruCache.set(CACHE_KEY_DOMAIN_MAP, domainMap);
|
|
70
|
+
}
|
|
71
|
+
return domainMap;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
public isMatchWorkbenchCode(workbench_code_array: string | string[], workbench_code: string): boolean {
|
|
75
|
+
if (workbench_code_array === '*') {
|
|
76
|
+
return true;
|
|
77
|
+
}
|
|
78
|
+
const supportWorkbenchArray = parseJsonObject(workbench_code_array)
|
|
79
|
+
.map(s => s.trim())
|
|
80
|
+
.filter(Boolean);
|
|
81
|
+
|
|
82
|
+
return supportWorkbenchArray.includes('*') || supportWorkbenchArray.includes(workbench_code);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* 获取当前请求的域名所对应的站点信息
|
|
87
|
+
*/
|
|
88
|
+
public async getCurrentHostWorkbenchInfo(): Promise<IWorkbenchEntity> {
|
|
89
|
+
// 本地调试模式
|
|
90
|
+
if (this.isEnableDebug() && this.isLocalEnv()) {
|
|
91
|
+
const debugWorkbenchCode = getDebugWorkbenchCode(this.ctx);
|
|
92
|
+
if (!debugWorkbenchCode) {
|
|
93
|
+
throw new CommonException('本地环境调试时需要使用ModHeader浏览器插件,指定站点编码');
|
|
94
|
+
}
|
|
95
|
+
const list = await this.getAllWorkbenchInfoList();
|
|
96
|
+
for (let i = 0; i < list.length; i++) {
|
|
97
|
+
const workbenchInfo = list[i];
|
|
98
|
+
if (workbenchInfo.workbench_code === debugWorkbenchCode) {
|
|
99
|
+
return workbenchInfo;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
return null;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
//正式环境: 根据域名获取站点配置
|
|
106
|
+
const host = this.getCurrentHost();
|
|
107
|
+
const domainMap = await this.getAllWorkbenchInfoMap();
|
|
108
|
+
return domainMap[host];
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
private getCurrentHost(): string {
|
|
112
|
+
const host = this.ctx.request.host;
|
|
113
|
+
if (!host) {
|
|
114
|
+
throw new CommonException('GET_CURRENT_HOST_ERROR','获取当前域名失败');
|
|
115
|
+
}
|
|
116
|
+
return host;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
public async isSupportCurrentWorkbench(workbench_code_array: string | string[]): Promise<boolean> {
|
|
121
|
+
// 本地调试模式
|
|
122
|
+
if (this.isEnableDebug() && this.isLocalEnv()) {
|
|
123
|
+
return true;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
if (!workbench_code_array) {
|
|
127
|
+
throw new CommonException('IS_SUPPORT_CURRENT_WORKBENCH', '未配置支持的站点字段');
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
const workbench = await this.getCurrentHostWorkbenchInfo();
|
|
131
|
+
if (!workbench) {
|
|
132
|
+
throw new CommonException('WORKBENCH_IS_NOT_FOUND', '站点未找到');
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
const curWorkbenchCode = workbench.workbench_code;
|
|
136
|
+
return this.isMatchWorkbenchCode(workbench_code_array, curWorkbenchCode);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
public async isSupportCurrentHostForForMiddleware(): Promise<string | boolean> {
|
|
140
|
+
// 本地调试模式
|
|
141
|
+
if (this.isEnableDebug() && this.isLocalEnv()) {
|
|
142
|
+
return true;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
const host = this.getCurrentHost();
|
|
146
|
+
|
|
147
|
+
const workbenchInfo = await this.getCurrentHostWorkbenchInfo();
|
|
148
|
+
|
|
149
|
+
if (!workbenchInfo || workbenchInfo.status !== 1) {
|
|
150
|
+
this.logInfo(`域名不存在 host=${host}`);
|
|
151
|
+
const infos = {
|
|
152
|
+
host,
|
|
153
|
+
errorInfo: `ERR_FATCMS_REFUSED <br/> 域名配置不存在 host=${host}`,
|
|
154
|
+
};
|
|
155
|
+
this.ctx.status = 404;
|
|
156
|
+
return this.ctx.render('404_workbench', infos);
|
|
157
|
+
}
|
|
158
|
+
return true;
|
|
159
|
+
}
|
|
160
|
+
}
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import { Inject, Provide } from '@midwayjs/core';
|
|
2
|
+
import { Context } from '@midwayjs/koa';
|
|
3
|
+
import * as vm from 'node:vm';
|
|
4
|
+
import { LRUCache } from 'lru-cache';
|
|
5
|
+
import { BaseService } from '../base/BaseService';
|
|
6
|
+
import { CurdMixService } from '../curd/CurdMixService';
|
|
7
|
+
import { ISysAnyApiEntity } from '../../models/SystemEntities';
|
|
8
|
+
import axios from 'axios';
|
|
9
|
+
import * as _ from 'lodash';
|
|
10
|
+
import * as moment from 'moment';
|
|
11
|
+
import * as nodemailer from 'nodemailer';
|
|
12
|
+
|
|
13
|
+
const scriptCacheOptions = {
|
|
14
|
+
max: 500,
|
|
15
|
+
ttl: 1000 * 60 * 5,
|
|
16
|
+
allowStale: false,
|
|
17
|
+
updateAgeOnGet: true,
|
|
18
|
+
updateAgeOnHas: true,
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
const scriptCache = new LRUCache<string, vm.Script>(scriptCacheOptions);
|
|
22
|
+
|
|
23
|
+
function getCompiledScript(anyApi: ISysAnyApiEntity, code: string): vm.Script {
|
|
24
|
+
const { id, func_code_md5 } = anyApi;
|
|
25
|
+
const cacheKey = id + '_' + func_code_md5;
|
|
26
|
+
const oldScript = scriptCache.get(cacheKey);
|
|
27
|
+
if (oldScript) {
|
|
28
|
+
return oldScript;
|
|
29
|
+
}
|
|
30
|
+
const script = new vm.Script(code);
|
|
31
|
+
scriptCache.set(cacheKey, script);
|
|
32
|
+
return script;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export interface IRunInSandboxParams {
|
|
36
|
+
body: any;
|
|
37
|
+
query: any;
|
|
38
|
+
headers: any;
|
|
39
|
+
params?: any;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
@Provide()
|
|
43
|
+
export class AnyApiSandboxService extends BaseService {
|
|
44
|
+
@Inject()
|
|
45
|
+
protected ctx: Context;
|
|
46
|
+
|
|
47
|
+
@Inject()
|
|
48
|
+
private curdMixService: CurdMixService;
|
|
49
|
+
|
|
50
|
+
public async runInSandbox(anyApi: ISysAnyApiEntity, allParams: IRunInSandboxParams) {
|
|
51
|
+
const { func_code, method } = anyApi;
|
|
52
|
+
|
|
53
|
+
return new Promise((resolve, reject) => {
|
|
54
|
+
const logger = this.getPrefixContextLogger(`[AnyApiSandboxService][method=${method}]`);
|
|
55
|
+
// 创建一个沙盒上下文
|
|
56
|
+
const proc = process;
|
|
57
|
+
const newContext = {
|
|
58
|
+
sandbox: {
|
|
59
|
+
allParams,
|
|
60
|
+
logger,
|
|
61
|
+
moment,
|
|
62
|
+
axios,
|
|
63
|
+
nodemailer,
|
|
64
|
+
_,
|
|
65
|
+
userSession: this.ctx.userSession,
|
|
66
|
+
ctx: this.ctx,
|
|
67
|
+
curdMixService: this.curdMixService,
|
|
68
|
+
redisService: this.redisService,
|
|
69
|
+
publicOSSService: this.getPublicOSSService(),
|
|
70
|
+
privateOSSService: this.getPrivateOSSService(),
|
|
71
|
+
returnSuccess: resolve,
|
|
72
|
+
returnError: reject,
|
|
73
|
+
processInfo: {
|
|
74
|
+
version: proc.version,
|
|
75
|
+
versions: proc.versions,
|
|
76
|
+
env: process.env,
|
|
77
|
+
argv: process.argv,
|
|
78
|
+
cwd: process.cwd(),
|
|
79
|
+
},
|
|
80
|
+
},
|
|
81
|
+
console: logger,
|
|
82
|
+
JSON: JSON,
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
const nextLine100 = new Array(10).fill('\n').join('');
|
|
86
|
+
const bindCode = this.toBindCodeString('httpController', newContext, 'sandbox');
|
|
87
|
+
const code = `
|
|
88
|
+
(async () => {
|
|
89
|
+
${nextLine100}${func_code}; // 必须有一个 class HttpController { async handleRequest(params){} }
|
|
90
|
+
${nextLine100}
|
|
91
|
+
try {
|
|
92
|
+
const httpController = new HttpController();
|
|
93
|
+
${bindCode}
|
|
94
|
+
const res = await httpController.handleRequest(sandbox.allParams.params);
|
|
95
|
+
sandbox.returnSuccess(res);
|
|
96
|
+
} catch (e) {
|
|
97
|
+
sandbox.returnError(e)
|
|
98
|
+
}
|
|
99
|
+
})(); `;
|
|
100
|
+
|
|
101
|
+
try {
|
|
102
|
+
const script = getCompiledScript(anyApi, code);
|
|
103
|
+
script.runInNewContext(newContext, {
|
|
104
|
+
filename: 'method',
|
|
105
|
+
timeout: anyApi.timeout_ms || 1000 * 60 * 5,
|
|
106
|
+
});
|
|
107
|
+
} catch (e) {
|
|
108
|
+
reject(e);
|
|
109
|
+
}
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
private toBindCodeString(toName: string, newContext: any, fromName: any): string {
|
|
114
|
+
const keys = Object.keys(newContext[fromName]);
|
|
115
|
+
return keys
|
|
116
|
+
.map(key => {
|
|
117
|
+
return `${toName}.${key} = ${fromName}.${key};\n`;
|
|
118
|
+
})
|
|
119
|
+
.join('');
|
|
120
|
+
}
|
|
121
|
+
}
|
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
import { Inject, Provide } from '@midwayjs/core';
|
|
2
|
+
import { Context } from '@midwayjs/koa';
|
|
3
|
+
import { KeysOfSimpleSQL } from '../../libs/crud-pro/models/keys';
|
|
4
|
+
import {SystemDbName, SystemDbType, SystemTables} from '../../models/SystemTables';
|
|
5
|
+
import { LRUCache } from 'lru-cache';
|
|
6
|
+
import { BizException } from '../../models/devops';
|
|
7
|
+
import { CurdMixService } from '../curd/CurdMixService';
|
|
8
|
+
import { ISysAnyApiEntity } from '../../models/SystemEntities';
|
|
9
|
+
import { AnyApiSandboxService, IRunInSandboxParams } from './AnyApiSandboxService';
|
|
10
|
+
import { parseJsonObject } from '../../libs/utils/functions';
|
|
11
|
+
import * as _ from 'lodash';
|
|
12
|
+
import { MixinUtils } from '../../libs/crud-pro/utils/MixinUtils';
|
|
13
|
+
import { WorkbenchService } from '../WorkbenchService';
|
|
14
|
+
import { validateByCfgString } from '../../libs/crud-pro/utils/ValidateUtils';
|
|
15
|
+
import { API_BASE_TYPE, ApiBaseService } from '../base/ApiBaseService';
|
|
16
|
+
|
|
17
|
+
const lruCache = new LRUCache<string, any>({
|
|
18
|
+
max: 500,
|
|
19
|
+
ttl: 1000 * 60,
|
|
20
|
+
ttlAutopurge: true,
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
@Provide()
|
|
24
|
+
export class AnyApiService extends ApiBaseService {
|
|
25
|
+
@Inject()
|
|
26
|
+
protected ctx: Context;
|
|
27
|
+
|
|
28
|
+
@Inject()
|
|
29
|
+
private curdMixService: CurdMixService;
|
|
30
|
+
|
|
31
|
+
@Inject()
|
|
32
|
+
private anyApiSandboxService: AnyApiSandboxService;
|
|
33
|
+
|
|
34
|
+
@Inject()
|
|
35
|
+
protected workbenchService: WorkbenchService;
|
|
36
|
+
|
|
37
|
+
async executeAnyApiMethod(methodCode: string, headers: any, body: any, query: any) {
|
|
38
|
+
const anyApi = await this.getAnyApiMethod(methodCode);
|
|
39
|
+
if (!anyApi || anyApi.status !== 1) {
|
|
40
|
+
throw new BizException('接口不存在或已下线:' + methodCode);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const isSupport = await this.workbenchService.isSupportCurrentWorkbench(anyApi.workbench_code_array);
|
|
44
|
+
if (!isSupport) {
|
|
45
|
+
throw new BizException('此接口不支持在当前站点打开:' + methodCode);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
await super.beforeCheckApiAccessibility(API_BASE_TYPE.PROXY_API, anyApi);
|
|
49
|
+
|
|
50
|
+
if (!anyApi.func_code) {
|
|
51
|
+
throw new BizException('没有配置代码:' + methodCode);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
if (!this.checkFuncCode(anyApi.func_code)) {
|
|
55
|
+
throw new BizException('接口代码校验失败:不满足形式: class HttpController { async handleRequest(params){} }; ');
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
const allParams: IRunInSandboxParams = { headers, body, query };
|
|
59
|
+
allParams.params = this.toAnyApiParams(anyApi, allParams); // 组合参数
|
|
60
|
+
|
|
61
|
+
// 执行代码
|
|
62
|
+
const funcRes = await this.executeFunctionCode(anyApi, allParams);
|
|
63
|
+
return funcRes;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
private async getAnyApiMethod(methodCode: string): Promise<ISysAnyApiEntity> {
|
|
67
|
+
|
|
68
|
+
// 开发环境,不使用缓存
|
|
69
|
+
if (this.isEnableDebug()) {
|
|
70
|
+
return this._getAnyApiMethod(methodCode);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
// 线上环境可以使用缓存
|
|
74
|
+
let anyApi = lruCache.get(methodCode);
|
|
75
|
+
if (!anyApi) {
|
|
76
|
+
anyApi = await this._getAnyApiMethod(methodCode);
|
|
77
|
+
lruCache.set(methodCode, anyApi);
|
|
78
|
+
}
|
|
79
|
+
return anyApi;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
private async _getAnyApiMethod(methodCode: string): Promise<ISysAnyApiEntity> {
|
|
83
|
+
const res = await this.curdMixService.executeCrudByCfg(
|
|
84
|
+
{ condition: { method: methodCode } },
|
|
85
|
+
{
|
|
86
|
+
sqlTable: SystemTables.sys_anyapi,
|
|
87
|
+
method: `get_sys_anyapi_${methodCode}`,
|
|
88
|
+
sqlSimpleName: KeysOfSimpleSQL.SIMPLE_QUERY_ONE,
|
|
89
|
+
sqlDatabase: SystemDbName,
|
|
90
|
+
sqlDdType: SystemDbType,
|
|
91
|
+
updateCfg: {},
|
|
92
|
+
}
|
|
93
|
+
);
|
|
94
|
+
const obj: ISysAnyApiEntity = res.getOneObj();
|
|
95
|
+
if (!obj) {
|
|
96
|
+
return null;
|
|
97
|
+
}
|
|
98
|
+
obj.parsedOthers = parseJsonObject(obj.others);
|
|
99
|
+
return obj;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* 构造参数
|
|
104
|
+
* @param anyApi
|
|
105
|
+
* @param allParams
|
|
106
|
+
* @private
|
|
107
|
+
*/
|
|
108
|
+
private toAnyApiParams(anyApi: ISysAnyApiEntity, allParams: IRunInSandboxParams): any {
|
|
109
|
+
if (!anyApi.req_params) {
|
|
110
|
+
return {};
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
const configs = anyApi.parsedOthers?.req_params || [];
|
|
114
|
+
const params = {};
|
|
115
|
+
for (let i = 0; i < configs.length; i++) {
|
|
116
|
+
const { name, fromType, fromKey, validate_required, validate_cfg_list, valueType, defaultValue } = configs[i];
|
|
117
|
+
const value = _.get(allParams, [fromType, fromKey], defaultValue);
|
|
118
|
+
if (validate_required && MixinUtils.isEmpty(value)) {
|
|
119
|
+
throw new BizException(`参数校验失败:${name} 不能为空`);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
// 参数校验
|
|
123
|
+
if (Array.isArray(validate_cfg_list)) {
|
|
124
|
+
for (let j = 0; j < validate_cfg_list.length; j++) {
|
|
125
|
+
const validateCfg = validate_cfg_list[j];
|
|
126
|
+
validateByCfgString(validateCfg, value, name);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
// 格式转换
|
|
131
|
+
params[name] = MixinUtils.parseValueByType(value, valueType);
|
|
132
|
+
}
|
|
133
|
+
return params;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* 运行代码
|
|
138
|
+
* @param anyApiEntity
|
|
139
|
+
* @param allParams
|
|
140
|
+
* @private
|
|
141
|
+
*/
|
|
142
|
+
private async executeFunctionCode(anyApiEntity: ISysAnyApiEntity, allParams: IRunInSandboxParams): Promise<any> {
|
|
143
|
+
return this.anyApiSandboxService.runInSandbox(anyApiEntity, allParams);
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
private checkFuncCode(func_code: string): boolean {
|
|
147
|
+
if (!func_code) {
|
|
148
|
+
return false;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
const lineHasKey = (lineTrim: string, target: string): boolean => {
|
|
152
|
+
const words = lineTrim.split(/[\s{}();]/);
|
|
153
|
+
for (let i = 0; i < words.length; i++) {
|
|
154
|
+
const word = words[i];
|
|
155
|
+
if (word && word === target) {
|
|
156
|
+
return true;
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
return false;
|
|
160
|
+
};
|
|
161
|
+
|
|
162
|
+
let hasClass = false;
|
|
163
|
+
let hasMethod = false;
|
|
164
|
+
const lines = func_code.split('\n');
|
|
165
|
+
for (let i = 0; i < lines.length; i++) {
|
|
166
|
+
const line = lines[i];
|
|
167
|
+
if (line) {
|
|
168
|
+
const lineTrim = line.trim();
|
|
169
|
+
if (lineTrim) {
|
|
170
|
+
if (lineHasKey(lineTrim, 'class') && lineHasKey(lineTrim, 'HttpController')) {
|
|
171
|
+
hasClass = true;
|
|
172
|
+
}
|
|
173
|
+
if (lineHasKey(lineTrim, 'async') && lineHasKey(lineTrim, 'handleRequest')) {
|
|
174
|
+
hasMethod = true;
|
|
175
|
+
}
|
|
176
|
+
if (lineTrim.startsWith('handleRequest')) {
|
|
177
|
+
hasMethod = true;
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
return hasMethod && hasClass;
|
|
183
|
+
}
|
|
184
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { Provide } from '@midwayjs/core';
|
|
2
|
+
import { BaseService } from './BaseService';
|
|
3
|
+
import { IApiBaseEntity } from '../../models/SystemEntities';
|
|
4
|
+
import { BizException } from '../../models/devops';
|
|
5
|
+
import { Exceptions } from '../../libs/crud-pro/exceptions';
|
|
6
|
+
import { tryAcquireToken } from './ApiRateLimiter';
|
|
7
|
+
|
|
8
|
+
export const API_BASE_TYPE = {
|
|
9
|
+
PROXY_API: 'PROXY_API',
|
|
10
|
+
ANY_API: 'ANY_API',
|
|
11
|
+
CRUD_METHOD: 'CRUD_METHOD',
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
@Provide()
|
|
15
|
+
export class ApiBaseService extends BaseService {
|
|
16
|
+
/**
|
|
17
|
+
* 前置校验
|
|
18
|
+
* @param apiBaseType
|
|
19
|
+
* @param entity
|
|
20
|
+
*/
|
|
21
|
+
public async beforeCheckApiAccessibility(apiBaseType: string, entity: IApiBaseEntity) {
|
|
22
|
+
// 权限校验
|
|
23
|
+
const isPermSuccess = this.ctx.userSession.isAuthPass(entity.auth_type as any, entity.auth_config);
|
|
24
|
+
if (!isPermSuccess) {
|
|
25
|
+
throw new BizException('权限校验失败', Exceptions.NO_AUTH);
|
|
26
|
+
}
|
|
27
|
+
//服务降级
|
|
28
|
+
if (entity.fallback_enable === 1) {
|
|
29
|
+
throw new BizException(entity.fallback_message || '此服务暂时不支持访问', 'FALLBACK_ENABLE');
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// 限流令牌桶
|
|
33
|
+
if (entity.limit_enabled === 1) {
|
|
34
|
+
const accountId = this.ctx.userSession.getSessionInfo().accountId;
|
|
35
|
+
const apiId = apiBaseType + '_' + entity.id;
|
|
36
|
+
const isAcquire = tryAcquireToken(apiId, accountId, entity.limit_max, entity.limit_rate);
|
|
37
|
+
if (!isAcquire) {
|
|
38
|
+
throw new BizException('频繁访问此接口,被限流', 'LIMIT_ENABLED');
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|