midway-fatcms 0.0.1-beta.40 → 0.0.1-beta.42

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.
@@ -35,11 +35,7 @@ exports.default = (appInfo) => {
35
35
  jsonLimit: '10mb',
36
36
  textLimit: '10mb',
37
37
  xmlLimit: '10mb',
38
- ignore: [
39
- '/ns/gw/proxy/*',
40
- '/ns/gw/file/uploadFile',
41
- '/ns/api/manage/deploy/uploadAssets',
42
- ], // 忽略代理路径的 body 解析
38
+ ignore: ['/ns/gw/proxy/*', '/ns/gw/file/uploadFile', '/ns/api/manage/deploy/uploadAssets'], // 忽略代理路径的 body 解析
43
39
  },
44
40
  mysql2: {
45
41
  fatcms: {
@@ -115,34 +111,7 @@ exports.default = (appInfo) => {
115
111
  fileSize: '20mb',
116
112
  limit: '20mb',
117
113
  // whitelist: string[],文件扩展名白名单
118
- whitelist: [
119
- '.jpg',
120
- '.jpeg',
121
- '.png',
122
- '.gif',
123
- '.pdf',
124
- '.zip',
125
- '.xlsx',
126
- '.docx',
127
- '.pptx',
128
- '.txt',
129
- '.md',
130
- '.json',
131
- '.js',
132
- '.cjs',
133
- '.ejs',
134
- '.jsx',
135
- '.css',
136
- '.java',
137
- '.ts',
138
- '.tsx',
139
- '.less',
140
- '.scss',
141
- '.html',
142
- '.ttf',
143
- '.map',
144
- '.svg',
145
- ],
114
+ whitelist: ['.jpg', '.jpeg', '.png', '.gif', '.pdf', '.zip', '.xlsx', '.docx', '.pptx', '.txt', '.md', '.json', '.js', '.cjs', '.ejs', '.jsx', '.css', '.java', '.ts', '.tsx', '.less', '.scss', '.html', '.ttf', '.map', '.svg'],
146
115
  // tmpdir: string,上传的文件临时存储路径
147
116
  tmpdir: (0, path_1.join)((0, os_1.tmpdir)(), 'fatcms-upload-files'),
148
117
  // cleanTimeout: number,上传的文件在临时目录中多久之后自动删除,默认为 5 分钟
@@ -186,6 +155,6 @@ exports.default = (appInfo) => {
186
155
  // Excel导出文件的临时目录
187
156
  fatcmsExportExcelTmpFilePath: (0, path_1.join)((0, os_1.tmpdir)(), 'fatcms-export-excel'),
188
157
  // 在某些场景下,只有一个workbench code。如果启用了此配置,则不再根据域名配置识别Workbench.
189
- fatcmsTargetWorkbenchCode: null
158
+ fatcmsTargetWorkbenchCode: null,
190
159
  };
191
160
  };
@@ -3,6 +3,7 @@ declare class Transaction {
3
3
  private transactionMySQL;
4
4
  private transactionPostgres;
5
5
  private transactionSqlServer;
6
+ private isReleased;
6
7
  private getTxObj;
7
8
  /**
8
9
  * 获取链接对象
@@ -10,6 +10,7 @@ class Transaction {
10
10
  this.transactionMySQL = new TransactionMySQL_1.TransactionMySQL();
11
11
  this.transactionPostgres = new TransactionPostgres_1.TransactionPostgres();
12
12
  this.transactionSqlServer = new TransactionSqlServer_1.TransactionSqlServer();
13
+ this.isReleased = false;
13
14
  }
14
15
  getTxObj(pool) {
15
16
  if (pool.dbType === keys_1.SqlDbType.postgres) {
@@ -28,6 +29,11 @@ class Transaction {
28
29
  * @param pool
29
30
  */
30
31
  async getTxConnection(pool) {
32
+ if (this.isReleased) {
33
+ const msg = '[Transaction] getTxConnection error, the txObject is isReleased, please check your code . DB request must be await';
34
+ console.error(msg);
35
+ throw new Error(msg);
36
+ }
31
37
  const txObj = this.getTxObj(pool);
32
38
  return txObj.getTxConnection(pool);
33
39
  }
@@ -62,6 +68,7 @@ class Transaction {
62
68
  await this.transactionMySQL.releaseTx();
63
69
  await this.transactionPostgres.releaseTx();
64
70
  await this.transactionSqlServer.releaseTx();
71
+ this.isReleased = true;
65
72
  }
66
73
  }
67
74
  exports.Transaction = Transaction;
@@ -34,6 +34,10 @@ interface IGlobalStaticConfig {
34
34
  toFatcmsUserAccountId(bizTableUserId: any): string;
35
35
  SystemDbName: string;
36
36
  SystemDbType: SqlDbType;
37
+ /**
38
+ * Excel导出时,每页查询的最大数量
39
+ */
40
+ maxPageSizeOfExportExcel: number;
37
41
  }
38
42
  declare class GlobalStaticConfig {
39
43
  private configObject;
@@ -17,6 +17,7 @@ class GlobalStaticConfig {
17
17
  },
18
18
  SystemDbName: 'fatcms',
19
19
  SystemDbType: keys_1.SqlDbType.mysql,
20
+ maxPageSizeOfExportExcel: 1000
20
21
  };
21
22
  }
22
23
  getConfig() {
@@ -0,0 +1,9 @@
1
+ declare function toBase64(obj: any): string;
2
+ /**
3
+ * 将经 toBase64 函数序列化的 Base64 字符串还原为 JS 对象
4
+ * @param base64Str - 经 toBase64 处理后的 Base64 字符串
5
+ * @returns 还原后的 JS 对象
6
+ * @throws 当 Base64 格式无效或 JSON 解析失败时抛出含具体原因的错误
7
+ */
8
+ declare function fromBase64(base64Str: string): any;
9
+ export { toBase64, fromBase64 };
@@ -0,0 +1,42 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.fromBase64 = exports.toBase64 = void 0;
4
+ function toBase64(obj) {
5
+ const jsonString = JSON.stringify(obj);
6
+ return Buffer.from(jsonString, 'utf8').toString('base64');
7
+ }
8
+ exports.toBase64 = toBase64;
9
+ /**
10
+ * 将经 toBase64 函数序列化的 Base64 字符串还原为 JS 对象
11
+ * @param base64Str - 经 toBase64 处理后的 Base64 字符串
12
+ * @returns 还原后的 JS 对象
13
+ * @throws 当 Base64 格式无效或 JSON 解析失败时抛出含具体原因的错误
14
+ */
15
+ function fromBase64(base64Str) {
16
+ // 校验输入是否为字符串
17
+ if (typeof base64Str !== 'string') {
18
+ throw new Error('input must Base64 string');
19
+ }
20
+ try {
21
+ // 1. 反向步骤1:将 Base64 字符串解码为 UTF-8 格式的 JSON 字符串
22
+ // 对应原函数的 Buffer.from(jsonString, 'utf8') 反向操作
23
+ const jsonString = Buffer.from(base64Str, 'base64').toString('utf8');
24
+ // 2. 反向步骤2:将 JSON 字符串解析为 JS 对象
25
+ // 对应原函数的 JSON.stringify(obj) 反向操作
26
+ const restoredObj = JSON.parse(jsonString);
27
+ return restoredObj;
28
+ }
29
+ catch (error) {
30
+ // 分类处理不同错误类型,提供明确提示
31
+ if (error instanceof TypeError && error.message.includes('invalid base64')) {
32
+ throw new Error('还原失败:输入不是有效的 Base64 字符串');
33
+ }
34
+ else if (error instanceof SyntaxError && error.message.includes('JSON')) {
35
+ throw new Error('还原失败:解码后的内容不是有效的 JSON 格式');
36
+ }
37
+ else {
38
+ throw new Error(`还原失败:未知错误 - ${error.message}`);
39
+ }
40
+ }
41
+ }
42
+ exports.fromBase64 = fromBase64;
@@ -136,7 +136,7 @@ let WorkbenchService = class WorkbenchService extends BaseService_1.BaseService
136
136
  }
137
137
  // 只有一个workbench的场景。对于后台系统。不需要配置域名的场景。
138
138
  const fatcmsTargetWorkbenchCode = this.fatcmsTargetWorkbenchCode;
139
- if (typeof fatcmsTargetWorkbenchCode === "string" && fatcmsTargetWorkbenchCode.length > 3) {
139
+ if (typeof fatcmsTargetWorkbenchCode === 'string' && fatcmsTargetWorkbenchCode.length > 3) {
140
140
  return await this.getWorkbenchInfoByCode(fatcmsTargetWorkbenchCode);
141
141
  }
142
142
  //正式环境: 根据域名获取站点配置
@@ -146,7 +146,7 @@ let WorkbenchService = class WorkbenchService extends BaseService_1.BaseService
146
146
  return workbenchInfo;
147
147
  }
148
148
  // 最后兜底
149
- return await this.getWorkbenchInfoByHost("*");
149
+ return await this.getWorkbenchInfoByHost('*');
150
150
  }
151
151
  /**
152
152
  * 获取当前请求的域名
@@ -155,7 +155,7 @@ let AsyncTaskRunnerService = class AsyncTaskRunnerService extends BaseService_1.
155
155
  return Promise.resolve();
156
156
  }
157
157
  const timeoutTime = moment().subtract(24, 'hours').format("YYYY-MM-DD HH:mm:ss.SSS");
158
- this.curdProService.executeCrudByCfg({
158
+ await this.curdProService.executeCrudByCfg({
159
159
  condition: {
160
160
  task_status: AsyncTaskModel_1.SysAsyncTaskStatus.RUNNING,
161
161
  updated_at: {
@@ -247,7 +247,7 @@ let AsyncTaskRunnerService = class AsyncTaskRunnerService extends BaseService_1.
247
247
  sqlDbType: SystemDbType,
248
248
  });
249
249
  // 开始执行。
250
- exports.ASYNC_TASK_RUNNER.executeTaskList(taskList).then(() => {
250
+ await exports.ASYNC_TASK_RUNNER.executeTaskList(taskList).then(() => {
251
251
  console.log('[AsyncTaskRunnerService] ASYNC_TASK_RUNNER finished taskIds ==> ' + JSON.stringify(taskIds));
252
252
  });
253
253
  }
@@ -6,6 +6,7 @@ const axios_1 = require("axios");
6
6
  const AsyncTaskModel_1 = require("../../../models/AsyncTaskModel");
7
7
  const schedule_1 = require("../../../schedule");
8
8
  const functions_1 = require("../../../libs/utils/functions");
9
+ const global_config_1 = require("../../../libs/global-config/global-config");
9
10
  function pickData(a, key) {
10
11
  if (a && typeof a.getResModel === 'function') {
11
12
  const s = a.getResModel();
@@ -29,8 +30,9 @@ class ExportExcelByInnerHttpHandler {
29
30
  this.appCode = this.inputParams.appCode;
30
31
  }
31
32
  async getPageSize() {
33
+ const maxPageSizeOfExportExcel = global_config_1.GLOBAL_STATIC_CONFIG.getConfig().maxPageSizeOfExportExcel;
32
34
  if (typeof this.inputParams.pageSize === 'number') {
33
- return Math.min(this.inputParams.pageSize, 1000);
35
+ return Math.min(this.inputParams.pageSize, maxPageSizeOfExportExcel);
34
36
  }
35
37
  return 1000;
36
38
  }
@@ -4,6 +4,7 @@ exports.ExportExcelByStdCrudHandler = void 0;
4
4
  const _ = require("lodash");
5
5
  const CrudStdService_1 = require("../../../service/crudstd/CrudStdService");
6
6
  const keys_1 = require("../../../libs/crud-pro/models/keys");
7
+ const global_config_1 = require("../../../libs/global-config/global-config");
7
8
  function pickData(a, key) {
8
9
  if (a && typeof a.getResModel === 'function') {
9
10
  const s = a.getResModel();
@@ -27,8 +28,9 @@ class ExportExcelByStdCrudHandler {
27
28
  this.appCode = this.inputParams.appCode;
28
29
  }
29
30
  async getPageSize() {
31
+ const maxPageSizeOfExportExcel = global_config_1.GLOBAL_STATIC_CONFIG.getConfig().maxPageSizeOfExportExcel;
30
32
  if (typeof this.inputParams.pageSize === 'number') {
31
- return Math.min(this.inputParams.pageSize, 1000);
33
+ return Math.min(this.inputParams.pageSize, maxPageSizeOfExportExcel);
32
34
  }
33
35
  return 1000;
34
36
  }
@@ -57,4 +57,5 @@ export declare class ProxyApiService extends ApiBaseService {
57
57
  */
58
58
  private selectTargetByBalanceStrategy;
59
59
  private setRequestHeaders;
60
+ private buildUserContextHeader;
60
61
  }
@@ -22,10 +22,7 @@ const fatcms_request_1 = require("../../libs/utils/fatcms-request");
22
22
  const ProxyApiUtils_1 = require("./ProxyApiUtils");
23
23
  const ProxyApiLoadService_1 = require("./ProxyApiLoadService");
24
24
  const ApiBaseService_1 = require("../base/ApiBaseService");
25
- function toBase64(obj) {
26
- const jsonString = JSON.stringify(obj);
27
- return Buffer.from(jsonString, 'utf8').toString('base64');
28
- }
25
+ const base64_1 = require("../../libs/utils/base64");
29
26
  /**
30
27
  * 接口代理
31
28
  */
@@ -231,20 +228,40 @@ let ProxyApiService = class ProxyApiService extends ApiBaseService_1.ApiBaseServ
231
228
  }
232
229
  setRequestHeaders(headers, proxyApiEntity) {
233
230
  const ctx = this.ctx;
231
+ // 转发IP
234
232
  if (proxyApiEntity.pass_real_ip) {
235
233
  headers['x-real-ip'] = ctx.headers['x-real-ip'];
236
234
  headers['x-forwarded-for'] = ctx.headers['x-forwarded-for'];
237
235
  }
236
+ // 转发用户上下文
237
+ const userContextHeader = this.buildUserContextHeader(proxyApiEntity);
238
+ if (userContextHeader) {
239
+ headers['x-fatcms-usercontext'] = userContextHeader;
240
+ }
241
+ else {
242
+ delete headers['x-fatcms-usercontext']; // 只有自己构建的才能被转发。前面传过来的,不要转发。
243
+ }
244
+ if (proxyApiEntity.change_host && proxyApiEntity.change_host.length > 0) {
245
+ headers.host = proxyApiEntity.change_host;
246
+ }
247
+ if (proxyApiEntity.change_origin && proxyApiEntity.change_origin.length > 0) {
248
+ headers.origin = proxyApiEntity.change_origin;
249
+ }
250
+ }
251
+ buildUserContextHeader(proxyApiEntity) {
252
+ var _a, _b;
238
253
  // 传递整个用户上下文
239
254
  if (proxyApiEntity.user_context === SystemEntities_1.ProxyUserContextEnum.SESSION_INFO) {
240
255
  const isLogin = this.ctx.userSession.isLogin();
241
256
  const sessionInfo = this.ctx.userSession.getSessionInfo();
242
- headers['x-fatcms-usercontext'] = toBase64({ ...sessionInfo, isLogin });
257
+ const workbenchCode = (_a = this.ctx.workbenchInfo) === null || _a === void 0 ? void 0 : _a.workbench_code;
258
+ return (0, base64_1.toBase64)({ ...sessionInfo, isLogin, workbenchCode });
243
259
  }
244
260
  // 只传递用户基本信息
245
261
  if (proxyApiEntity.user_context === SystemEntities_1.ProxyUserContextEnum.BASIC_INFO) {
246
262
  const isLogin = this.ctx.userSession.isLogin();
247
263
  const sessionInfo = this.ctx.userSession.getSessionInfo();
264
+ const workbenchCode = (_b = this.ctx.workbenchInfo) === null || _b === void 0 ? void 0 : _b.workbench_code;
248
265
  const userBasicInfo = { isLogin };
249
266
  if (sessionInfo && isLogin) {
250
267
  userBasicInfo.loginName = sessionInfo.loginName;
@@ -253,14 +270,10 @@ let ProxyApiService = class ProxyApiService extends ApiBaseService_1.ApiBaseServ
253
270
  userBasicInfo.workbenchCode = sessionInfo.workbenchCode;
254
271
  userBasicInfo.accountType = sessionInfo.accountType;
255
272
  }
256
- headers['x-fatcms-usercontext'] = toBase64(userBasicInfo);
257
- }
258
- if (proxyApiEntity.change_host && proxyApiEntity.change_host.length > 0) {
259
- headers.host = proxyApiEntity.change_host;
260
- }
261
- if (proxyApiEntity.change_origin && proxyApiEntity.change_origin.length > 0) {
262
- headers.origin = proxyApiEntity.change_origin;
273
+ userBasicInfo.workbenchCode = workbenchCode;
274
+ return (0, base64_1.toBase64)(userBasicInfo);
263
275
  }
276
+ return null;
264
277
  }
265
278
  };
266
279
  __decorate([
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "midway-fatcms",
3
- "version": "0.0.1-beta.40",
3
+ "version": "0.0.1-beta.42",
4
4
  "description": "This is a midway component sample",
5
5
  "main": "dist/index.js",
6
6
  "typings": "index.d.ts",
@@ -12,6 +12,9 @@
12
12
  "lint:fix": "mwts fix"
13
13
  },
14
14
  "keywords": [],
15
+ "engines": {
16
+ "node": ">10"
17
+ },
15
18
  "author": "",
16
19
  "files": [
17
20
  "dist/**/*.txt",