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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (171) hide show
  1. package/dist/controller/home.controller.js +2 -1
  2. package/dist/controller/render/AppRenderController.js +2 -1
  3. package/dist/models/bizmodels.d.ts +1 -0
  4. package/dist/service/asyncTask/handler/ExportExcelAsyncTaskHandler.js +1 -1
  5. package/dist/service/crudstd/CrudStdService.d.ts +0 -6
  6. package/dist/service/crudstd/CrudStdService.js +13 -33
  7. package/package.json +1 -5
  8. package/src/config/config.default.ts +0 -207
  9. package/src/config/seed/aeskey.txt +0 -1
  10. package/src/config/utils.ts +0 -22
  11. package/src/configuration.ts +0 -109
  12. package/src/controller/base/BaseApiController.ts +0 -170
  13. package/src/controller/gateway/AnyApiGatewayController.ts +0 -33
  14. package/src/controller/gateway/AsyncTaskController.ts +0 -157
  15. package/src/controller/gateway/CrudMtdGatewayController.ts +0 -111
  16. package/src/controller/gateway/CrudStdGatewayController.ts +0 -101
  17. package/src/controller/gateway/DocGatewayController.ts +0 -173
  18. package/src/controller/gateway/FileController.ts +0 -109
  19. package/src/controller/gateway/ProxyApiGatewayController.ts +0 -47
  20. package/src/controller/gateway/PublicApiController.ts +0 -142
  21. package/src/controller/gateway/StaticController.ts +0 -298
  22. package/src/controller/helpers.controller.ts +0 -161
  23. package/src/controller/home.controller.ts +0 -64
  24. package/src/controller/manage/AnyApiMangeApi.ts +0 -66
  25. package/src/controller/manage/AppLogMangeApi.ts +0 -53
  26. package/src/controller/manage/AppMangeApi.ts +0 -53
  27. package/src/controller/manage/AppPageMangeApi.ts +0 -52
  28. package/src/controller/manage/AppSchemaHistoryApi.ts +0 -49
  29. package/src/controller/manage/CrudMethodsMangeApi.ts +0 -49
  30. package/src/controller/manage/CrudStandardDesignApi.ts +0 -346
  31. package/src/controller/manage/DataDictManageApi.ts +0 -78
  32. package/src/controller/manage/DeployManageApi.ts +0 -175
  33. package/src/controller/manage/DocLibManageApi.ts +0 -69
  34. package/src/controller/manage/DocManageApi.ts +0 -99
  35. package/src/controller/manage/FileManageApi.ts +0 -45
  36. package/src/controller/manage/LowCodeTplManageApi.ts +0 -52
  37. package/src/controller/manage/MenuManageApi.ts +0 -58
  38. package/src/controller/manage/ProxyApiMangeApi.ts +0 -52
  39. package/src/controller/manage/SuperAdminManageApi.ts +0 -139
  40. package/src/controller/manage/SysConfigMangeApi.ts +0 -95
  41. package/src/controller/manage/SystemInfoManageApi.ts +0 -53
  42. package/src/controller/manage/UserAccountManageApi.ts +0 -94
  43. package/src/controller/manage/WorkbenchMangeApi.ts +0 -72
  44. package/src/controller/myinfo/AuthController.ts +0 -108
  45. package/src/controller/myinfo/MyInfoController.ts +0 -32
  46. package/src/controller/render/AppRenderController.ts +0 -79
  47. package/src/controller/test.controller.ts +0 -37
  48. package/src/filter/default.filter.ts +0 -13
  49. package/src/filter/notfound.filter.ts +0 -10
  50. package/src/index.ts +0 -106
  51. package/src/interface.ts +0 -31
  52. package/src/libs/crud-pro/CrudPro.ts +0 -165
  53. package/src/libs/crud-pro/defaultConfigs.ts +0 -15
  54. package/src/libs/crud-pro/exceptions.ts +0 -124
  55. package/src/libs/crud-pro/interfaces.ts +0 -190
  56. package/src/libs/crud-pro/models/ExecuteContext.ts +0 -120
  57. package/src/libs/crud-pro/models/ExecuteContextFunc.ts +0 -96
  58. package/src/libs/crud-pro/models/FuncContext.ts +0 -21
  59. package/src/libs/crud-pro/models/RequestCfgModel.ts +0 -141
  60. package/src/libs/crud-pro/models/RequestModel.ts +0 -141
  61. package/src/libs/crud-pro/models/ResModel.ts +0 -19
  62. package/src/libs/crud-pro/models/ServiceHub.ts +0 -32
  63. package/src/libs/crud-pro/models/SqlCfgModel.ts +0 -52
  64. package/src/libs/crud-pro/models/SqlSegArg.ts +0 -13
  65. package/src/libs/crud-pro/models/Transaction.ts +0 -73
  66. package/src/libs/crud-pro/models/TransactionMySQL.ts +0 -79
  67. package/src/libs/crud-pro/models/TransactionPostgres.ts +0 -91
  68. package/src/libs/crud-pro/models/TransactionSqlServer.ts +0 -102
  69. package/src/libs/crud-pro/models/keys.ts +0 -159
  70. package/src/libs/crud-pro/services/CrudProCachedCfgService.ts +0 -83
  71. package/src/libs/crud-pro/services/CrudProExecuteFuncService.ts +0 -128
  72. package/src/libs/crud-pro/services/CrudProExecuteSqlService.ts +0 -262
  73. package/src/libs/crud-pro/services/CrudProFieldUpdateService.ts +0 -60
  74. package/src/libs/crud-pro/services/CrudProFieldValidateService.ts +0 -180
  75. package/src/libs/crud-pro/services/CrudProGenSqlCondition.ts +0 -354
  76. package/src/libs/crud-pro/services/CrudProGenSqlService.ts +0 -185
  77. package/src/libs/crud-pro/services/CrudProOriginToExecuteSql.ts +0 -393
  78. package/src/libs/crud-pro/services/CrudProServiceBase.ts +0 -94
  79. package/src/libs/crud-pro/services/CrudProTableMetaService.ts +0 -86
  80. package/src/libs/crud-pro/services/CurdProServiceHub.ts +0 -92
  81. package/src/libs/crud-pro/sql.txt +0 -120
  82. package/src/libs/crud-pro/utils/CompareUtils.ts +0 -23
  83. package/src/libs/crud-pro/utils/DatabaseName.ts +0 -60
  84. package/src/libs/crud-pro/utils/DateTimeUtils.ts +0 -20
  85. package/src/libs/crud-pro/utils/MemoryRefreshCache.ts +0 -64
  86. package/src/libs/crud-pro/utils/MessageParseUtils.ts +0 -33
  87. package/src/libs/crud-pro/utils/MixinUtils.ts +0 -285
  88. package/src/libs/crud-pro/utils/ModelUtils.ts +0 -55
  89. package/src/libs/crud-pro/utils/MultiKeyMap.ts +0 -72
  90. package/src/libs/crud-pro/utils/SqlFuncUtils.ts +0 -29
  91. package/src/libs/crud-pro/utils/TypeUtils.ts +0 -188
  92. package/src/libs/crud-pro/utils/ValidateUtils.ts +0 -165
  93. package/src/libs/crud-pro/utils/pool/MySQLUtils.ts +0 -20
  94. package/src/libs/crud-pro/utils/pool/PostgresUtils.ts +0 -22
  95. package/src/libs/crud-pro/utils/pool/SqlServerUtils.ts +0 -22
  96. package/src/libs/crud-pro/utils/sqlConvert/convertColumnName.ts +0 -26
  97. package/src/libs/crud-pro/utils/sqlConvert/convertMix.ts +0 -26
  98. package/src/libs/crud-pro/utils/sqlConvert/convertMsSql.ts +0 -11
  99. package/src/libs/crud-pro/utils/sqlConvert/convertPgSql.ts +0 -11
  100. package/src/libs/crud-pro/utils/sqlConvert/convertPgType.ts +0 -129
  101. package/src/libs/global-config/global-config.ts +0 -78
  102. package/src/libs/utils/common-dto.ts +0 -52
  103. package/src/libs/utils/crypto-utils.ts +0 -50
  104. package/src/libs/utils/errorToString.ts +0 -61
  105. package/src/libs/utils/fatcms-request.ts +0 -103
  106. package/src/libs/utils/functions.ts +0 -73
  107. package/src/libs/utils/ordernum-utils.ts +0 -14
  108. package/src/libs/utils/parseConfig.ts +0 -54
  109. package/src/libs/utils/parseCreateSql.ts +0 -91
  110. package/src/libs/utils/render-utils.ts +0 -184
  111. package/src/middleware/forbidden.middleware.ts +0 -52
  112. package/src/middleware/global.middleware.ts +0 -280
  113. package/src/middleware/permission.middleware.ts +0 -80
  114. package/src/middleware/tx.middleware.ts +0 -30
  115. package/src/models/AsyncTaskModel.ts +0 -82
  116. package/src/models/RedisKeys.ts +0 -13
  117. package/src/models/SystemEntities.ts +0 -115
  118. package/src/models/SystemPerm.ts +0 -105
  119. package/src/models/SystemTables.ts +0 -27
  120. package/src/models/bizmodels.ts +0 -120
  121. package/src/models/contextLogger.ts +0 -132
  122. package/src/models/devops.ts +0 -17
  123. package/src/models/userSession.ts +0 -216
  124. package/src/schedule/anonymousContext.ts +0 -73
  125. package/src/schedule/index.ts +0 -12
  126. package/src/schedule/runSchedule.ts +0 -82
  127. package/src/schedule/scheduleNames.ts +0 -21
  128. package/src/service/AuthService.ts +0 -272
  129. package/src/service/EnumInfoService.ts +0 -130
  130. package/src/service/FileCenterService.ts +0 -395
  131. package/src/service/SysConfigService.ts +0 -37
  132. package/src/service/UserAccountService.ts +0 -107
  133. package/src/service/UserSessionService.ts +0 -78
  134. package/src/service/VisitStatService.ts +0 -166
  135. package/src/service/WorkbenchService.ts +0 -165
  136. package/src/service/anyapi/AnyApiSandboxService.ts +0 -121
  137. package/src/service/anyapi/AnyApiService.ts +0 -186
  138. package/src/service/asyncTask/AsyncTaskRunnerService.ts +0 -266
  139. package/src/service/asyncTask/AsyncTaskService.ts +0 -21
  140. package/src/service/asyncTask/handler/ExcelInfoModel.ts +0 -11
  141. package/src/service/asyncTask/handler/ExportExcelAsyncTaskHandler.ts +0 -245
  142. package/src/service/asyncTask/handler/ExportExcelByInnerHttpHandler.ts +0 -147
  143. package/src/service/asyncTask/handler/ExportExcelByStdCrudHandler.ts +0 -138
  144. package/src/service/base/ApiBaseService.ts +0 -42
  145. package/src/service/base/ApiRateLimiter.ts +0 -59
  146. package/src/service/base/BaseService.ts +0 -100
  147. package/src/service/base/RedisCacheService.ts +0 -38
  148. package/src/service/crudstd/CrudStdActionService.ts +0 -27
  149. package/src/service/crudstd/CrudStdConstant.ts +0 -62
  150. package/src/service/crudstd/CrudStdRelationService.ts +0 -78
  151. package/src/service/crudstd/CrudStdService.ts +0 -283
  152. package/src/service/curd/CrudProQuick.ts +0 -131
  153. package/src/service/curd/CurdMixByAccountService.ts +0 -90
  154. package/src/service/curd/CurdMixByDictService.ts +0 -114
  155. package/src/service/curd/CurdMixByLinkToCustomService.ts +0 -219
  156. package/src/service/curd/CurdMixBySysConfigService.ts +0 -78
  157. package/src/service/curd/CurdMixByWorkbenchService.ts +0 -71
  158. package/src/service/curd/CurdMixService.ts +0 -97
  159. package/src/service/curd/CurdMixUtils.ts +0 -311
  160. package/src/service/curd/CurdProService.ts +0 -229
  161. package/src/service/curd/fixCfgModel.ts +0 -139
  162. package/src/service/proxyapi/ProxyApiLoadService.ts +0 -174
  163. package/src/service/proxyapi/ProxyApiService.ts +0 -262
  164. package/src/service/proxyapi/ProxyApiUtils.ts +0 -32
  165. package/src/service/proxyapi/RouteHandler.ts +0 -8
  166. package/src/service/proxyapi/RouteTrie.ts +0 -74
  167. package/src/service/proxyapi/WeightedRandom.ts +0 -37
  168. package/src/service/proxyapi/WeightedRoundRobin.ts +0 -44
  169. package/src/views/404_app.html +0 -31
  170. package/src/views/404_workbench.html +0 -34
  171. package/src/views/static/favicon.ico +0 -0
@@ -1,298 +0,0 @@
1
- import { All, Controller, Inject, Param } from '@midwayjs/core';
2
- import { Context } from '@midwayjs/koa';
3
- import { BaseApiController } from '../base/BaseApiController';
4
- import * as fs from 'fs/promises';
5
- import * as fs2 from 'fs';
6
- import * as path from 'path';
7
- import * as https from 'https';
8
- import { parseJsonObject } from '@/libs/utils/functions';
9
-
10
- interface HttpGetRes {
11
- statusCode: number;
12
- headers: any;
13
- body: NodeJS.ReadableStream;
14
- }
15
-
16
- function getPathConfig(ossName: string) {
17
- const remoteBaseUrlMap = {
18
- cdnjsx: 'https://cdnjsx.oss-cn-shanghai.aliyuncs.com',
19
- 'i.alicdn.com': 'https://i.alicdn.com',
20
- 'img.alicdn.com': 'https://img.alicdn.com',
21
- 'at.alicdn.com': 'https://at.alicdn.com',
22
- };
23
- let remoteBaseUrl = remoteBaseUrlMap[ossName];
24
- if (!remoteBaseUrl) {
25
- console.error(`getPathConfig ossName: ${ossName} 未配置`);
26
- remoteBaseUrl = `https://${ossName}`;
27
- }
28
- return {
29
- remoteBaseUrl,
30
- };
31
- }
32
-
33
- // 404列表缓存
34
- let notFoundList = new Set();
35
- let notFoundListIsInit = false;
36
-
37
- /**
38
- * 静态文件代理功能
39
- */
40
- @Controller('/ns/static')
41
- export class StaticController extends BaseApiController {
42
- @Inject()
43
- protected ctx: Context;
44
-
45
- constructor() {
46
- super();
47
- this.initNotFoundList();
48
- }
49
-
50
- private getLocalPaths(): any {
51
- const appDir = this.app.getAppDir();
52
- const localDir = path.join(appDir, './public/static'); // 本地文件存储目录
53
- const notFoundListFile = path.join(localDir, '__404__list.json'); // 404列表文件
54
- return {
55
- localDir,
56
- notFoundListFile,
57
- };
58
- }
59
-
60
- private async initNotFoundList() {
61
- if (notFoundListIsInit) {
62
- return;
63
- }
64
- notFoundListIsInit = true;
65
-
66
- const { localDir, notFoundListFile } = this.getLocalPaths();
67
- try {
68
- // 确保本地存储目录存在
69
- await fs.mkdir(localDir, { recursive: true });
70
- const data = await fs.readFile(notFoundListFile, 'utf8');
71
-
72
- notFoundList = new Set(JSON.parse(data));
73
- console.log(`已加载${notFoundList.size}个404记录`);
74
- } catch (error) {
75
- if (error.code !== 'ENOENT') {
76
- console.error('读取404列表失败:', error);
77
- }
78
- }
79
- }
80
-
81
- private async responseLocalFile(localFilePath: string, localHeaderPath: string, relativePath: string): Promise<boolean> {
82
- const headers = {
83
- 'Cache-Control': 'public, max-age=31536000',
84
- Expires: new Date(Date.now() + 31536000000).toUTCString(),
85
- };
86
-
87
- try {
88
- // 检查本地文件是否存在.头文件
89
- const stats = await fs.stat(localHeaderPath);
90
- if (stats.isFile()) {
91
- const headerDataStr = await fs.readFile(localHeaderPath, 'utf8');
92
- const headerData = parseJsonObject(headerDataStr);
93
- if (headerData) {
94
- headers['content-type'] = headerData['content-type'];
95
- headers['content-length'] = headerData['content-length'];
96
- headers['last-modified'] = headerData['last-modified'];
97
- headers['etag'] = headerData['etag'];
98
- headers['cache-control'] = headerData['cache-control'];
99
- headers['accept-ranges'] = headerData['accept-ranges'];
100
- }
101
- }
102
- } catch (error) {
103
- this.logDebug('[StaticController]responseLocalFile', error);
104
- }
105
-
106
- try {
107
- // 检查本地文件是否存在
108
- const stats = await fs.stat(localFilePath);
109
- if (stats.isFile()) {
110
- if (!headers['content-type']) {
111
- headers['content-type'] = this.getMimeType(localFilePath);
112
- }
113
-
114
- const stream = fs2.createReadStream(localFilePath);
115
- stream.setMaxListeners(50);
116
- // const oldOn = stream.on.bind(stream);
117
- // stream.on = (...args)=>{
118
- // return oldOn(...args)
119
- // }
120
-
121
- this.logInfo(`[StaticController]返回本地文件: ${relativePath}`);
122
- this.ctx.status = 200;
123
- this.ctx.set(headers);
124
-
125
- this.ctx.body = stream;
126
- return true;
127
- }
128
- } catch (error) {
129
- // 文件不存在,继续请求远程
130
- }
131
-
132
- return false;
133
- }
134
-
135
- @All('/:ossName/:relativePath+')
136
- async proxyStaticFile(@Param('ossName') ossName: string, @Param('relativePath') relativePath: string) {
137
- const { localDir } = this.getLocalPaths();
138
- const PATH_CONFIG = getPathConfig(ossName);
139
-
140
- // 构建本地路径和远程路径
141
- const localFilePath = path.join(localDir, 'files', ossName, relativePath);
142
- const localHeaderPath = path.join(localDir, 'headers', ossName, relativePath);
143
- const remoteUrl = `${PATH_CONFIG.remoteBaseUrl}/${relativePath}`;
144
-
145
- // 检查是否在404列表中
146
- if (notFoundList.has(relativePath)) {
147
- this.ctx.status = 404;
148
- return this.ctx.render('500', { errorMsg: ' 远程文件不存在, 命中notFoundList' });
149
- }
150
-
151
- // 检查并返回本地文件
152
- if (await this.responseLocalFile(localFilePath, localHeaderPath, relativePath)) {
153
- return;
154
- }
155
-
156
- // 请求远程文件
157
- this.logInfo(`[StaticController]请求远程文件: ${remoteUrl}`);
158
-
159
- try {
160
- const remoteRes = await this.httpsGet(remoteUrl);
161
-
162
- // 处理远程响应状态码
163
- if (remoteRes.statusCode === 200) {
164
- // 写入本地文件
165
- await this.writeResponseToFile(remoteRes, localFilePath, localHeaderPath);
166
-
167
- // 检查并返回本地文件
168
- if (await this.responseLocalFile(localFilePath, localHeaderPath, relativePath)) {
169
- return;
170
- }
171
- } else if (remoteRes.statusCode === 404) {
172
- // 记录404并返回
173
- notFoundList.add(relativePath);
174
- await this.saveNotFoundList();
175
- this.logInfo(`[StaticController]远程文件不存在,已记录404: ${relativePath}`);
176
- this.ctx.status = 404;
177
- return this.ctx.render('500', { errorMsg: ' 远程文件不存在,已记录404' });
178
- } else {
179
- // 其他状态码
180
- const msg = `[StaticController]远程服务器返回状态码: ${remoteRes.statusCode}`;
181
- this.logInfo(msg);
182
- this.ctx.status = 502;
183
- return this.ctx.render('500', { errorMsg: msg });
184
- }
185
- } catch (err) {
186
- const msg = `[StaticController]请求远程文件失败: ${err}`;
187
- this.logError(msg);
188
- this.ctx.status = 500;
189
- return this.ctx.render('500', { errorMsg: msg });
190
- }
191
-
192
- this.ctx.status = 500;
193
- return this.ctx.render('500', { errorMsg: '未知异常' });
194
- }
195
-
196
- // 保存404列表
197
- async saveNotFoundList() {
198
- const { notFoundListFile } = this.getLocalPaths();
199
- try {
200
- // 确保存储404列表的目录存在
201
- const dir = path.dirname(notFoundListFile);
202
- await fs.mkdir(dir, { recursive: true });
203
-
204
- await fs.writeFile(notFoundListFile, JSON.stringify(Array.from(notFoundList), null), 'utf8');
205
- } catch (error) {
206
- this.logError('[StaticController]保存404列表失败:', error);
207
- }
208
- }
209
-
210
- // 封装https请求为异步函数
211
- async httpsGet(url: string): Promise<HttpGetRes> {
212
- return new Promise<HttpGetRes>((resolve, reject) => {
213
- https
214
- .get(url, res => {
215
- resolve({
216
- statusCode: res.statusCode || 500,
217
- headers: res.headers,
218
- body: res,
219
- });
220
- })
221
- .on('error', err => {
222
- reject(err);
223
- });
224
- });
225
- }
226
-
227
- // 新增:将响应body写入文件的函数
228
- async writeResponseToFile(httpsGetRes: HttpGetRes, localFilePath: string, localHeaderPath: string): Promise<void> {
229
- // 创建本地目录(如果不存在)
230
- const localFileDir = path.dirname(localFilePath);
231
- await fs.mkdir(localFileDir, { recursive: true });
232
-
233
- const localHeaderDir = path.dirname(localHeaderPath);
234
- await fs.mkdir(localHeaderDir, { recursive: true });
235
-
236
- try {
237
- const { statusCode, body } = httpsGetRes;
238
-
239
- // 检查HTTP状态码
240
- if (statusCode >= 400) {
241
- throw new Error(`HTTP请求失败,状态码: ${statusCode}`);
242
- }
243
-
244
- // 创建可写流
245
- const fileStream = fs2.createWriteStream(localFilePath);
246
-
247
- // 使用管道将响应流写入文件
248
- await new Promise((resolve, reject) => {
249
- body.pipe(fileStream);
250
-
251
- body.on('error', err => {
252
- reject(new Error(`读取响应流失败: ${err.message}`));
253
- });
254
-
255
- fileStream.on('finish', resolve);
256
- fileStream.on('error', err => {
257
- reject(new Error(`写入文件失败: ${err.message}`));
258
- });
259
- });
260
-
261
- this.logInfo(`[StaticController]文件已成功写入1: ${localFilePath}`);
262
-
263
- await fs.writeFile(localHeaderPath, JSON.stringify(httpsGetRes.headers), 'utf8');
264
-
265
- this.logInfo(`[StaticController]文件已成功写入2: ${localHeaderPath}`);
266
- } catch (err) {
267
- // 发生错误时删除可能存在的不完整文件
268
- if (fs2.existsSync(localFilePath)) {
269
- fs2.unlinkSync(localFilePath);
270
- }
271
- throw new Error(`下载过程中发生错误: ${err.message}`);
272
- }
273
- }
274
-
275
- // 根据文件扩展名获取MIME类型
276
- getMimeType(filePath: string) {
277
- const extname = path.extname(filePath).toLowerCase();
278
- const mimeTypes = {
279
- '.html': 'text/html',
280
- '.js': 'text/javascript',
281
- '.css': 'text/css',
282
- '.json': 'application/json',
283
- '.png': 'image/png',
284
- '.jpg': 'image/jpg',
285
- '.gif': 'image/gif',
286
- '.svg': 'image/svg+xml',
287
- '.woff': 'font/woff',
288
- '.woff2': 'font/woff2',
289
- '.ttf': 'font/ttf',
290
- '.eot': 'application/vnd.ms-fontobject',
291
- '.txt': 'text/plain',
292
- '.pdf': 'application/pdf',
293
- '.mp4': 'video/mp4',
294
- '.ico': 'image/x-icon',
295
- };
296
- return mimeTypes[extname] || 'application/octet-stream';
297
- }
298
- }
@@ -1,161 +0,0 @@
1
- import { Inject, Controller, Get, Post, MidwayWebRouterService, Query } from '@midwayjs/core';
2
- import { Context } from '@midwayjs/koa';
3
- import * as _ from 'lodash';
4
- import * as md5 from 'md5';
5
- import { CurdMixService } from '../service/curd/CurdMixService';
6
- import { CommonException, Exceptions } from '../libs/crud-pro/exceptions';
7
- import { createUniqueId } from '../libs/utils/functions';
8
- import { privateAES } from '../libs/utils/crypto-utils';
9
- import { CommonResult } from '../libs/utils/common-dto';
10
-
11
- // http://127.0.0.1:7002/ns/api/helpers/getApiScript?prefix=/ns/api/manage
12
- // http://127.0.0.1:7002/ns/api/helpers/getApiScript
13
- // http://127.0.0.1:7002/ns/api/helpers/getApiEnv
14
- // http://127.0.0.1:7002/ns/api/helpers/cryptoAes128CBC?input=123
15
-
16
- @Controller('/ns/api/helpers')
17
- export class HelpersApi {
18
- @Inject()
19
- protected ctx: Context;
20
-
21
- @Inject()
22
- private midwayWebRouterService: MidwayWebRouterService;
23
-
24
- @Inject()
25
- protected curdMixService: CurdMixService;
26
-
27
- @Get('/getApiEnv')
28
- async getApiEnv() {
29
- const host = this.ctx.req.headers.host;
30
- const env = this.ctx.app.env;
31
- const href = this.ctx.href;
32
- const proc = process;
33
- return {
34
- env,
35
- href,
36
- host,
37
- ctx: this.ctx,
38
- processInfo: {
39
- version: proc.version,
40
- versions: proc.versions,
41
- env: proc.env,
42
- argv: proc.argv,
43
- cwd: proc.cwd(),
44
- },
45
- };
46
- }
47
-
48
- @Get('/getApiScript')
49
- async getApiScript(@Query() queryData) {
50
- this.checkLocalPermissionEnv();
51
-
52
- const prefix = queryData.prefix || '/api/';
53
-
54
- const routers0 = await this.midwayWebRouterService.getFlattenRouterTable();
55
-
56
- const routers = routers0.filter(r => {
57
- return r.fullUrl.startsWith(prefix);
58
- });
59
-
60
- const group = _.groupBy(routers, r => {
61
- return r.controllerId;
62
- });
63
-
64
- const groupKeys = Object.keys(group).sort();
65
-
66
- const controllers = groupKeys.map(controllerId => {
67
- const routers2 = group[controllerId];
68
-
69
- const routers3 = routers2.sort((a, b) => {
70
- const f1 = '' + a.fullUrl;
71
- const f2 = '' + b.fullUrl;
72
- return f1.localeCompare(f2);
73
- });
74
-
75
- const methods = routers3
76
- .map(r => {
77
- let method = r.requestMethod.toUpperCase();
78
- if (method === 'ALL') {
79
- method = 'POST';
80
- }
81
- return ` ${r.method}: createApiRequest('${r.fullUrl}', '${method}'),`;
82
- })
83
- .filter(r => {
84
- return !!r;
85
- })
86
- .join('\n');
87
- return `const ${controllerId} = {\n${methods} \n}`;
88
- });
89
-
90
- const href = this.ctx.href;
91
- const infos = `/* 代码生成路径为:${href} */ \n`;
92
- const imports = 'import {createApiRequest} from "./utils.js";\n';
93
- const exports = groupKeys.join(',\n ');
94
- return infos + imports + controllers.join('\n\n') + `\n\nexport {\n ${exports} \n}`;
95
- }
96
-
97
- @Post('/testExecuteCrudByCfg')
98
- async testExecuteCrudByCfg() {
99
- this.checkLocalPermissionEnv();
100
-
101
- const { reqJson, cfgModel } = this.ctx.request.body as any;
102
- return await this.curdMixService.executeCrudByCfg(reqJson, cfgModel);
103
- }
104
-
105
- /**
106
- * 工具函数: 由明文生成数据库中的存储的密码
107
- * @param queryData
108
- */
109
- @Get('/generateDatabasePassword')
110
- async generateDatabasePassword(@Query() queryData) {
111
- const loginName = queryData.loginName;
112
- const pw0 = queryData.pw0;
113
-
114
- // 这个函数的逻辑,在生产环境中,在前端执行
115
- const toUnsaltedPwd = (pw0: string, loginName: string): string => {
116
- return md5(md5(pw0) + '_' + loginName);
117
- };
118
-
119
- const unsaltedPwd = toUnsaltedPwd(pw0, loginName);
120
- const pwd_salt = createUniqueId();
121
- const pwd_md5 = md5(unsaltedPwd + pwd_salt);
122
-
123
- return {
124
- pwd_salt,
125
- pwd_md5,
126
- login_name: loginName,
127
- };
128
- }
129
-
130
- /**
131
- * 工具函数: 使用Aes128CBC加密
132
- * @param queryData
133
- */
134
- @Get('/cryptoAes128CBC')
135
- async cryptoAes128CBC(@Query() queryData) {
136
- const input = queryData.input;
137
- if (!input) {
138
- return CommonResult.errorRes('input 参数不能为空');
139
- }
140
- const encrypted = await privateAES.time_encrypt_utf8_base64(input);
141
- const decrypted = await privateAES.time_decrypt_base64_utf8(encrypted);
142
- return CommonResult.successRes({
143
- input,
144
- encrypted,
145
- decrypted,
146
- isEqual: input === decrypted,
147
- });
148
- }
149
-
150
- private checkLocalPermissionEnv() {
151
- const isLocalEnv = (): boolean => {
152
- const env = this.ctx.app.env;
153
- const host = this.ctx.req.headers.host;
154
- return env === 'local' && (host.startsWith('127.0.0.1') || host.startsWith('localhost:') || host === 'localhost');
155
- };
156
-
157
- if (!isLocalEnv()) {
158
- throw new CommonException(Exceptions.NO_AUTH, '此测试函数,仅只有本地环境可以调用');
159
- }
160
- }
161
- }
@@ -1,64 +0,0 @@
1
- import { Controller, Get, Inject } from '@midwayjs/core';
2
- import { Context } from '@midwayjs/koa';
3
- import { BaseApiController } from './base/BaseApiController';
4
- import { WorkbenchService } from '../service/WorkbenchService';
5
- import { createRenderUtils } from '../libs/utils/render-utils';
6
- import { privateAES } from '../libs/utils/crypto-utils';
7
-
8
- @Controller('/')
9
- export class HomeController extends BaseApiController {
10
- @Inject()
11
- protected ctx: Context;
12
-
13
- @Inject()
14
- protected workbenchService: WorkbenchService;
15
-
16
- @Get('/*')
17
- async home(): Promise<string> {
18
- const host = this.ctx.request.host;
19
- const hostname = this.ctx.request.hostname;
20
-
21
- const workbenchInfo = await this.workbenchService.getCurrentHostWorkbenchInfo();
22
-
23
- if (!workbenchInfo || workbenchInfo.status !== 1) {
24
- this.logInfo(`域名不存在:hostname = ${hostname}, host=${host}`);
25
- const infos = {
26
- host,
27
- errorInfo: `ERR_FATCMS_REFUSED <br/> 域名配置不存在:hostname = ${hostname}, host=${host}`,
28
- };
29
- this.ctx.status = 404;
30
- return this.ctx.render('404_workbench', infos);
31
- }
32
-
33
- const html_content = workbenchInfo.html_content || '未配置HTML模版';
34
-
35
- const userInfo = this.getUserSessionInfo();
36
-
37
- const fatcmscsrftoken = await privateAES.time_encrypt_utf8_base64('' + Date.now());
38
-
39
- const utils = createRenderUtils({
40
- ctx: this.ctx,
41
- userInfo,
42
- workbenchInfo,
43
- package_assets: workbenchInfo.package_assets,
44
- fatcmscsrftoken,
45
- });
46
-
47
- return this.ctx.renderString(html_content, { workbenchInfo, userInfo, utils }, { viewEngine: 'ejs' });
48
- }
49
-
50
- @Get('/robots.txt')
51
- async robots(): Promise<string> {
52
- return `User-agent: * \nDisallow: /ns/api/manage/`;
53
- }
54
-
55
- // @Get('/favicon.ico')
56
- // async favicon() {
57
- // debugger
58
- // const p = path.join(this.app.getBaseDir(), './views/favicon.ico');
59
- // const buffer = fs.readFileSync(p);
60
- // const ctx = this.ctx;
61
- // ctx.set('Content-Type', 'image/jpeg');
62
- // ctx.body = buffer;
63
- // }
64
- }
@@ -1,66 +0,0 @@
1
- import { Controller, Inject, Post } from '@midwayjs/core';
2
- import { Context } from '@midwayjs/koa';
3
- import { KeysOfSimpleSQL, KeysOfValidators } from '@/libs/crud-pro/models/keys';
4
- import { BaseApiController } from '../base/BaseApiController';
5
- import { checkPermission } from '@/middleware/permission.middleware';
6
- import { SystemFuncCode } from '@/models/SystemPerm';
7
- import { SystemTables } from '@/models/SystemTables';
8
- import { ISysAnyApiEntity } from '@/models/SystemEntities';
9
- import * as md5 from 'md5';
10
- import { parseJsonObject } from '@/libs/utils/functions';
11
-
12
- function fixBodyData(body: any) {
13
- const dataObj: any = (body.data || {}) as ISysAnyApiEntity;
14
- const parsedOthers = parseJsonObject(dataObj.others);
15
- dataObj.func_code_md5 = md5(dataObj.func_code || '');
16
- dataObj.req_params = parsedOthers?.req_params?.length || 0; // 参数个数
17
- }
18
-
19
- @Controller('/ns/api/manage/anyapi', { middleware: [checkPermission(SystemFuncCode.AnyApiManageRead)] })
20
- export class AnyApiMangeApi extends BaseApiController {
21
- @Inject()
22
- protected ctx: Context;
23
-
24
- @Post('/getAnyApiList')
25
- async getAnyApiList() {
26
- return this.executeSysSimpleSQL(SystemTables.sys_anyapi, KeysOfSimpleSQL.SIMPLE_QUERY_PAGE);
27
- }
28
-
29
- @Post('/getAnyApiOne')
30
- async getAnyApiOne() {
31
- return this.executeSysSimpleSQL(SystemTables.sys_anyapi, KeysOfSimpleSQL.SIMPLE_QUERY_ONE);
32
- }
33
-
34
- @Post('/createAnyApi', { middleware: [checkPermission(SystemFuncCode.AnyApiManageWrite)] })
35
- async createAnyApi() {
36
- fixBodyData(this.ctx.request.body);
37
-
38
- return this.executeSysSimpleSQL(SystemTables.sys_anyapi, KeysOfSimpleSQL.SIMPLE_INSERT, {
39
- validateCfg: {
40
- 'data.method': [KeysOfValidators.REQUIRED, KeysOfValidators.STRING],
41
- 'data.method_name': [KeysOfValidators.REQUIRED, KeysOfValidators.STRING],
42
- 'data.func_code': [KeysOfValidators.REQUIRED, KeysOfValidators.STRING],
43
- },
44
- });
45
- }
46
-
47
- @Post('/updateAnyApi', { middleware: [checkPermission(SystemFuncCode.AnyApiManageWrite)] })
48
- async updateAnyApi() {
49
- fixBodyData(this.ctx.request.body);
50
-
51
- return this.executeSysSimpleSQL(SystemTables.sys_anyapi, KeysOfSimpleSQL.SIMPLE_UPDATE, {
52
- validateCfg: {
53
- 'condition.id': [KeysOfValidators.REQUIRED, KeysOfValidators.NUMERIC],
54
- },
55
- });
56
- }
57
-
58
- @Post('/deleteAnyApi', { middleware: [checkPermission(SystemFuncCode.AnyApiManageWrite)] })
59
- async deleteAnyApi() {
60
- return this.executeSysSimpleSQL(SystemTables.sys_anyapi, KeysOfSimpleSQL.SIMPLE_DELETE, {
61
- validateCfg: {
62
- 'condition.id': [KeysOfValidators.REQUIRED, KeysOfValidators.NUMERIC],
63
- },
64
- });
65
- }
66
- }
@@ -1,53 +0,0 @@
1
- import { Controller, Inject, Post } from '@midwayjs/core';
2
- import { Context } from '@midwayjs/koa';
3
- import { KeysOfSimpleSQL, KeysOfValidators } from '@/libs/crud-pro/models/keys';
4
- import { BaseApiController } from '../base/BaseApiController';
5
- import { checkPermission } from '@/middleware/permission.middleware';
6
- import { SystemFuncCode } from '@/models/SystemPerm';
7
-
8
- @Controller('/ns/api/manage/appLog', { middleware: [checkPermission(SystemFuncCode.AppMangeRead)] })
9
- export class AppLogMangeApi extends BaseApiController {
10
- @Inject()
11
- ctx: Context;
12
-
13
- @Post('/getAppLogList')
14
- async getAppLogList() {
15
- return this.executeSysSimpleSQL('sys_app_log', KeysOfSimpleSQL.SIMPLE_QUERY_PAGE);
16
- }
17
-
18
- @Post('/getAppLogOne')
19
- async getAppLogOne() {
20
- return this.executeSysSimpleSQL('sys_app_log', KeysOfSimpleSQL.SIMPLE_QUERY_ONE);
21
- }
22
-
23
- @Post('/createAppLog', { middleware: [checkPermission(SystemFuncCode.AppMangeWrite)] })
24
- async createAppLog() {
25
- return this.executeSysSimpleSQL('sys_app_log', KeysOfSimpleSQL.SIMPLE_INSERT, {
26
- validateCfg: {
27
- 'data.app_code': [KeysOfValidators.REQUIRED, KeysOfValidators.STRING],
28
- 'data.app_name': [KeysOfValidators.REQUIRED, KeysOfValidators.STRING],
29
- 'data.app_type': [KeysOfValidators.REQUIRED, KeysOfValidators.STRING],
30
- },
31
- });
32
- }
33
-
34
- @Post('/updateAppLog', { middleware: [checkPermission(SystemFuncCode.AppMangeWrite)] })
35
- async updateAppLog() {
36
- return this.executeSysSimpleSQL('sys_app_log', KeysOfSimpleSQL.SIMPLE_UPDATE, {
37
- validateCfg: {
38
- 'condition.id': [KeysOfValidators.REQUIRED, KeysOfValidators.NUMERIC],
39
- 'condition.app_code': [KeysOfValidators.REQUIRED, KeysOfValidators.STRING],
40
- },
41
- });
42
- }
43
-
44
- @Post('/deleteAppLog', { middleware: [checkPermission(SystemFuncCode.AppMangeWrite)] })
45
- async deleteAppLog() {
46
- return this.executeSysSimpleSQL('sys_app_log', KeysOfSimpleSQL.SIMPLE_DELETE, {
47
- validateCfg: {
48
- 'condition.id': [KeysOfValidators.REQUIRED, KeysOfValidators.NUMERIC],
49
- 'condition.app_code': [KeysOfValidators.REQUIRED, KeysOfValidators.STRING],
50
- },
51
- });
52
- }
53
- }
@@ -1,53 +0,0 @@
1
- import { Controller, Inject, Post } from '@midwayjs/core';
2
- import { Context } from '@midwayjs/koa';
3
- import { KeysOfSimpleSQL, KeysOfValidators } from '@/libs/crud-pro/models/keys';
4
- import { BaseApiController } from '../base/BaseApiController';
5
- import { checkPermission } from '@/middleware/permission.middleware';
6
- import { SystemFuncCode } from '@/models/SystemPerm';
7
-
8
- @Controller('/ns/api/manage/app', { middleware: [checkPermission(SystemFuncCode.AppMangeRead)] })
9
- export class AppMangeApi extends BaseApiController {
10
- @Inject()
11
- ctx: Context;
12
-
13
- @Post('/getAppList')
14
- async getAppList() {
15
- return this.executeSysSimpleSQL('sys_app', KeysOfSimpleSQL.SIMPLE_QUERY_PAGE);
16
- }
17
-
18
- @Post('/getAppOne')
19
- async getAppOne() {
20
- return this.executeSysSimpleSQL('sys_app', KeysOfSimpleSQL.SIMPLE_QUERY_ONE);
21
- }
22
-
23
- @Post('/createApp', { middleware: [checkPermission(SystemFuncCode.AppMangeWrite)] })
24
- async createApp() {
25
- return this.executeSysSimpleSQL('sys_app', KeysOfSimpleSQL.SIMPLE_INSERT, {
26
- validateCfg: {
27
- 'data.app_code': [KeysOfValidators.REQUIRED, KeysOfValidators.STRING],
28
- 'data.app_name': [KeysOfValidators.REQUIRED, KeysOfValidators.STRING],
29
- 'data.app_type': [KeysOfValidators.REQUIRED, KeysOfValidators.STRING],
30
- },
31
- });
32
- }
33
-
34
- @Post('/updateApp', { middleware: [checkPermission(SystemFuncCode.AppMangeWrite)] })
35
- async updateApp() {
36
- return this.executeSysSimpleSQL('sys_app', KeysOfSimpleSQL.SIMPLE_UPDATE, {
37
- validateCfg: {
38
- 'condition.id': [KeysOfValidators.REQUIRED, KeysOfValidators.NUMERIC],
39
- 'condition.app_code': [KeysOfValidators.REQUIRED, KeysOfValidators.STRING],
40
- },
41
- });
42
- }
43
-
44
- @Post('/deleteApp', { middleware: [checkPermission(SystemFuncCode.AppMangeWrite)] })
45
- async deleteApp() {
46
- return this.executeSysSimpleSQL('sys_app', KeysOfSimpleSQL.SIMPLE_DELETE, {
47
- validateCfg: {
48
- 'condition.id': [KeysOfValidators.REQUIRED, KeysOfValidators.NUMERIC],
49
- 'condition.app_code': [KeysOfValidators.REQUIRED, KeysOfValidators.STRING],
50
- },
51
- });
52
- }
53
- }