midway-fatcms 0.0.1-beta.64 → 0.0.1-beta.66
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/dist/config/config.default.js +7 -0
- package/dist/controller/base/BaseApiController.d.ts +5 -0
- package/dist/controller/base/BaseApiController.js +25 -0
- package/dist/controller/gateway/CrudStdGatewayController.d.ts +1 -1
- package/dist/controller/gateway/CrudStdGatewayController.js +36 -10
- package/dist/controller/gateway/FileController.js +2 -1
- package/dist/controller/gateway/PublicApiController.d.ts +1 -0
- package/dist/controller/gateway/PublicApiController.js +64 -28
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/interface.d.ts +2 -0
- package/dist/libs/crud-pro/exceptions.d.ts +2 -0
- package/dist/libs/crud-pro/exceptions.js +2 -0
- package/dist/libs/crud-pro/models/keys.d.ts +1 -1
- package/dist/libs/crud-pro/models/keys.js +1 -1
- package/dist/libs/crud-pro/services/CrudProOriginToExecuteSql.js +6 -1
- package/dist/libs/crud-pro/utils/sqlConvert/convertColumnName.js +14 -0
- package/dist/libs/utils/AsymmetricCrypto.d.ts +76 -0
- package/dist/libs/utils/AsymmetricCrypto.js +261 -0
- package/dist/libs/utils/format-url.d.ts +2 -0
- package/dist/libs/utils/format-url.js +13 -0
- package/dist/libs/utils/render-utils.d.ts +16 -7
- package/dist/libs/utils/render-utils.js +27 -6
- package/dist/middleware/global.middleware.js +7 -0
- package/dist/models/SystemEntities.d.ts +34 -0
- package/dist/models/SystemEntities.js +22 -1
- package/dist/models/WorkbenchInfoTools.d.ts +7 -0
- package/dist/models/WorkbenchInfoTools.js +20 -0
- package/dist/models/bizmodels.d.ts +9 -0
- package/dist/models/contextLogger.d.ts +2 -0
- package/dist/models/contextLogger.js +8 -1
- package/dist/models/userSession.d.ts +2 -0
- package/dist/models/userSession.js +2 -0
- package/dist/schedule/anonymousContext.js +2 -0
- package/dist/service/AuthService.js +7 -0
- package/dist/service/EnumInfoService.d.ts +1 -1
- package/dist/service/EnumInfoService.js +32 -26
- package/dist/service/UserSessionService.d.ts +6 -1
- package/dist/service/UserSessionService.js +26 -17
- package/dist/service/WorkbenchService.d.ts +1 -0
- package/dist/service/WorkbenchService.js +27 -1
- package/dist/service/base/cache/CacheServiceFactory.d.ts +20 -0
- package/dist/service/base/cache/CacheServiceFactory.js +67 -0
- package/dist/service/base/cache/FatcmsBaseCtxCache.d.ts +19 -0
- package/dist/service/base/cache/FatcmsBaseCtxCache.js +38 -0
- package/dist/service/base/cache/FatcmsBaseDiskCache.d.ts +24 -0
- package/dist/service/base/cache/FatcmsBaseDiskCache.js +81 -0
- package/dist/service/base/cache/FatcmsBaseMemoryCache.d.ts +18 -0
- package/dist/service/base/cache/FatcmsBaseMemoryCache.js +66 -0
- package/dist/service/base/cache/FatcmsBaseNoneCache.d.ts +10 -0
- package/dist/service/base/cache/FatcmsBaseNoneCache.js +19 -0
- package/dist/service/base/{RedisCacheService.d.ts → cache/FatcmsBaseRedisCache.d.ts} +6 -6
- package/dist/service/base/cache/FatcmsBaseRedisCache.js +39 -0
- package/dist/service/crudstd/CrudStdService.d.ts +6 -4
- package/dist/service/crudstd/CrudStdService.js +24 -10
- package/dist/service/curd/CurdMixByDictService.d.ts +1 -2
- package/dist/service/curd/CurdMixByDictService.js +12 -8
- package/dist/service/curd/CurdMixByLinkToCustomService.d.ts +1 -2
- package/dist/service/curd/CurdMixByLinkToCustomService.js +17 -13
- package/dist/service/curd/CurdMixBySysConfigService.d.ts +4 -0
- package/dist/service/curd/CurdMixBySysConfigService.js +50 -10
- package/dist/service/curd/CurdMixByWorkbenchService.d.ts +2 -1
- package/dist/service/curd/CurdMixByWorkbenchService.js +30 -22
- package/package.json +1 -1
- package/src/config/config.default.ts +8 -0
- package/src/controller/base/BaseApiController.ts +39 -0
- package/src/controller/gateway/CrudStdGatewayController.ts +42 -10
- package/src/controller/gateway/FileController.ts +2 -2
- package/src/controller/gateway/PublicApiController.ts +72 -28
- package/src/controller/manage/DocLibManageApi.ts +5 -5
- package/src/controller/manage/FileManageApi.ts +5 -5
- package/src/controller/manage/MenuManageApi.ts +4 -4
- package/src/index.ts +1 -1
- package/src/interface.ts +2 -0
- package/src/libs/crud-pro/exceptions.ts +2 -0
- package/src/libs/crud-pro/models/keys.ts +6 -6
- package/src/libs/crud-pro/services/CrudProOriginToExecuteSql.ts +7 -1
- package/src/libs/crud-pro/utils/sqlConvert/convertColumnName.ts +18 -0
- package/src/libs/utils/AsymmetricCrypto.ts +310 -0
- package/src/libs/utils/format-url.ts +16 -0
- package/src/libs/utils/render-utils.ts +56 -15
- package/src/middleware/global.middleware.ts +8 -0
- package/src/models/SystemEntities.ts +43 -0
- package/src/models/WorkbenchInfoTools.ts +18 -0
- package/src/models/bizmodels.ts +12 -0
- package/src/models/contextLogger.ts +10 -1
- package/src/models/userSession.ts +4 -0
- package/src/schedule/anonymousContext.ts +2 -0
- package/src/service/AuthService.ts +11 -0
- package/src/service/EnumInfoService.ts +35 -22
- package/src/service/UserSessionService.ts +29 -18
- package/src/service/WorkbenchService.ts +42 -2
- package/src/service/base/cache/CacheServiceFactory.ts +66 -0
- package/src/service/base/cache/FatcmsBaseCtxCache.ts +47 -0
- package/src/service/base/cache/FatcmsBaseDiskCache.ts +87 -0
- package/src/service/base/cache/FatcmsBaseMemoryCache.ts +74 -0
- package/src/service/base/cache/FatcmsBaseNoneCache.ts +24 -0
- package/src/service/base/cache/FatcmsBaseRedisCache.ts +48 -0
- package/src/service/crudstd/CrudStdService.ts +28 -12
- package/src/service/curd/CurdMixByAccountService.ts +1 -0
- package/src/service/curd/CurdMixByDictService.ts +14 -8
- package/src/service/curd/CurdMixByLinkToCustomService.ts +21 -12
- package/src/service/curd/CurdMixBySysConfigService.ts +60 -11
- package/src/service/curd/CurdMixByWorkbenchService.ts +31 -24
- package/src/service/proxyapi/WeightedRandom.ts +1 -1
- package/src/service/proxyapi/WeightedRoundRobin.ts +1 -1
- package/dist/service/base/RedisCacheService.js +0 -57
- package/src/service/base/RedisCacheService.ts +0 -42
|
@@ -0,0 +1,261 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AsymmetricCrypto = void 0;
|
|
4
|
+
function getCrypto() {
|
|
5
|
+
if (typeof crypto !== 'undefined' && crypto.subtle) {
|
|
6
|
+
// 浏览器环境或Node.js 19+的global.crypto
|
|
7
|
+
return crypto;
|
|
8
|
+
}
|
|
9
|
+
else if (typeof global !== 'undefined') {
|
|
10
|
+
// Node.js环境
|
|
11
|
+
if (global.crypto && global.crypto.subtle) {
|
|
12
|
+
// Node.js 19+
|
|
13
|
+
return global.crypto;
|
|
14
|
+
}
|
|
15
|
+
// @ts-ignore
|
|
16
|
+
else if (global.crypto && global.crypto.webcrypto && global.crypto.webcrypto.subtle) {
|
|
17
|
+
// Node.js 16+
|
|
18
|
+
// @ts-ignore
|
|
19
|
+
return global.crypto.webcrypto;
|
|
20
|
+
}
|
|
21
|
+
else {
|
|
22
|
+
// Node.js 16-18,使用crypto.webcrypto
|
|
23
|
+
const nodeCrypto = require('crypto');
|
|
24
|
+
if (nodeCrypto.webcrypto && nodeCrypto.webcrypto.subtle) {
|
|
25
|
+
return nodeCrypto.webcrypto;
|
|
26
|
+
}
|
|
27
|
+
throw new Error('Node.js版本低于16或缺少webcrypto支持');
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
throw new Error('当前环境不支持Web Crypto API');
|
|
31
|
+
}
|
|
32
|
+
class AsymmetricCrypto {
|
|
33
|
+
/**
|
|
34
|
+
* 生成RSA密钥对并返回字符串格式的公钥和私钥
|
|
35
|
+
* @param {number} modulusLength - 密钥长度,默认2048
|
|
36
|
+
* @returns {Promise<{publicKey: string, privateKey: string}>} PEM格式的密钥字符串
|
|
37
|
+
*/
|
|
38
|
+
static async generateKeyPair(modulusLength = 2048) {
|
|
39
|
+
const crypto = getCrypto();
|
|
40
|
+
try {
|
|
41
|
+
// 生成密钥对
|
|
42
|
+
const keyPair = await crypto.subtle.generateKey({
|
|
43
|
+
name: "RSA-OAEP",
|
|
44
|
+
modulusLength,
|
|
45
|
+
publicExponent: new Uint8Array([0x01, 0x00, 0x01]),
|
|
46
|
+
hash: "SHA-256",
|
|
47
|
+
}, true, // 是否可导出
|
|
48
|
+
["encrypt", "decrypt"]);
|
|
49
|
+
// 导出公钥为PEM格式字符串
|
|
50
|
+
const publicKeyDer = await crypto.subtle.exportKey("spki", keyPair.publicKey);
|
|
51
|
+
const publicKeyPem = this.derToPem(publicKeyDer, 'PUBLIC');
|
|
52
|
+
// 导出私钥为PEM格式字符串
|
|
53
|
+
const privateKeyDer = await crypto.subtle.exportKey("pkcs8", keyPair.privateKey);
|
|
54
|
+
const privateKeyPem = this.derToPem(privateKeyDer, 'PRIVATE');
|
|
55
|
+
return {
|
|
56
|
+
publicKey: publicKeyPem,
|
|
57
|
+
privateKey: privateKeyPem
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
catch (error) {
|
|
61
|
+
throw new Error(`生成密钥对失败: ${error.message}`);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* 使用公钥加密字符串
|
|
66
|
+
* @param {string} publicKeyPem - PEM格式的公钥字符串
|
|
67
|
+
* @param {string} data - 要加密的字符串数据
|
|
68
|
+
* @returns {Promise<string>} Base64编码的加密字符串
|
|
69
|
+
*/
|
|
70
|
+
static async encrypt(publicKeyPem, data) {
|
|
71
|
+
const crypto = getCrypto();
|
|
72
|
+
try {
|
|
73
|
+
// 导入公钥
|
|
74
|
+
const publicKey = await this.importPublicKey(publicKeyPem);
|
|
75
|
+
// 转换数据为Uint8Array
|
|
76
|
+
const encoder = new TextEncoder();
|
|
77
|
+
const dataBuffer = encoder.encode(data);
|
|
78
|
+
// 检查数据长度(RSA-OAEP有最大长度限制)
|
|
79
|
+
const maxLength = this.getMaxEncryptLength(publicKeyPem);
|
|
80
|
+
if (dataBuffer.length > maxLength) {
|
|
81
|
+
throw new Error(`数据过长,最大支持${maxLength}字节,当前${dataBuffer.length}字节`);
|
|
82
|
+
}
|
|
83
|
+
// 加密数据
|
|
84
|
+
const encrypted = await crypto.subtle.encrypt({
|
|
85
|
+
name: "RSA-OAEP"
|
|
86
|
+
}, publicKey, dataBuffer);
|
|
87
|
+
// 转换为Base64字符串
|
|
88
|
+
return this.arrayBufferToBase64(encrypted);
|
|
89
|
+
}
|
|
90
|
+
catch (error) {
|
|
91
|
+
throw new Error(`加密失败: ${error.message}`);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* 使用私钥解密字符串
|
|
96
|
+
* @param {string} privateKeyPem - PEM格式的私钥字符串
|
|
97
|
+
* @param {string} encryptedData - Base64编码的加密字符串
|
|
98
|
+
* @returns {Promise<string>} 解密后的原始字符串
|
|
99
|
+
*/
|
|
100
|
+
static async decrypt(privateKeyPem, encryptedData) {
|
|
101
|
+
const crypto = getCrypto();
|
|
102
|
+
try {
|
|
103
|
+
// 导入私钥
|
|
104
|
+
const privateKey = await this.importPrivateKey(privateKeyPem);
|
|
105
|
+
// 转换Base64字符串为ArrayBuffer
|
|
106
|
+
const encryptedBuffer = this.base64ToArrayBuffer(encryptedData);
|
|
107
|
+
// 解密数据
|
|
108
|
+
const decrypted = await crypto.subtle.decrypt({
|
|
109
|
+
name: "RSA-OAEP"
|
|
110
|
+
}, privateKey, encryptedBuffer);
|
|
111
|
+
// 转换回字符串
|
|
112
|
+
const decoder = new TextDecoder();
|
|
113
|
+
return decoder.decode(decrypted);
|
|
114
|
+
}
|
|
115
|
+
catch (error) {
|
|
116
|
+
throw new Error(`解密失败: ${error.message}`);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* 导入PEM格式的公钥字符串为CryptoKey对象
|
|
121
|
+
* @param {string} publicKeyPem - PEM格式的公钥字符串
|
|
122
|
+
* @returns {Promise<CryptoKey>}
|
|
123
|
+
*/
|
|
124
|
+
static async importPublicKey(publicKeyPem) {
|
|
125
|
+
const crypto = getCrypto();
|
|
126
|
+
try {
|
|
127
|
+
// PEM转DER
|
|
128
|
+
const der = this.pemToDer(publicKeyPem);
|
|
129
|
+
// 导入密钥
|
|
130
|
+
return await crypto.subtle.importKey("spki", der, {
|
|
131
|
+
name: "RSA-OAEP",
|
|
132
|
+
hash: "SHA-256"
|
|
133
|
+
}, true, ["encrypt"]);
|
|
134
|
+
}
|
|
135
|
+
catch (error) {
|
|
136
|
+
throw new Error(`导入公钥失败: ${error.message}`);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* 导入PEM格式的私钥字符串为CryptoKey对象
|
|
141
|
+
* @param {string} privateKeyPem - PEM格式的私钥字符串
|
|
142
|
+
* @returns {Promise<CryptoKey>}
|
|
143
|
+
*/
|
|
144
|
+
static async importPrivateKey(privateKeyPem) {
|
|
145
|
+
const crypto = getCrypto();
|
|
146
|
+
try {
|
|
147
|
+
// PEM转DER
|
|
148
|
+
const der = this.pemToDer(privateKeyPem);
|
|
149
|
+
// 导入密钥
|
|
150
|
+
return await crypto.subtle.importKey("pkcs8", der, {
|
|
151
|
+
name: "RSA-OAEP",
|
|
152
|
+
hash: "SHA-256"
|
|
153
|
+
}, true, ["decrypt"]);
|
|
154
|
+
}
|
|
155
|
+
catch (error) {
|
|
156
|
+
throw new Error(`导入私钥失败: ${error.message}`);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* 获取公钥支持的最大加密长度(字节数)
|
|
161
|
+
* @param {string} publicKeyPem - PEM格式的公钥字符串
|
|
162
|
+
* @returns {number} 最大加密字节数
|
|
163
|
+
*/
|
|
164
|
+
static getMaxEncryptLength(publicKeyPem) {
|
|
165
|
+
// 简单估算最大加密长度
|
|
166
|
+
// RSA-OAEP最大加密长度 = modulusLength/8 - 2*hashLength/8 - 2
|
|
167
|
+
// 这里通过PEM字符串长度来估算密钥长度
|
|
168
|
+
// 提取Base64内容
|
|
169
|
+
const base64Data = publicKeyPem
|
|
170
|
+
.replace(/-----BEGIN PUBLIC KEY-----/, '')
|
|
171
|
+
.replace(/-----END PUBLIC KEY-----/, '')
|
|
172
|
+
.replace(/\s+/g, '');
|
|
173
|
+
// Base64解码获取DER长度
|
|
174
|
+
const derLength = atob(base64Data).length;
|
|
175
|
+
// 典型长度对应关系:
|
|
176
|
+
if (derLength <= 294) { // 2048位密钥DER长度约294字节
|
|
177
|
+
return 190; // 2048位:190字节
|
|
178
|
+
}
|
|
179
|
+
else if (derLength <= 422) { // 3072位密钥DER长度约422字节
|
|
180
|
+
return 318; // 3072位:318字节
|
|
181
|
+
}
|
|
182
|
+
else { // 4096位
|
|
183
|
+
return 446; // 4096位:446字节
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
* 将DER格式转换为PEM格式字符串
|
|
188
|
+
* @param {ArrayBuffer} der - DER格式的密钥数据
|
|
189
|
+
* @param {string} type - 密钥类型 ('PUBLIC' 或 'PRIVATE')
|
|
190
|
+
* @returns {string} PEM格式的密钥字符串
|
|
191
|
+
*/
|
|
192
|
+
static derToPem(der, type) {
|
|
193
|
+
const base64 = this.arrayBufferToBase64(der);
|
|
194
|
+
// 将Base64字符串分割为64字符一行
|
|
195
|
+
const wrapped = base64.match(/.{1,64}/g).join('\n');
|
|
196
|
+
if (type === 'PUBLIC') {
|
|
197
|
+
return `-----BEGIN PUBLIC KEY-----\n${wrapped}\n-----END PUBLIC KEY-----`;
|
|
198
|
+
}
|
|
199
|
+
else {
|
|
200
|
+
return `-----BEGIN PRIVATE KEY-----\n${wrapped}\n-----END PRIVATE KEY-----`;
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
/**
|
|
204
|
+
* 将PEM格式字符串转换为DER格式
|
|
205
|
+
* @param {string} pem - PEM格式的密钥字符串
|
|
206
|
+
* @returns {ArrayBuffer} DER格式的密钥数据
|
|
207
|
+
*/
|
|
208
|
+
static pemToDer(pem) {
|
|
209
|
+
// 移除PEM头部、尾部和所有空白字符
|
|
210
|
+
const base64 = pem
|
|
211
|
+
.replace(/-----BEGIN (?:PUBLIC|PRIVATE) KEY-----/, '')
|
|
212
|
+
.replace(/-----END (?:PUBLIC|PRIVATE) KEY-----/, '')
|
|
213
|
+
.replace(/\s+/g, '');
|
|
214
|
+
return this.base64ToArrayBuffer(base64);
|
|
215
|
+
}
|
|
216
|
+
/**
|
|
217
|
+
* ArrayBuffer转Base64字符串
|
|
218
|
+
* @param {ArrayBuffer} buffer
|
|
219
|
+
* @returns {string}
|
|
220
|
+
*/
|
|
221
|
+
static arrayBufferToBase64(buffer) {
|
|
222
|
+
const bytes = new Uint8Array(buffer);
|
|
223
|
+
let binary = '';
|
|
224
|
+
for (let i = 0; i < bytes.byteLength; i++) {
|
|
225
|
+
binary += String.fromCharCode(bytes[i]);
|
|
226
|
+
}
|
|
227
|
+
return btoa(binary);
|
|
228
|
+
}
|
|
229
|
+
/**
|
|
230
|
+
* Base64字符串转ArrayBuffer
|
|
231
|
+
* @param {string} base64
|
|
232
|
+
* @returns {ArrayBuffer}
|
|
233
|
+
*/
|
|
234
|
+
static base64ToArrayBuffer(base64) {
|
|
235
|
+
const binaryString = atob(base64);
|
|
236
|
+
const bytes = new Uint8Array(binaryString.length);
|
|
237
|
+
for (let i = 0; i < binaryString.length; i++) {
|
|
238
|
+
bytes[i] = binaryString.charCodeAt(i);
|
|
239
|
+
}
|
|
240
|
+
return bytes.buffer;
|
|
241
|
+
}
|
|
242
|
+
/**
|
|
243
|
+
* 验证PEM格式的密钥字符串
|
|
244
|
+
* @param {string} pem - PEM格式的密钥字符串
|
|
245
|
+
* @param {'PUBLIC'|'PRIVATE'} expectedType - 期望的密钥类型
|
|
246
|
+
* @returns {boolean} 是否为有效的PEM格式
|
|
247
|
+
*/
|
|
248
|
+
static validatePemFormat(pem, expectedType) {
|
|
249
|
+
if (typeof pem !== 'string')
|
|
250
|
+
return false;
|
|
251
|
+
const publicKeyPattern = /^-----BEGIN PUBLIC KEY-----\n([A-Za-z0-9+/=\n]+)\n-----END PUBLIC KEY-----$/;
|
|
252
|
+
const privateKeyPattern = /^-----BEGIN PRIVATE KEY-----\n([A-Za-z0-9+/=\n]+)\n-----END PRIVATE KEY-----$/;
|
|
253
|
+
if (expectedType === 'PUBLIC') {
|
|
254
|
+
return publicKeyPattern.test(pem);
|
|
255
|
+
}
|
|
256
|
+
else {
|
|
257
|
+
return privateKeyPattern.test(pem);
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
exports.AsymmetricCrypto = AsymmetricCrypto;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.formatHost = void 0;
|
|
4
|
+
function formatHost(host) {
|
|
5
|
+
if (host.endsWith(':80')) {
|
|
6
|
+
host = host.slice(0, -3);
|
|
7
|
+
}
|
|
8
|
+
if (host.endsWith(':443')) {
|
|
9
|
+
host = host.slice(0, -4);
|
|
10
|
+
}
|
|
11
|
+
return host;
|
|
12
|
+
}
|
|
13
|
+
exports.formatHost = formatHost;
|
|
@@ -1,19 +1,28 @@
|
|
|
1
1
|
import { Context } from '@midwayjs/koa';
|
|
2
|
+
import { ISessionInfo } from '../../models/userSession';
|
|
3
|
+
interface IFileElement {
|
|
4
|
+
fileUrl: string;
|
|
5
|
+
fileType?: string;
|
|
6
|
+
isModule?: boolean;
|
|
7
|
+
}
|
|
2
8
|
interface IRenderUtilsProps {
|
|
3
9
|
ctx: Context;
|
|
4
10
|
package_assets: any;
|
|
5
11
|
workbenchInfo: any;
|
|
6
|
-
userInfo?:
|
|
12
|
+
userInfo?: ISessionInfo;
|
|
7
13
|
appInfo?: any;
|
|
8
14
|
fatcmscsrftoken: string;
|
|
9
15
|
}
|
|
10
16
|
declare class RenderUtils {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
+
readonly ctx: Context;
|
|
18
|
+
readonly fileList: IFileElement[];
|
|
19
|
+
readonly workbenchInfo: any;
|
|
20
|
+
readonly userInfo: ISessionInfo;
|
|
21
|
+
readonly appInfo: any;
|
|
22
|
+
readonly cookieInfo: any;
|
|
23
|
+
readonly fatcmscsrftoken: string;
|
|
24
|
+
readonly isMobileUserAgent: boolean;
|
|
25
|
+
readonly isMobileByQuery: boolean;
|
|
17
26
|
constructor(props: IRenderUtilsProps);
|
|
18
27
|
renderCsrfToken(): string;
|
|
19
28
|
renderUserInfo(): string;
|
|
@@ -37,14 +37,34 @@ function parseCookie(cookieStr) {
|
|
|
37
37
|
}
|
|
38
38
|
return cookies;
|
|
39
39
|
}
|
|
40
|
+
function isMobileUserAgent(userAgent = '') {
|
|
41
|
+
// 空值处理
|
|
42
|
+
if (!userAgent)
|
|
43
|
+
return false;
|
|
44
|
+
// 转为小写统一匹配
|
|
45
|
+
const ua = userAgent.toLowerCase();
|
|
46
|
+
// 【核心】移动端关键词(覆盖主流系统)
|
|
47
|
+
const mobileKeywords = /android|iphone|ipod|ios|mobile|blackberry|iemobile|opera mini|windows phone|harmonyos/i;
|
|
48
|
+
// 【排除项】平板/PC关键词(避免误判)
|
|
49
|
+
const excludeKeywords = /ipad|tablet|playbook|kindle|pc|windows nt|macintosh|linux x86_64/i;
|
|
50
|
+
// 判断规则:包含移动端关键词 + 不包含排除项关键词
|
|
51
|
+
const isMatchMobile = mobileKeywords.test(ua);
|
|
52
|
+
const isExclude = excludeKeywords.test(ua);
|
|
53
|
+
return isMatchMobile && !isExclude;
|
|
54
|
+
}
|
|
40
55
|
class RenderUtils {
|
|
41
56
|
constructor(props) {
|
|
42
|
-
var _a, _b;
|
|
57
|
+
var _a, _b, _c, _d;
|
|
43
58
|
this.ctx = props.ctx;
|
|
59
|
+
const query = ((_a = props.ctx) === null || _a === void 0 ? void 0 : _a.query) || {};
|
|
60
|
+
const headers = ((_b = props.ctx) === null || _b === void 0 ? void 0 : _b.headers) || {};
|
|
44
61
|
this.workbenchInfo = props.workbenchInfo || {};
|
|
45
62
|
this.userInfo = props.userInfo || {};
|
|
46
63
|
this.appInfo = props.appInfo || {};
|
|
47
64
|
this.fatcmscsrftoken = props.fatcmscsrftoken;
|
|
65
|
+
this.cookieInfo = parseCookie(headers === null || headers === void 0 ? void 0 : headers.cookie);
|
|
66
|
+
this.isMobileUserAgent = isMobileUserAgent(headers['user-agent'] || '');
|
|
67
|
+
this.isMobileByQuery = `${query['__is_mobile_request__']}` === 'true';
|
|
48
68
|
const packageAssets = (0, functions_1.parseJsonObject)(props.package_assets) || {};
|
|
49
69
|
const fileList = _.get(packageAssets, 'data.fileList');
|
|
50
70
|
if (Array.isArray(fileList)) {
|
|
@@ -58,8 +78,8 @@ class RenderUtils {
|
|
|
58
78
|
console.info(time +
|
|
59
79
|
' 解析fileList为空==>' +
|
|
60
80
|
JSON.stringify({
|
|
61
|
-
workbench_code: (
|
|
62
|
-
app_code: (
|
|
81
|
+
workbench_code: (_c = this.workbenchInfo) === null || _c === void 0 ? void 0 : _c.workbench_code,
|
|
82
|
+
app_code: (_d = this.appInfo) === null || _d === void 0 ? void 0 : _d.app_code,
|
|
63
83
|
}));
|
|
64
84
|
}
|
|
65
85
|
}
|
|
@@ -67,7 +87,9 @@ class RenderUtils {
|
|
|
67
87
|
return `<script>window.__fatcmscsrftoken = "${this.fatcmscsrftoken}";</script>`;
|
|
68
88
|
}
|
|
69
89
|
renderUserInfo() {
|
|
70
|
-
|
|
90
|
+
const userInfoClone = { ...this.userInfo };
|
|
91
|
+
delete userInfoClone.privateKey;
|
|
92
|
+
return `<script>window.__user_info = ${JSON.stringify(userInfoClone)} </script>`;
|
|
71
93
|
}
|
|
72
94
|
renderWorkbenchInfo() {
|
|
73
95
|
const infoPick = _.pick(this.workbenchInfo, ['id', 'workbench_code', 'workbench_name', 'workbench_domain', 'workbench_desc', 'config_type', 'config_content']);
|
|
@@ -78,9 +100,8 @@ class RenderUtils {
|
|
|
78
100
|
return `<script>window.__app_info = ${JSON.stringify(infoPick)}</script>`;
|
|
79
101
|
}
|
|
80
102
|
renderCookieInfo(keys) {
|
|
81
|
-
var _a;
|
|
82
103
|
try {
|
|
83
|
-
const cookies =
|
|
104
|
+
const cookies = this.cookieInfo;
|
|
84
105
|
const cookieObj = {};
|
|
85
106
|
if (typeof keys === 'string') {
|
|
86
107
|
const keyArr = keys.split(',');
|
|
@@ -18,6 +18,7 @@ const fatcms_request_1 = require("../libs/utils/fatcms-request");
|
|
|
18
18
|
const contextLogger_1 = require("../models/contextLogger");
|
|
19
19
|
const node_stream_1 = require("node:stream");
|
|
20
20
|
const VisitStatService_1 = require("../service/VisitStatService");
|
|
21
|
+
const WorkbenchInfoTools_1 = require("../models/WorkbenchInfoTools");
|
|
21
22
|
function isFunction(fun) {
|
|
22
23
|
return typeof fun === 'function';
|
|
23
24
|
}
|
|
@@ -230,6 +231,12 @@ let GlobalMiddleware = class GlobalMiddleware {
|
|
|
230
231
|
const isSuperAdmin = checkIsSuperAdmin(ctx, sessionInfo);
|
|
231
232
|
ctx.userSession = new userSession_1.UserSessionInfo(sessionInfo, isSuperAdmin);
|
|
232
233
|
ctx.workbenchInfo = await workbenchService.getCurrentHostWorkbenchInfo();
|
|
234
|
+
ctx.workbenchInfoTools = new WorkbenchInfoTools_1.WorkbenchInfoTools(ctx.workbenchInfo);
|
|
235
|
+
// 校验是否支持该路径
|
|
236
|
+
const isSupportTheNodePath = workbenchService.isSupportTheNodePathByWorkbenchInfo(ctx.workbenchInfo, ctx.path);
|
|
237
|
+
if (!isSupportTheNodePath) {
|
|
238
|
+
return common_dto_1.CommonResult.errorRes('非法访问!此站点不支持该路径!', 'NOT_SUPPORT_PATH');
|
|
239
|
+
}
|
|
233
240
|
// 数据埋点
|
|
234
241
|
await trackRequest(ctx);
|
|
235
242
|
const res0 = await next();
|
|
@@ -103,3 +103,37 @@ export interface IWorkbenchEntity {
|
|
|
103
103
|
workbench_type: number;
|
|
104
104
|
package_assets?: string;
|
|
105
105
|
}
|
|
106
|
+
export declare enum CacheLevelEnum {
|
|
107
|
+
NONE = "NONE",
|
|
108
|
+
CONTEXT = "CONTEXT",
|
|
109
|
+
MEMORY = "MEMORY",
|
|
110
|
+
REDIS = "REDIS",
|
|
111
|
+
DISK = "DISK"
|
|
112
|
+
}
|
|
113
|
+
export declare enum CacheNameEnum {
|
|
114
|
+
CurdMixByDict = "CurdMixByDict",
|
|
115
|
+
CurdMixByLinkToCustom = "CurdMixByLinkToCustom",
|
|
116
|
+
CurdMixBySysConfig = "CurdMixBySysConfig",
|
|
117
|
+
CurdMixByWorkbench = "CurdMixByWorkbench",
|
|
118
|
+
GetParsedCrudStdAppInfo = "GetParsedCrudStdAppInfo",
|
|
119
|
+
GetWorkbenchMenu = "GetWorkbenchMenu",
|
|
120
|
+
GetNavPageInfo = "GetNavPageInfo",
|
|
121
|
+
GetEnumInfoByCode = "GetEnumInfoByCode",
|
|
122
|
+
UserSessionBySessionId = "UserSessionBySessionId",
|
|
123
|
+
UserSessionByAsyncTaskId = "UserSessionByAsyncTaskId"
|
|
124
|
+
}
|
|
125
|
+
export interface IWorkbenchConfig {
|
|
126
|
+
nodeApiWhiteEnable?: boolean;
|
|
127
|
+
nodeApiWhiteList?: string[];
|
|
128
|
+
nodeApiWhitePrefix?: string[];
|
|
129
|
+
crudStdAppInfoCacheLevel?: CacheLevelEnum;
|
|
130
|
+
crudStdAppInfoCacheSecond?: number;
|
|
131
|
+
publicApiNavPageInfoCacheLevel?: CacheLevelEnum;
|
|
132
|
+
publicApiNavPageInfoCacheSecond?: number;
|
|
133
|
+
publicApiMenuCacheLevel?: CacheLevelEnum;
|
|
134
|
+
publicApiMenuCacheSecond?: number;
|
|
135
|
+
queryEnumInfoCacheLevel?: CacheLevelEnum;
|
|
136
|
+
queryEnumInfoCacheSecond?: number;
|
|
137
|
+
curdMixByCommonCacheLevel?: CacheLevelEnum;
|
|
138
|
+
curdMixByCommonCacheSecond?: number;
|
|
139
|
+
}
|
|
@@ -1,9 +1,30 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ProxyUserContextEnum = void 0;
|
|
3
|
+
exports.CacheNameEnum = exports.CacheLevelEnum = exports.ProxyUserContextEnum = void 0;
|
|
4
4
|
var ProxyUserContextEnum;
|
|
5
5
|
(function (ProxyUserContextEnum) {
|
|
6
6
|
ProxyUserContextEnum[ProxyUserContextEnum["NO_PASS"] = 0] = "NO_PASS";
|
|
7
7
|
ProxyUserContextEnum[ProxyUserContextEnum["BASIC_INFO"] = 1] = "BASIC_INFO";
|
|
8
8
|
ProxyUserContextEnum[ProxyUserContextEnum["SESSION_INFO"] = 2] = "SESSION_INFO";
|
|
9
9
|
})(ProxyUserContextEnum = exports.ProxyUserContextEnum || (exports.ProxyUserContextEnum = {}));
|
|
10
|
+
var CacheLevelEnum;
|
|
11
|
+
(function (CacheLevelEnum) {
|
|
12
|
+
CacheLevelEnum["NONE"] = "NONE";
|
|
13
|
+
CacheLevelEnum["CONTEXT"] = "CONTEXT";
|
|
14
|
+
CacheLevelEnum["MEMORY"] = "MEMORY";
|
|
15
|
+
CacheLevelEnum["REDIS"] = "REDIS";
|
|
16
|
+
CacheLevelEnum["DISK"] = "DISK";
|
|
17
|
+
})(CacheLevelEnum = exports.CacheLevelEnum || (exports.CacheLevelEnum = {}));
|
|
18
|
+
var CacheNameEnum;
|
|
19
|
+
(function (CacheNameEnum) {
|
|
20
|
+
CacheNameEnum["CurdMixByDict"] = "CurdMixByDict";
|
|
21
|
+
CacheNameEnum["CurdMixByLinkToCustom"] = "CurdMixByLinkToCustom";
|
|
22
|
+
CacheNameEnum["CurdMixBySysConfig"] = "CurdMixBySysConfig";
|
|
23
|
+
CacheNameEnum["CurdMixByWorkbench"] = "CurdMixByWorkbench";
|
|
24
|
+
CacheNameEnum["GetParsedCrudStdAppInfo"] = "GetParsedCrudStdAppInfo";
|
|
25
|
+
CacheNameEnum["GetWorkbenchMenu"] = "GetWorkbenchMenu";
|
|
26
|
+
CacheNameEnum["GetNavPageInfo"] = "GetNavPageInfo";
|
|
27
|
+
CacheNameEnum["GetEnumInfoByCode"] = "GetEnumInfoByCode";
|
|
28
|
+
CacheNameEnum["UserSessionBySessionId"] = "UserSessionBySessionId";
|
|
29
|
+
CacheNameEnum["UserSessionByAsyncTaskId"] = "UserSessionByAsyncTaskId";
|
|
30
|
+
})(CacheNameEnum = exports.CacheNameEnum || (exports.CacheNameEnum = {}));
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { IWorkbenchConfig, IWorkbenchEntity } from "./SystemEntities";
|
|
2
|
+
export declare class WorkbenchInfoTools {
|
|
3
|
+
private readonly workbenchInfo;
|
|
4
|
+
private parsedConfigContent;
|
|
5
|
+
constructor(workbenchInfo: IWorkbenchEntity);
|
|
6
|
+
getWorkbenchConfig(): IWorkbenchConfig;
|
|
7
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.WorkbenchInfoTools = void 0;
|
|
4
|
+
const functions_1 = require("../libs/utils/functions");
|
|
5
|
+
class WorkbenchInfoTools {
|
|
6
|
+
constructor(workbenchInfo) {
|
|
7
|
+
this.workbenchInfo = workbenchInfo;
|
|
8
|
+
this.parsedConfigContent = null;
|
|
9
|
+
}
|
|
10
|
+
getWorkbenchConfig() {
|
|
11
|
+
var _a;
|
|
12
|
+
if (this.parsedConfigContent) {
|
|
13
|
+
return this.parsedConfigContent;
|
|
14
|
+
}
|
|
15
|
+
const configObj = (0, functions_1.parseJsonObject)((_a = this.workbenchInfo) === null || _a === void 0 ? void 0 : _a.config_content);
|
|
16
|
+
this.parsedConfigContent = configObj || {};
|
|
17
|
+
return this.parsedConfigContent;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
exports.WorkbenchInfoTools = WorkbenchInfoTools;
|
|
@@ -102,3 +102,12 @@ export interface IStdCrudExportInputParams {
|
|
|
102
102
|
primaryKey: any;
|
|
103
103
|
pageSize: number;
|
|
104
104
|
}
|
|
105
|
+
export interface ICacheServiceBase {
|
|
106
|
+
getJsonObject(key: string): Promise<any>;
|
|
107
|
+
setJsonObject(key: string, obj: any, cacheSecond?: number): Promise<any>;
|
|
108
|
+
removeItem(key: string): Promise<any>;
|
|
109
|
+
}
|
|
110
|
+
export interface IfatcmsCacheConfig {
|
|
111
|
+
diskCacheDir: string;
|
|
112
|
+
keyPrefix: string;
|
|
113
|
+
}
|
|
@@ -11,8 +11,10 @@ declare class ContextLogger implements ILoggerContext {
|
|
|
11
11
|
private readonly ctx;
|
|
12
12
|
private readonly app;
|
|
13
13
|
private readonly logList;
|
|
14
|
+
private currentTime;
|
|
14
15
|
constructor(ctx: Context);
|
|
15
16
|
getLogList(): any;
|
|
17
|
+
private getDiffTime;
|
|
16
18
|
debug(msg: any, ...args: any[]): void;
|
|
17
19
|
error(msg: any, ...args: any[]): void;
|
|
18
20
|
info(msg: any, ...args: any[]): void;
|
|
@@ -49,10 +49,16 @@ class ContextLogger {
|
|
|
49
49
|
this.app = ctx.app;
|
|
50
50
|
this.ctx = ctx;
|
|
51
51
|
this.logList = [];
|
|
52
|
+
this.currentTime = Date.now();
|
|
52
53
|
}
|
|
53
54
|
getLogList() {
|
|
54
55
|
return this.logList;
|
|
55
56
|
}
|
|
57
|
+
getDiffTime() {
|
|
58
|
+
const diffTime = Date.now() - this.currentTime;
|
|
59
|
+
this.currentTime = Date.now();
|
|
60
|
+
return diffTime;
|
|
61
|
+
}
|
|
56
62
|
debug(msg, ...args) {
|
|
57
63
|
this.getLogger().debug(msg, ...args);
|
|
58
64
|
this.appendLogList('debug', msg, ...args);
|
|
@@ -80,7 +86,8 @@ class ContextLogger {
|
|
|
80
86
|
}
|
|
81
87
|
const time = moment().format('YYYY-MM-DD HH:mm:ss.SSS');
|
|
82
88
|
const caller = getCallerInfo();
|
|
83
|
-
this.
|
|
89
|
+
const diffTime = this.getDiffTime();
|
|
90
|
+
this.logList.push({ level, msg, args, caller, time, diffTime });
|
|
84
91
|
}
|
|
85
92
|
getLogger() {
|
|
86
93
|
const logger = this.app.getLogger('logger');
|
|
@@ -23,6 +23,7 @@ const common_dto_1 = require("../libs/utils/common-dto");
|
|
|
23
23
|
const fatcms_request_1 = require("../libs/utils/fatcms-request");
|
|
24
24
|
const exceptions_1 = require("../libs/crud-pro/exceptions");
|
|
25
25
|
const global_config_1 = require("../libs/global-config/global-config");
|
|
26
|
+
const AsymmetricCrypto_1 = require("../libs/utils/AsymmetricCrypto");
|
|
26
27
|
let AuthService = class AuthService {
|
|
27
28
|
/**
|
|
28
29
|
* 明文密码转unsaltedPwd密码
|
|
@@ -80,6 +81,7 @@ let AuthService = class AuthService {
|
|
|
80
81
|
roleCodes = await this.queryUserRoleCodeList(accountId);
|
|
81
82
|
functionCodes = await this.queryFunctionCodeList(roleCodes);
|
|
82
83
|
}
|
|
84
|
+
const { publicKey, privateKey } = await AsymmetricCrypto_1.AsymmetricCrypto.generateKeyPair();
|
|
83
85
|
const sessionInfo = {
|
|
84
86
|
nickName: consumerUserInfo.nickName,
|
|
85
87
|
avatar: consumerUserInfo.avatar,
|
|
@@ -90,6 +92,8 @@ let AuthService = class AuthService {
|
|
|
90
92
|
accountId: consumerUserInfo.accountId,
|
|
91
93
|
workbenchCode: consumerUserInfo.workbenchCode,
|
|
92
94
|
accountType: consumerUserInfo.accountType,
|
|
95
|
+
publicKey,
|
|
96
|
+
privateKey,
|
|
93
97
|
};
|
|
94
98
|
await this.userSessionService.saveUserSession(sessionInfo);
|
|
95
99
|
return {
|
|
@@ -116,6 +120,7 @@ let AuthService = class AuthService {
|
|
|
116
120
|
const sessionId = (0, functions_1.createUniqueId)();
|
|
117
121
|
const roleCodes = await this.queryUserRoleCodeList(accountId);
|
|
118
122
|
const functionCodes = await this.queryFunctionCodeList(roleCodes);
|
|
123
|
+
const { publicKey, privateKey } = await AsymmetricCrypto_1.AsymmetricCrypto.generateKeyPair();
|
|
119
124
|
const sessionInfo = {
|
|
120
125
|
nickName: userAccount.nick_name,
|
|
121
126
|
avatar: userAccount.avatar,
|
|
@@ -127,6 +132,8 @@ let AuthService = class AuthService {
|
|
|
127
132
|
workbenchCode,
|
|
128
133
|
accountType: userSession_1.SYS_ACCOUNT_TYPE,
|
|
129
134
|
bizExt: {},
|
|
135
|
+
publicKey,
|
|
136
|
+
privateKey,
|
|
130
137
|
};
|
|
131
138
|
if (bizExt && typeof bizExt === 'object') {
|
|
132
139
|
sessionInfo.bizExt = bizExt;
|
|
@@ -14,7 +14,7 @@ export declare class EnumInfoService {
|
|
|
14
14
|
ctx: Context;
|
|
15
15
|
private curdProService;
|
|
16
16
|
private curdMixByLinkToCustomService;
|
|
17
|
-
private
|
|
17
|
+
private cacheServiceFactory;
|
|
18
18
|
queryEnumInfo(codeList: IQueryEnumInfo[], refreshCache: boolean): Promise<IQueryEnumResult[]>;
|
|
19
19
|
/**
|
|
20
20
|
* code形如:fatcms~~~sys_perm_role~~~role_code,role_name,xxx_name
|