midway-fatcms 0.0.1-beta.17 → 0.0.1-beta.19
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintrc.json +3 -1
- package/dist/configuration.js +18 -7
- package/dist/controller/gateway/AsyncTaskController.js +3 -3
- package/dist/controller/gateway/DocGatewayController.js +1 -1
- package/dist/controller/gateway/PublicApiController.js +4 -6
- package/dist/controller/gateway/StaticController.js +25 -22
- package/dist/controller/helpers.controller.d.ts +1 -1
- package/dist/controller/manage/CrudStandardDesignApi.d.ts +1 -1
- package/dist/controller/manage/CrudStandardDesignApi.js +4 -16
- package/dist/controller/manage/DataDictManageApi.d.ts +1 -1
- package/dist/controller/manage/DeployManageApi.d.ts +1 -1
- package/dist/controller/manage/DeployManageApi.js +32 -30
- package/dist/controller/manage/MenuManageApi.js +1 -1
- package/dist/controller/manage/SuperAdminManageApi.d.ts +2 -2
- package/dist/controller/manage/SysConfigMangeApi.d.ts +1 -1
- package/dist/controller/manage/SysConfigMangeApi.js +3 -3
- package/dist/controller/manage/SystemInfoManageApi.d.ts +1 -1
- package/dist/controller/manage/SystemInfoManageApi.js +7 -1
- package/dist/controller/manage/UserAccountManageApi.d.ts +1 -1
- package/dist/controller/manage/WorkbenchMangeApi.js +1 -1
- package/dist/controller/myinfo/AuthController.js +1 -1
- package/dist/controller/render/AppRenderController.js +6 -2
- package/dist/controller/test.controller.d.ts +1 -1
- package/dist/controller/test.controller.js +4 -4
- package/dist/libs/crud-pro/models/ExecuteContext.d.ts +1 -1
- package/dist/libs/crud-pro/models/TransactionSqlServer.js +1 -1
- package/dist/libs/crud-pro/services/CrudProCachedCfgService.js +1 -1
- package/dist/libs/crud-pro/services/CrudProExecuteSqlService.js +7 -6
- package/dist/libs/crud-pro/services/CrudProGenSqlCondition.d.ts +1 -1
- package/dist/libs/crud-pro/services/CrudProGenSqlCondition.js +2 -4
- package/dist/libs/crud-pro/services/CrudProGenSqlService.js +6 -15
- package/dist/libs/crud-pro/services/CrudProOriginToExecuteSql.js +5 -4
- package/dist/libs/crud-pro/services/CrudProTableMetaService.js +2 -2
- package/dist/libs/crud-pro/utils/MixinUtils.js +1 -1
- package/dist/libs/crud-pro/utils/ValidateUtils.js +1 -1
- package/dist/libs/utils/fatcms-request.js +2 -2
- package/dist/middleware/forbidden.middleware.js +4 -20
- package/dist/middleware/global.middleware.js +1 -4
- package/dist/models/AsyncTaskModel.d.ts +2 -1
- package/dist/models/RedisKeys.d.ts +8 -0
- package/dist/models/RedisKeys.js +11 -0
- package/dist/schedule/index.d.ts +3 -3
- package/dist/schedule/index.js +3 -4
- package/dist/schedule/runSchedule.d.ts +11 -2
- package/dist/schedule/runSchedule.js +49 -15
- package/dist/schedule/scheduleNames.d.ts +8 -3
- package/dist/schedule/scheduleNames.js +12 -12
- package/dist/service/UserSessionService.js +2 -1
- package/dist/service/VisitStatService.d.ts +1 -1
- package/dist/service/VisitStatService.js +16 -25
- package/dist/service/asyncTask/AsyncTaskRunnerService.d.ts +9 -3
- package/dist/service/asyncTask/AsyncTaskRunnerService.js +57 -21
- package/dist/service/asyncTask/AsyncTaskService.d.ts +1 -1
- package/dist/service/asyncTask/AsyncTaskService.js +4 -3
- package/package.json +1 -1
- package/src/configuration.ts +23 -11
- package/src/controller/base/BaseApiController.ts +6 -6
- package/src/controller/gateway/AsyncTaskController.ts +17 -22
- package/src/controller/gateway/CrudMtdGatewayController.ts +7 -7
- package/src/controller/gateway/CrudStdGatewayController.ts +4 -4
- package/src/controller/gateway/DocGatewayController.ts +17 -17
- package/src/controller/gateway/FileController.ts +8 -9
- package/src/controller/gateway/ProxyApiGatewayController.ts +4 -4
- package/src/controller/gateway/PublicApiController.ts +19 -22
- package/src/controller/gateway/StaticController.ts +234 -264
- package/src/controller/helpers.controller.ts +1 -1
- package/src/controller/home.controller.ts +0 -5
- package/src/controller/manage/AnyApiMangeApi.ts +4 -4
- package/src/controller/manage/AppLogMangeApi.ts +3 -3
- package/src/controller/manage/AppMangeApi.ts +5 -5
- package/src/controller/manage/AppPageMangeApi.ts +3 -3
- package/src/controller/manage/AppSchemaHistoryApi.ts +1 -1
- package/src/controller/manage/CrudMethodsMangeApi.ts +3 -3
- package/src/controller/manage/CrudStandardDesignApi.ts +25 -77
- package/src/controller/manage/DataDictManageApi.ts +4 -4
- package/src/controller/manage/DeployManageApi.ts +84 -91
- package/src/controller/manage/DocLibManageApi.ts +3 -3
- package/src/controller/manage/DocManageApi.ts +3 -3
- package/src/controller/manage/MenuManageApi.ts +9 -14
- package/src/controller/manage/SuperAdminManageApi.ts +2 -10
- package/src/controller/manage/SysConfigMangeApi.ts +8 -11
- package/src/controller/manage/SystemInfoManageApi.ts +11 -6
- package/src/controller/manage/UserAccountManageApi.ts +2 -2
- package/src/controller/manage/WorkbenchMangeApi.ts +6 -6
- package/src/controller/myinfo/AuthController.ts +4 -8
- package/src/controller/render/AppRenderController.ts +8 -8
- package/src/controller/test.controller.ts +17 -17
- package/src/index.ts +0 -1
- package/src/libs/crud-pro/CrudPro.ts +0 -1
- package/src/libs/crud-pro/interfaces.ts +1 -3
- package/src/libs/crud-pro/models/ExecuteContext.ts +1 -4
- package/src/libs/crud-pro/models/ExecuteContextFunc.ts +1 -2
- package/src/libs/crud-pro/models/RequestModel.ts +1 -1
- package/src/libs/crud-pro/models/ResModel.ts +7 -12
- package/src/libs/crud-pro/models/SqlCfgModel.ts +1 -1
- package/src/libs/crud-pro/models/Transaction.ts +8 -9
- package/src/libs/crud-pro/models/TransactionPostgres.ts +1 -1
- package/src/libs/crud-pro/models/TransactionSqlServer.ts +8 -13
- package/src/libs/crud-pro/services/CrudProCachedCfgService.ts +1 -3
- package/src/libs/crud-pro/services/CrudProExecuteSqlService.ts +36 -48
- package/src/libs/crud-pro/services/CrudProGenSqlCondition.ts +19 -38
- package/src/libs/crud-pro/services/CrudProGenSqlService.ts +15 -32
- package/src/libs/crud-pro/services/CrudProOriginToExecuteSql.ts +23 -27
- package/src/libs/crud-pro/services/CrudProServiceBase.ts +1 -2
- package/src/libs/crud-pro/services/CrudProTableMetaService.ts +6 -14
- package/src/libs/crud-pro/utils/DateTimeUtils.ts +2 -2
- package/src/libs/crud-pro/utils/MixinUtils.ts +1 -1
- package/src/libs/crud-pro/utils/ValidateUtils.ts +1 -3
- package/src/libs/crud-pro/utils/pool/MySQLUtils.ts +1 -1
- package/src/libs/crud-pro/utils/pool/PostgresUtils.ts +3 -3
- package/src/libs/crud-pro/utils/pool/SqlServerUtils.ts +3 -3
- package/src/libs/global-config/global-config.ts +0 -5
- package/src/libs/utils/crypto-utils.ts +2 -4
- package/src/libs/utils/errorToString.ts +3 -8
- package/src/libs/utils/fatcms-request.ts +9 -21
- package/src/libs/utils/ordernum-utils.ts +2 -6
- package/src/libs/utils/parseConfig.ts +7 -15
- package/src/middleware/forbidden.middleware.ts +6 -25
- package/src/middleware/global.middleware.ts +10 -21
- package/src/models/AsyncTaskModel.ts +3 -2
- package/src/models/RedisKeys.ts +13 -0
- package/src/models/bizmodels.ts +1 -2
- package/src/schedule/index.ts +4 -6
- package/src/schedule/runSchedule.ts +65 -17
- package/src/schedule/scheduleNames.ts +12 -11
- package/src/service/UserSessionService.ts +5 -4
- package/src/service/VisitStatService.ts +55 -72
- package/src/service/anyapi/AnyApiService.ts +7 -7
- package/src/service/asyncTask/AsyncTaskRunnerService.ts +118 -87
- package/src/service/asyncTask/AsyncTaskService.ts +10 -10
- package/src/service/proxyapi/ProxyApiLoadService.ts +4 -3
|
@@ -1,328 +1,298 @@
|
|
|
1
1
|
import { All, Controller, Inject, Param } from '@midwayjs/core';
|
|
2
2
|
import { Context } from '@midwayjs/koa';
|
|
3
3
|
import { BaseApiController } from '../base/BaseApiController';
|
|
4
|
-
import * as _ from 'lodash';
|
|
5
4
|
import * as fs from 'fs/promises';
|
|
6
5
|
import * as fs2 from 'fs';
|
|
7
6
|
import * as path from 'path';
|
|
8
7
|
import * as https from 'https';
|
|
9
8
|
import { parseJsonObject } from '@/libs/utils/functions';
|
|
10
9
|
|
|
11
|
-
|
|
12
10
|
interface HttpGetRes {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
11
|
+
statusCode: number;
|
|
12
|
+
headers: any;
|
|
13
|
+
body: NodeJS.ReadableStream;
|
|
16
14
|
}
|
|
17
15
|
|
|
18
|
-
|
|
19
|
-
|
|
20
16
|
function getPathConfig(ossName: string) {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
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
|
+
};
|
|
35
31
|
}
|
|
36
32
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
33
|
// 404列表缓存
|
|
41
34
|
let notFoundList = new Set();
|
|
42
35
|
let notFoundListIsInit = false;
|
|
43
36
|
|
|
44
|
-
|
|
45
|
-
|
|
46
37
|
/**
|
|
47
38
|
* 静态文件代理功能
|
|
48
39
|
*/
|
|
49
40
|
@Controller('/ns/static')
|
|
50
41
|
export class StaticController extends BaseApiController {
|
|
51
|
-
|
|
52
|
-
|
|
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
|
+
}
|
|
53
59
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
60
|
+
private async initNotFoundList() {
|
|
61
|
+
if (notFoundListIsInit) {
|
|
62
|
+
return;
|
|
57
63
|
}
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
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
|
+
}
|
|
68
78
|
}
|
|
79
|
+
}
|
|
69
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
|
+
};
|
|
70
86
|
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
console.log(`已加载${notFoundList.size}个404记录`);
|
|
85
|
-
} catch (error) {
|
|
86
|
-
if (error.code !== 'ENOENT') {
|
|
87
|
-
console.error('读取404列表失败:', error);
|
|
88
|
-
}
|
|
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'];
|
|
89
100
|
}
|
|
101
|
+
}
|
|
102
|
+
} catch (error) {
|
|
103
|
+
console.debug('[StaticController]responseLocalFile', error);
|
|
90
104
|
}
|
|
91
105
|
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
try {
|
|
102
|
-
// 检查本地文件是否存在.头文件
|
|
103
|
-
const stats = await fs.stat(localHeaderPath);
|
|
104
|
-
if (stats.isFile()) {
|
|
105
|
-
const headerDataStr = await fs.readFile(localHeaderPath, 'utf8');
|
|
106
|
-
const headerData = parseJsonObject(headerDataStr)
|
|
107
|
-
if (headerData) {
|
|
108
|
-
headers["content-type"] = headerData["content-type"];
|
|
109
|
-
headers["content-length"] = headerData["content-length"];
|
|
110
|
-
headers["last-modified"] = headerData["last-modified"];
|
|
111
|
-
headers["etag"] = headerData["etag"];
|
|
112
|
-
headers["cache-control"] = headerData["cache-control"];
|
|
113
|
-
headers["accept-ranges"] = headerData["accept-ranges"];
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
} catch (error) {
|
|
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);
|
|
117
112
|
}
|
|
118
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
|
+
console.log(`返回本地文件: ${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
|
+
}
|
|
119
131
|
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
const stats = await fs.stat(localFilePath);
|
|
123
|
-
if (stats.isFile()) {
|
|
124
|
-
if (!headers['content-type']) {
|
|
125
|
-
headers['content-type'] = this.getMimeType(localFilePath);
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
const stream = fs2.createReadStream(localFilePath);
|
|
129
|
-
stream.setMaxListeners(50);
|
|
130
|
-
// const oldOn = stream.on.bind(stream);
|
|
131
|
-
// stream.on = (...args)=>{
|
|
132
|
-
// return oldOn(...args)
|
|
133
|
-
// }
|
|
134
|
-
|
|
135
|
-
console.log(`返回本地文件: ${relativePath}`);
|
|
136
|
-
this.ctx.status = 200;
|
|
137
|
-
this.ctx.set(headers);
|
|
138
|
-
|
|
132
|
+
return false;
|
|
133
|
+
}
|
|
139
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);
|
|
140
139
|
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
// 文件不存在,继续请求远程
|
|
146
|
-
}
|
|
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}`;
|
|
147
144
|
|
|
148
|
-
|
|
145
|
+
// 检查是否在404列表中
|
|
146
|
+
if (notFoundList.has(relativePath)) {
|
|
147
|
+
this.ctx.status = 404;
|
|
148
|
+
return this.ctx.render('500', { errorMsg: ' 远程文件不存在, 命中notFoundList' });
|
|
149
149
|
}
|
|
150
150
|
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
const PATH_CONFIG = getPathConfig(ossName);
|
|
156
|
-
|
|
151
|
+
// 检查并返回本地文件
|
|
152
|
+
if (await this.responseLocalFile(localFilePath, localHeaderPath, relativePath)) {
|
|
153
|
+
return;
|
|
154
|
+
}
|
|
157
155
|
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
const localHeaderPath = path.join(localDir, ossName, "headers", relativePath);
|
|
161
|
-
const remoteUrl = `${PATH_CONFIG.remoteBaseUrl}/${relativePath}`;
|
|
156
|
+
// 请求远程文件
|
|
157
|
+
console.log(`请求远程文件: ${remoteUrl}`);
|
|
162
158
|
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
this.ctx.status = 404;
|
|
166
|
-
return this.ctx.render('500', { errorMsg: ' 远程文件不存在, 命中notFoundList' });
|
|
167
|
-
}
|
|
159
|
+
try {
|
|
160
|
+
const remoteRes = await this.httpsGet(remoteUrl);
|
|
168
161
|
|
|
162
|
+
// 处理远程响应状态码
|
|
163
|
+
if (remoteRes.statusCode === 200) {
|
|
164
|
+
// 写入本地文件
|
|
165
|
+
await this.writeResponseToFile(remoteRes, localFilePath, localHeaderPath);
|
|
169
166
|
|
|
170
167
|
// 检查并返回本地文件
|
|
171
168
|
if (await this.responseLocalFile(localFilePath, localHeaderPath, relativePath)) {
|
|
172
|
-
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
// 请求远程文件
|
|
177
|
-
console.log(`请求远程文件: ${remoteUrl}`);
|
|
178
|
-
|
|
179
|
-
try {
|
|
180
|
-
const remoteRes = await this.httpsGet(remoteUrl);
|
|
181
|
-
|
|
182
|
-
// 处理远程响应状态码
|
|
183
|
-
if (remoteRes.statusCode === 200) {
|
|
184
|
-
|
|
185
|
-
// 写入本地文件
|
|
186
|
-
await this.writeResponseToFile(remoteRes, localFilePath, localHeaderPath);
|
|
187
|
-
|
|
188
|
-
// 检查并返回本地文件
|
|
189
|
-
if (await this.responseLocalFile(localFilePath, localHeaderPath, relativePath)) {
|
|
190
|
-
return;
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
} else if (remoteRes.statusCode === 404) {
|
|
195
|
-
// 记录404并返回
|
|
196
|
-
notFoundList.add(relativePath);
|
|
197
|
-
await this.saveNotFoundList();
|
|
198
|
-
console.log(`远程文件不存在,已记录404: ${relativePath}`);
|
|
199
|
-
this.ctx.status = 404;
|
|
200
|
-
return this.ctx.render('500', { errorMsg: ' 远程文件不存在,已记录404' });
|
|
201
|
-
} else {
|
|
202
|
-
// 其他状态码
|
|
203
|
-
const msg = `远程服务器返回状态码: ${remoteRes.statusCode}`;
|
|
204
|
-
console.log(msg);
|
|
205
|
-
this.ctx.status = 502;
|
|
206
|
-
return this.ctx.render('500', { errorMsg: msg });
|
|
207
|
-
}
|
|
208
|
-
} catch (err) {
|
|
209
|
-
const msg = `请求远程文件失败: ${err}`;
|
|
210
|
-
console.log(msg);
|
|
211
|
-
this.ctx.status = 500;
|
|
212
|
-
return this.ctx.render('500', { errorMsg: msg });
|
|
169
|
+
return;
|
|
213
170
|
}
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
171
|
+
} else if (remoteRes.statusCode === 404) {
|
|
172
|
+
// 记录404并返回
|
|
173
|
+
notFoundList.add(relativePath);
|
|
174
|
+
await this.saveNotFoundList();
|
|
175
|
+
console.log(`远程文件不存在,已记录404: ${relativePath}`);
|
|
176
|
+
this.ctx.status = 404;
|
|
177
|
+
return this.ctx.render('500', { errorMsg: ' 远程文件不存在,已记录404' });
|
|
178
|
+
} else {
|
|
179
|
+
// 其他状态码
|
|
180
|
+
const msg = `远程服务器返回状态码: ${remoteRes.statusCode}`;
|
|
181
|
+
console.log(msg);
|
|
182
|
+
this.ctx.status = 502;
|
|
183
|
+
return this.ctx.render('500', { errorMsg: msg });
|
|
184
|
+
}
|
|
185
|
+
} catch (err) {
|
|
186
|
+
const msg = `请求远程文件失败: ${err}`;
|
|
187
|
+
console.log(msg);
|
|
188
|
+
this.ctx.status = 500;
|
|
189
|
+
return this.ctx.render('500', { errorMsg: msg });
|
|
217
190
|
}
|
|
218
191
|
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
console.error('保存404列表失败:', error);
|
|
235
|
-
}
|
|
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
|
+
console.error('保存404列表失败:', error);
|
|
236
207
|
}
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
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);
|
|
250
223
|
});
|
|
251
|
-
}
|
|
252
|
-
|
|
253
|
-
// 新增:将响应body写入文件的函数
|
|
254
|
-
async writeResponseToFile(httpsGetRes: HttpGetRes, localFilePath: string, localHeaderPath: string): Promise<void> {
|
|
255
|
-
|
|
256
|
-
// 创建本地目录(如果不存在)
|
|
257
|
-
const localFileDir = path.dirname(localFilePath);
|
|
258
|
-
await fs.mkdir(localFileDir, { recursive: true });
|
|
224
|
+
});
|
|
225
|
+
}
|
|
259
226
|
|
|
260
|
-
|
|
261
|
-
|
|
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 });
|
|
262
232
|
|
|
263
|
-
|
|
264
|
-
|
|
233
|
+
const localHeaderDir = path.dirname(localHeaderPath);
|
|
234
|
+
await fs.mkdir(localHeaderDir, { recursive: true });
|
|
265
235
|
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
throw new Error(`HTTP请求失败,状态码: ${statusCode}`);
|
|
269
|
-
}
|
|
236
|
+
try {
|
|
237
|
+
const { statusCode, body } = httpsGetRes;
|
|
270
238
|
|
|
271
|
-
|
|
272
|
-
|
|
239
|
+
// 检查HTTP状态码
|
|
240
|
+
if (statusCode >= 400) {
|
|
241
|
+
throw new Error(`HTTP请求失败,状态码: ${statusCode}`);
|
|
242
|
+
}
|
|
273
243
|
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
body.pipe(fileStream);
|
|
244
|
+
// 创建可写流
|
|
245
|
+
const fileStream = fs2.createWriteStream(localFilePath);
|
|
277
246
|
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
247
|
+
// 使用管道将响应流写入文件
|
|
248
|
+
await new Promise((resolve, reject) => {
|
|
249
|
+
body.pipe(fileStream);
|
|
281
250
|
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
});
|
|
286
|
-
});
|
|
287
|
-
|
|
288
|
-
console.log(`文件已成功写入1: ${localFilePath}`);
|
|
289
|
-
|
|
290
|
-
await fs.writeFile(localHeaderPath, JSON.stringify(httpsGetRes.headers), 'utf8')
|
|
251
|
+
body.on('error', err => {
|
|
252
|
+
reject(new Error(`读取响应流失败: ${err.message}`));
|
|
253
|
+
});
|
|
291
254
|
|
|
292
|
-
|
|
255
|
+
fileStream.on('finish', resolve);
|
|
256
|
+
fileStream.on('error', err => {
|
|
257
|
+
reject(new Error(`写入文件失败: ${err.message}`));
|
|
258
|
+
});
|
|
259
|
+
});
|
|
293
260
|
|
|
261
|
+
console.log(`文件已成功写入1: ${localFilePath}`);
|
|
294
262
|
|
|
295
|
-
|
|
296
|
-
// 发生错误时删除可能存在的不完整文件
|
|
297
|
-
if (fs2.existsSync(localFilePath)) {
|
|
298
|
-
fs2.unlinkSync(localFilePath);
|
|
299
|
-
}
|
|
300
|
-
throw new Error(`下载过程中发生错误: ${err.message}`);
|
|
301
|
-
}
|
|
302
|
-
}
|
|
263
|
+
await fs.writeFile(localHeaderPath, JSON.stringify(httpsGetRes.headers), 'utf8');
|
|
303
264
|
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
'.json': 'application/json',
|
|
312
|
-
'.png': 'image/png',
|
|
313
|
-
'.jpg': 'image/jpg',
|
|
314
|
-
'.gif': 'image/gif',
|
|
315
|
-
'.svg': 'image/svg+xml',
|
|
316
|
-
'.woff': 'font/woff',
|
|
317
|
-
'.woff2': 'font/woff2',
|
|
318
|
-
'.ttf': 'font/ttf',
|
|
319
|
-
'.eot': 'application/vnd.ms-fontobject',
|
|
320
|
-
'.txt': 'text/plain',
|
|
321
|
-
'.pdf': 'application/pdf',
|
|
322
|
-
'.mp4': 'video/mp4',
|
|
323
|
-
'.ico': 'image/x-icon'
|
|
324
|
-
};
|
|
325
|
-
return mimeTypes[extname] || 'application/octet-stream';
|
|
265
|
+
console.log(`文件已成功写入2: ${localHeaderPath}`);
|
|
266
|
+
} catch (err) {
|
|
267
|
+
// 发生错误时删除可能存在的不完整文件
|
|
268
|
+
if (fs2.existsSync(localFilePath)) {
|
|
269
|
+
fs2.unlinkSync(localFilePath);
|
|
270
|
+
}
|
|
271
|
+
throw new Error(`下载过程中发生错误: ${err.message}`);
|
|
326
272
|
}
|
|
327
|
-
|
|
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
|
+
}
|
|
328
298
|
}
|
|
@@ -47,8 +47,6 @@ export class HomeController extends BaseApiController {
|
|
|
47
47
|
return this.ctx.renderString(html_content, { workbenchInfo, userInfo, utils }, { viewEngine: 'ejs' });
|
|
48
48
|
}
|
|
49
49
|
|
|
50
|
-
|
|
51
|
-
|
|
52
50
|
@Get('/robots.txt')
|
|
53
51
|
async robots(): Promise<string> {
|
|
54
52
|
return `User-agent: * \nDisallow: /ns/api/manage/`;
|
|
@@ -63,7 +61,4 @@ export class HomeController extends BaseApiController {
|
|
|
63
61
|
// ctx.set('Content-Type', 'image/jpeg');
|
|
64
62
|
// ctx.body = buffer;
|
|
65
63
|
// }
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
64
|
}
|
|
@@ -7,13 +7,13 @@ import { SystemFuncCode } from '@/models/SystemPerm';
|
|
|
7
7
|
import { SystemTables } from '@/models/SystemTables';
|
|
8
8
|
import { ISysAnyApiEntity } from '@/models/SystemEntities';
|
|
9
9
|
import * as md5 from 'md5';
|
|
10
|
-
import {parseJsonObject} from
|
|
10
|
+
import { parseJsonObject } from '@/libs/utils/functions';
|
|
11
11
|
|
|
12
12
|
function fixBodyData(body: any) {
|
|
13
13
|
const dataObj: any = (body.data || {}) as ISysAnyApiEntity;
|
|
14
14
|
const parsedOthers = parseJsonObject(dataObj.others);
|
|
15
15
|
dataObj.func_code_md5 = md5(dataObj.func_code || '');
|
|
16
|
-
dataObj.req_params = parsedOthers?.req_params?.length || 0;
|
|
16
|
+
dataObj.req_params = parsedOthers?.req_params?.length || 0; // 参数个数
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
@Controller('/ns/api/manage/anyapi', { middleware: [checkPermission(SystemFuncCode.AnyApiManageRead)] })
|
|
@@ -31,7 +31,7 @@ export class AnyApiMangeApi extends BaseApiController {
|
|
|
31
31
|
return this.executeSysSimpleSQL(SystemTables.sys_anyapi, KeysOfSimpleSQL.SIMPLE_QUERY_ONE);
|
|
32
32
|
}
|
|
33
33
|
|
|
34
|
-
@Post('/createAnyApi',
|
|
34
|
+
@Post('/createAnyApi', { middleware: [checkPermission(SystemFuncCode.AnyApiManageWrite)] })
|
|
35
35
|
async createAnyApi() {
|
|
36
36
|
fixBodyData(this.ctx.request.body);
|
|
37
37
|
|
|
@@ -44,7 +44,7 @@ export class AnyApiMangeApi extends BaseApiController {
|
|
|
44
44
|
});
|
|
45
45
|
}
|
|
46
46
|
|
|
47
|
-
@Post('/updateAnyApi'
|
|
47
|
+
@Post('/updateAnyApi', { middleware: [checkPermission(SystemFuncCode.AnyApiManageWrite)] })
|
|
48
48
|
async updateAnyApi() {
|
|
49
49
|
fixBodyData(this.ctx.request.body);
|
|
50
50
|
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { Controller, Inject, Post } from '@midwayjs/core';
|
|
2
2
|
import { Context } from '@midwayjs/koa';
|
|
3
|
-
import { KeysOfSimpleSQL, KeysOfValidators } from '
|
|
3
|
+
import { KeysOfSimpleSQL, KeysOfValidators } from '@/libs/crud-pro/models/keys';
|
|
4
4
|
import { BaseApiController } from '../base/BaseApiController';
|
|
5
|
-
import { checkPermission } from '
|
|
6
|
-
import {SystemFuncCode} from
|
|
5
|
+
import { checkPermission } from '@/middleware/permission.middleware';
|
|
6
|
+
import { SystemFuncCode } from '@/models/SystemPerm';
|
|
7
7
|
|
|
8
8
|
@Controller('/ns/api/manage/appLog', { middleware: [checkPermission(SystemFuncCode.AppMangeRead)] })
|
|
9
9
|
export class AppLogMangeApi extends BaseApiController {
|