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,130 +0,0 @@
1
- import { Inject, Provide } from '@midwayjs/core';
2
- import { Context } from '@midwayjs/koa';
3
- import { KeysOfSimpleSQL } from '@/libs/crud-pro/models/keys';
4
- import { CurdProService } from './curd/CurdProService';
5
- import { RelatedType } from './curd/CurdMixUtils';
6
- import { SystemTables } from '@/models/SystemTables';
7
- import { parseConfigContentToEnumInfo, IEnumInfo } from '@/libs/utils/parseConfig';
8
- import { RedisCacheService } from './base/RedisCacheService';
9
- import { CurdMixByLinkToCustomService } from './curd/CurdMixByLinkToCustomService';
10
- import { GLOBAL_STATIC_CONFIG } from '@/libs/global-config/global-config';
11
- import { RedisKeys } from '@/models/RedisKeys';
12
-
13
- interface IQueryEnumInfo {
14
- type: RelatedType;
15
- code: string;
16
- }
17
- interface IQueryEnumResult {
18
- type: RelatedType;
19
- code: string;
20
- values: IEnumInfo[];
21
- }
22
-
23
- function filterEmpty(e: IEnumInfo): boolean {
24
- return e.label && typeof e.value !== 'undefined';
25
- }
26
-
27
- @Provide()
28
- export class EnumInfoService {
29
- @Inject()
30
- ctx: Context;
31
- @Inject()
32
- private curdProService: CurdProService;
33
-
34
- @Inject()
35
- private curdMixByLinkToCustomService: CurdMixByLinkToCustomService;
36
-
37
- @Inject()
38
- private redisCacheService: RedisCacheService;
39
-
40
- async queryEnumInfo(codeList: IQueryEnumInfo[], refreshCache: boolean): Promise<IQueryEnumResult[]> {
41
- const expireSecond = 2 * 60;
42
-
43
- const result = [];
44
- for (let i = 0; i < codeList.length; i++) {
45
- const { code, type } = codeList[i];
46
- const cacheKey = `${RedisKeys.QUERY_ENUM_INFO_PREFIX}${type}@@${code}`;
47
- const emums = refreshCache ? null : await this.redisCacheService.getJsonObject(cacheKey);
48
- if (!Array.isArray(emums) || emums.length === 0) {
49
- let values;
50
- if (type === RelatedType.sysCfgEnum) {
51
- values = await this.queryEnumInfoBySysCfgEnum(code);
52
- await this.redisCacheService.setJsonObject(cacheKey, values, expireSecond);
53
- } else if (type === RelatedType.dict) {
54
- values = await this.queryEnumInfoItemByDict(code);
55
- await this.redisCacheService.setJsonObject(cacheKey, values, expireSecond);
56
- } else if (type === RelatedType.linkToCustom) {
57
- values = await this.queryEnumInfoByLinkToCustom(code);
58
- // await this.redisCacheService.setJsonObject(cacheKey, values, expireSecond);
59
- }
60
- result.push({ type, code, values });
61
- } else {
62
- result.push({ type, code, values: emums });
63
- }
64
- }
65
- return result;
66
- }
67
-
68
- /**
69
- * code形如:fatcms~~~sys_perm_role~~~role_code,role_name,xxx_name
70
- * code形如:fatcms~~~sys_perm_role~~~id,*
71
- * 【数据库】~~~【表名】~~~【label】,【value】,【style】
72
- * @param code
73
- * @private
74
- */
75
- private async queryEnumInfoByLinkToCustom(code: string): Promise<IEnumInfo[]> {
76
- const cc = await this.curdMixByLinkToCustomService.queryInfoByLinkToCustom(code);
77
- if (!cc) {
78
- return [];
79
- }
80
- const keys = [...cc.keys()];
81
- return keys.map(value => {
82
- const label = cc.get(value);
83
- return { label, value };
84
- });
85
- }
86
-
87
- private async queryEnumInfoBySysCfgEnum(code: string): Promise<IEnumInfo[]> {
88
- const { SystemDbName, SystemDbType } = GLOBAL_STATIC_CONFIG.getConfig();
89
-
90
- const res1 = await this.curdProService.executeCrudByCfg(
91
- {
92
- condition: { config_code: code },
93
- },
94
- {
95
- sqlTable: SystemTables.sys_configs,
96
- sqlSimpleName: KeysOfSimpleSQL.SIMPLE_QUERY_ONE,
97
- sqlDatabase: SystemDbName,
98
- sqlDbType: SystemDbType,
99
- }
100
- );
101
- const obj = res1.getOneObj();
102
- if (!obj) {
103
- return null;
104
- }
105
-
106
- const rows = parseConfigContentToEnumInfo(obj);
107
- return rows.map(e => ({ label: e.label, value: e.value, children: e.children })).filter(filterEmpty);
108
- }
109
-
110
- private async queryEnumInfoItemByDict(code: string): Promise<IEnumInfo[]> {
111
- const { SystemDbName, SystemDbType } = GLOBAL_STATIC_CONFIG.getConfig();
112
-
113
- const res1 = await this.curdProService.executeCrudByCfg(
114
- {
115
- condition: { dict_code: code },
116
- },
117
- {
118
- sqlTable: SystemTables.sys_data_dict_item,
119
- sqlSimpleName: KeysOfSimpleSQL.SIMPLE_QUERY,
120
- sqlDatabase: SystemDbName,
121
- sqlDbType: SystemDbType,
122
- }
123
- );
124
- const obj = res1.getResRows();
125
- if (!obj) {
126
- return null;
127
- }
128
- return obj.map(e => ({ label: e.label, value: e.value })).filter(filterEmpty);
129
- }
130
- }
@@ -1,395 +0,0 @@
1
- import { Provide, Inject } from '@midwayjs/core';
2
- import { Context } from '@midwayjs/koa';
3
- import * as mime from 'mime-types';
4
- import * as md5 from 'md5';
5
- import * as fs from 'fs';
6
- import * as util from 'util';
7
- import { BizException } from '@/models/devops';
8
- import { CurdMixService } from './curd/CurdMixService';
9
- import { KeysOfSimpleSQL, KeysOfValidators } from '@/libs/crud-pro/models/keys';
10
- import { AccessType, IEntityCommonInfo, UploadCategoryType } from '@/models/bizmodels';
11
- import { IRequestCfgModel } from '@/libs/crud-pro/interfaces';
12
- import { BaseService } from './base/BaseService';
13
- import { GLOBAL_STATIC_CONFIG } from '@/libs/global-config/global-config';
14
-
15
- function getSuffix(s: string): string {
16
- if (s) {
17
- const indexOf = s.lastIndexOf('.');
18
- if (indexOf > 0) {
19
- return s.substring(indexOf); //'.jpg'
20
- }
21
- }
22
- return '';
23
- }
24
-
25
- function getDateTimeString() {
26
- const now = new Date();
27
- const year = now.getFullYear();
28
- const month = now.getMonth() + 1;
29
- const day = now.getDate();
30
- return [year, month, day]
31
- .map(num => {
32
- if (num < 10) {
33
- return '0' + num;
34
- }
35
- return num;
36
- })
37
- .join('');
38
- }
39
-
40
- function generateFileKey(filename: string, sessionId: string, fileStat: any) {
41
- const fileStatString = JSON.stringify(fileStat);
42
- const date = getDateTimeString();
43
- const fileSuffix = getSuffix(filename).toLowerCase();
44
- const fileKey = md5(`${filename}${sessionId}${fileStatString}${Math.random()}`) + Date.now() + fileSuffix;
45
- const storagePath = `upload/${date}/${fileKey}`;
46
-
47
- return {
48
- fileKey,
49
- fileSuffix,
50
- storagePath,
51
- };
52
- }
53
-
54
- function getAssetsContentType(filename: string): string {
55
- if (filename.endsWith('.css')) {
56
- return 'text/css';
57
- }
58
- if (filename.endsWith('.txt')) {
59
- return 'text/plain';
60
- }
61
- if (filename.endsWith('.js') || filename.endsWith('.cjs')) {
62
- return 'application/javascript';
63
- }
64
- if (filename.endsWith('.html')) {
65
- return 'text/html';
66
- }
67
- const contentType = mime.lookup(filename);
68
- if (contentType && typeof contentType === 'string') {
69
- return contentType;
70
- }
71
- return 'application/octet-stream';
72
- }
73
-
74
- // JPG、PNG、BMP、GIF、WebP、TIFF
75
- export function isImageFile(fileKey: string) {
76
- const fileKey1 = fileKey.toLowerCase();
77
- const suffix = ['.jpg', '.jpeg', '.png', '.bmp', '.gif', '.webp', '.tiff'];
78
- for (let i = 0; i < suffix.length; i++) {
79
- const suffix1 = suffix[i];
80
- if (fileKey1.endsWith(suffix1)) {
81
- return true;
82
- }
83
- }
84
- return false;
85
- }
86
-
87
- interface IFileInfo extends IEntityCommonInfo {
88
- file_key: string;
89
- file_name: string;
90
- file_size: number;
91
- file_type: string;
92
- file_suffix: string;
93
- file_desc: string;
94
- storage_path: string;
95
- storage_url: string;
96
- storage_engine: string;
97
- access_type: string;
98
- referer: string;
99
- }
100
-
101
- class FileDB {
102
- private curdMixService: CurdMixService;
103
-
104
- constructor(curdMixService: CurdMixService) {
105
- this.curdMixService = curdMixService;
106
- }
107
-
108
- async getFileInfo(fileKey: string): Promise<IFileInfo> {
109
- const { SystemDbName, SystemDbType } = GLOBAL_STATIC_CONFIG.getConfig();
110
-
111
- const condition: any = { file_key: fileKey };
112
- const cfgModel: IRequestCfgModel = {
113
- sqlTable: 'sys_file',
114
- sqlSimpleName: KeysOfSimpleSQL.SIMPLE_QUERY_ONE,
115
- sqlDatabase: SystemDbName,
116
- sqlDbType: SystemDbType,
117
- validateCfg: {
118
- 'condition.file_key': [KeysOfValidators.REQUIRED, KeysOfValidators.STRING],
119
- },
120
- };
121
-
122
- const res = await this.curdMixService.executeCrudByCfg({ condition }, cfgModel);
123
- return res.getOneObj();
124
- }
125
-
126
- async saveFileInfo(fileInfo: IFileInfo) {
127
- const { SystemDbName, SystemDbType } = GLOBAL_STATIC_CONFIG.getConfig();
128
-
129
- const cfgModel = {
130
- sqlTable: 'sys_file',
131
- sqlSimpleName: KeysOfSimpleSQL.SIMPLE_INSERT,
132
- sqlDatabase: SystemDbName,
133
- sqlDbType: SystemDbType,
134
- };
135
- return await this.curdMixService.executeCrudByCfg(
136
- {
137
- data: fileInfo,
138
- condition: {
139
- file_key: fileInfo.file_key,
140
- },
141
- },
142
- cfgModel
143
- );
144
- }
145
-
146
- async saveAssetsLog(fileInfo: IFileInfo) {
147
- const { SystemDbName, SystemDbType } = GLOBAL_STATIC_CONFIG.getConfig();
148
- const cfgModel = {
149
- sqlTable: 'sys_assets_log',
150
- sqlSimpleName: KeysOfSimpleSQL.SIMPLE_INSERT,
151
- sqlDatabase: SystemDbName,
152
- sqlDbType: SystemDbType,
153
- };
154
- return await this.curdMixService.executeCrudByCfg({ data: fileInfo }, cfgModel);
155
- }
156
-
157
- async deleteFileInfo(id: number) {
158
- const { SystemDbName, SystemDbType } = GLOBAL_STATIC_CONFIG.getConfig();
159
- const cfgModel: IRequestCfgModel = {
160
- sqlTable: 'sys_file',
161
- sqlSimpleName: KeysOfSimpleSQL.SIMPLE_DELETE,
162
- sqlDatabase: SystemDbName,
163
- sqlDbType: SystemDbType,
164
- validateCfg: {
165
- 'condition.id': [KeysOfValidators.REQUIRED, KeysOfValidators.NUMBER],
166
- },
167
- };
168
- return await this.curdMixService.executeCrudByCfg({ condition: { id } }, cfgModel);
169
- }
170
- }
171
-
172
- interface IUploadFileToOSSOptions {
173
- uploadCategoryType: UploadCategoryType;
174
- uploadPath: string;
175
- }
176
-
177
- export const PATH_PREFIX = '/ns/gw/file';
178
-
179
- export function toDownloadPaths(origin: string, fileKey: string) {
180
- const downloadPath = `${PATH_PREFIX}/get/download/${fileKey}`;
181
- const previewPath = `${PATH_PREFIX}/get/preview/${fileKey}`;
182
- const thumbnailPath = `${PATH_PREFIX}/get/thumbnail/${fileKey}`;
183
-
184
- return {
185
- downloadPath,
186
- previewPath,
187
- thumbnailPath,
188
- downloadURL: `${origin}${downloadPath}`,
189
- previewURL: `${origin}${previewPath}`,
190
- thumbnailURL: `${origin}${thumbnailPath}`,
191
- };
192
- }
193
-
194
- function toUploadOriginByReferer(referer: string): string {
195
- try {
196
- if (!referer || !referer.startsWith('http')) {
197
- return '';
198
- }
199
- const urlObj = new URL(referer);
200
- const pathname = urlObj.pathname;
201
- if (pathname.startsWith('/ns/app/doc-editor/')) {
202
- return 'doc-editor';
203
- }
204
- if (pathname.startsWith('/pages/devops/file-manage')) {
205
- return 'file-manage';
206
- }
207
- } catch (error) {
208
- console.error('toUploadOriginByReferer', error);
209
- }
210
- return '';
211
- }
212
-
213
- @Provide()
214
- export class FileCenterService extends BaseService {
215
- @Inject()
216
- protected ctx: Context;
217
-
218
- @Inject()
219
- private curdMixService: CurdMixService;
220
-
221
- private get fileBD(): FileDB {
222
- return new FileDB(this.curdMixService);
223
- }
224
-
225
- public async uploadFileToOSS(files: any, accessType: AccessType, referer: string, options?: IUploadFileToOSSOptions) {
226
- if (!files || files.length === 0) {
227
- throw new BizException('没有选中任何文件');
228
- }
229
- if (files.length > 1) {
230
- throw new BizException('每次只能上传一个文件');
231
- }
232
-
233
- const file = files[0]; // 每次只能上传一个文件
234
- const { mimeType, filename, data: fileData } = file;
235
- this.logInfo('[FileCenterService]uploadFileToOSS', file);
236
-
237
- const statAsync = util.promisify(fs.stat);
238
-
239
- const fileStat = await statAsync(fileData);
240
-
241
- this.logInfo('[FileCenterService]uploadFileToOSS fileStat', fileStat);
242
-
243
- const sessionId = this.ctx.userSession.getSessionInfo().sessionId;
244
-
245
- let fileSuffix = getSuffix(filename).toLowerCase();
246
- let fileKey: string, storagePath: string, result: any;
247
- const isAssets = options && options.uploadCategoryType === UploadCategoryType.assets;
248
- if (isAssets) {
249
- const uploadPath = options.uploadPath;
250
- storagePath = `assets/${uploadPath}`;
251
- fileKey = storagePath;
252
- result = await this.getPublicOSSService().put(storagePath, fileData, {
253
- mime: mimeType,
254
- headers: {
255
- 'Content-Type': getAssetsContentType(filename),
256
- },
257
- });
258
- } else {
259
- const generated = generateFileKey(filename, sessionId, fileStat);
260
- fileKey = generated.fileKey;
261
- fileSuffix = generated.fileSuffix;
262
- storagePath = generated.storagePath;
263
- result = await this.getPrivateOSSService().put(storagePath, fileData, {
264
- mime: mimeType,
265
- headers: {
266
- 'Content-Type': getAssetsContentType(filename),
267
- 'Content-Disposition': `attachment; filename="${encodeURI(filename)}"`,
268
- },
269
- });
270
- }
271
-
272
- const uploadOrigin = toUploadOriginByReferer(referer);
273
-
274
- const saveInfo = {
275
- file_key: fileKey,
276
- file_name: filename,
277
- file_size: fileStat.size,
278
- file_type: file.mimeType,
279
- file_suffix: fileSuffix,
280
- file_desc: '',
281
- storage_path: storagePath,
282
- storage_url: result.url,
283
- storage_engine: 'AliYunOSS',
284
- access_type: accessType,
285
- referer: referer,
286
- upload_origin: uploadOrigin,
287
- };
288
-
289
- if (isAssets) {
290
- await this.fileBD.saveAssetsLog(saveInfo);
291
- } else {
292
- await this.fileBD.saveFileInfo(saveInfo);
293
- }
294
-
295
- return {
296
- fileKey,
297
- fileSuffix,
298
- storagePath,
299
- storageUrl: result.url,
300
- fileSize: result.res.size,
301
- filename: file.filename,
302
- mimeType: file.mimeType,
303
- name: result.name,
304
- url: result.url,
305
- };
306
- }
307
-
308
- public async deleteFile(fileKey: string) {
309
- const fileInfo = await this.fileBD.getFileInfo(fileKey);
310
- if (!fileInfo || fileInfo.status !== 1) {
311
- throw new BizException('文件不存在');
312
- }
313
- const storagePath = fileInfo.storage_path;
314
- const res = await this.getPrivateOSSService().delete(storagePath);
315
- this.logInfo('deleteFile', res);
316
-
317
- return await this.fileBD.deleteFileInfo(fileInfo.id);
318
- }
319
-
320
- private async headFile(path: string) {
321
- try {
322
- return await this.getPrivateOSSService().head(path);
323
- } catch (error) {
324
- if (error.code !== 'NoSuchKey') {
325
- this.logError('[FILE_CHECK_ERROR]', error);
326
- }
327
- return false;
328
- }
329
- }
330
-
331
- public async downloadFile(fileKey: string, streaming: boolean, process: string): Promise<any> {
332
- const fileInfo = await this.fileBD.getFileInfo(fileKey);
333
- if (!fileInfo || fileInfo.status !== 1) {
334
- throw new BizException('文件不存在');
335
- }
336
-
337
- await this.checkAuthUserDownloadFile(fileInfo);
338
-
339
- const storagePath = fileInfo.storage_path;
340
-
341
- const header = await this.headFile(storagePath);
342
- if (!header) {
343
- throw new BizException('文件不存在或者已过期');
344
- }
345
-
346
- const urlParam: any = {};
347
- urlParam.expires = 60;
348
- if (process) {
349
- urlParam.process = process;
350
- }
351
- try {
352
- if (streaming) {
353
- const { res, stream } = await this.getPrivateOSSService().getStream(storagePath, urlParam);
354
- return { res, stream, downloadURL: null };
355
- } else {
356
- const downloadURL = this.getPrivateOSSService().signatureUrl(storagePath, urlParam);
357
- return { res: null, stream: null, downloadURL };
358
- }
359
- } catch (e) {
360
- this.logError('ossService ==> ', storagePath);
361
- throw e;
362
- }
363
- }
364
-
365
- /**
366
- * 检查用户下载权限
367
- * @param fileInfo
368
- * @private
369
- */
370
- private async checkAuthUserDownloadFile(fileInfo: IFileInfo) {
371
- const userSession = this.ctx.userSession;
372
- if (userSession.isSuperAdmin()) {
373
- return 'OK';
374
- }
375
-
376
- const access_type = fileInfo.access_type;
377
- if (access_type === AccessType.open) {
378
- return 'OK';
379
- }
380
-
381
- if (access_type === AccessType.owner) {
382
- if (!userSession.isMySelf(fileInfo.created_by)) {
383
- throw new BizException('您没有访问此文件的权限');
384
- }
385
- }
386
-
387
- if (access_type === AccessType.login) {
388
- if (!userSession.isLogin()) {
389
- throw new BizException('您当前未登录,您没有访问此文件的权限');
390
- }
391
- }
392
-
393
- return 'OK';
394
- }
395
- }
@@ -1,37 +0,0 @@
1
- import { Inject, Provide } from '@midwayjs/core';
2
- import { Context } from '@midwayjs/koa';
3
- import { KeysOfSimpleSQL } from '@/libs/crud-pro/models/keys';
4
- import { SystemTables } from '@/models/SystemTables';
5
- import { BaseService } from './base/BaseService';
6
- import { CurdProService } from './curd/CurdProService';
7
- import { GLOBAL_STATIC_CONFIG } from '@/libs/global-config/global-config';
8
-
9
- @Provide()
10
- export class SysConfigService extends BaseService {
11
- @Inject()
12
- ctx: Context;
13
-
14
- @Inject()
15
- private curdProService: CurdProService;
16
-
17
- async getSysConfigOne(config_code: string): Promise<any> {
18
- if (!config_code) {
19
- throw new Error('[getSysConfigOne] config_code required');
20
- }
21
-
22
- const { SystemDbName, SystemDbType } = GLOBAL_STATIC_CONFIG.getConfig();
23
-
24
- const res1 = await this.curdProService.executeCrudByCfg(
25
- {
26
- condition: { config_code },
27
- },
28
- {
29
- sqlTable: SystemTables.sys_configs,
30
- sqlSimpleName: KeysOfSimpleSQL.SIMPLE_QUERY_ONE,
31
- sqlDatabase: SystemDbName,
32
- sqlDbType: SystemDbType,
33
- }
34
- );
35
- return res1.getOneObj();
36
- }
37
- }
@@ -1,107 +0,0 @@
1
- import * as md5 from 'md5';
2
- import { Inject, Provide } from '@midwayjs/core';
3
- import { Context } from '@midwayjs/koa';
4
- import { KeysOfSimpleSQL } from '@/libs/crud-pro/models/keys';
5
- import { CurdMixService } from './curd/CurdMixService';
6
- import { createUniqueId } from '@/libs/utils/functions';
7
- import { CommonException, Exceptions } from '@/libs/crud-pro/exceptions';
8
- import { IRequestCfgModel, IRequestModel } from '@/libs/crud-pro/interfaces';
9
- import { SystemTables } from '@/models/SystemTables';
10
- import { CommonResult } from '@/libs/utils/common-dto';
11
- import { GLOBAL_STATIC_CONFIG } from '@/libs/global-config/global-config';
12
-
13
- @Provide()
14
- export class UserAccountService {
15
- @Inject()
16
- ctx: Context;
17
- @Inject()
18
- private curdMixService: CurdMixService;
19
-
20
- /**
21
- * 查询用户: 根据loginName查询
22
- * @param loginName
23
- */
24
- public async queryUserAccountByLoginName(loginName: string) {
25
- const { SystemDbName, SystemDbType } = GLOBAL_STATIC_CONFIG.getConfig();
26
-
27
- const query = await this.curdMixService.executeCrudByCfg(
28
- {
29
- condition: { login_name: loginName },
30
- },
31
- {
32
- method: 'UserAccountService.queryUserAccountByLoginName',
33
- sqlTable: SystemTables.sys_user_account,
34
- sqlSimpleName: KeysOfSimpleSQL.SIMPLE_QUERY_ONE,
35
- sqlDatabase: SystemDbName,
36
- sqlDbType: SystemDbType,
37
- }
38
- );
39
- const { row } = query.getResModel();
40
- return row;
41
- }
42
-
43
- /**
44
- * 查询基本信息:根据accountId数组
45
- * @param accountIdList
46
- * @param columns
47
- */
48
- public async queryAccountBasicInfoByIds(accountIdList: any[], columns: string[]): Promise<any[]> {
49
- if (!accountIdList || accountIdList.length === 0) {
50
- return [];
51
- }
52
-
53
- const { SystemDbName, SystemDbType } = GLOBAL_STATIC_CONFIG.getConfig();
54
-
55
- const accountIds = accountIdList.map(userId => {
56
- return `${userId}`;
57
- });
58
-
59
- const cfgModel: IRequestCfgModel = {
60
- method: 'UserAccountService.queryAccountBasicInfoByIds',
61
- sqlTable: SystemTables.sys_user_account,
62
- sqlSimpleName: KeysOfSimpleSQL.SIMPLE_QUERY,
63
- sqlDatabase: SystemDbName,
64
- sqlDbType: SystemDbType,
65
- };
66
-
67
- const reqJson: IRequestModel = {
68
- columns: columns,
69
- condition: {
70
- account_id: {
71
- $in: accountIds,
72
- },
73
- },
74
- };
75
-
76
- const res = await this.curdMixService.executeCrudByCfg(reqJson, cfgModel);
77
- return res.getResRows();
78
- }
79
-
80
- /**
81
- * 修改密码
82
- * @param loginName
83
- * @param unsaltedPwd
84
- */
85
- public async chgUserPassword(loginName: any, unsaltedPwd: any) {
86
- if (!loginName) {
87
- throw new CommonException(Exceptions.OTHER_EXCEPTION, 'loginName不存在');
88
- }
89
- const { SystemDbName, SystemDbType } = GLOBAL_STATIC_CONFIG.getConfig();
90
-
91
- const pwd_salt = createUniqueId();
92
- const pwd_md5 = md5(unsaltedPwd + pwd_salt);
93
- const res1 = await this.curdMixService.executeCrudByCfg(
94
- {
95
- data: { pwd_md5: pwd_md5, pwd_salt: pwd_salt },
96
- condition: { login_name: loginName },
97
- },
98
- {
99
- sqlTable: SystemTables.sys_user_account,
100
- sqlSimpleName: KeysOfSimpleSQL.SIMPLE_UPDATE,
101
- sqlDatabase: SystemDbName,
102
- sqlDbType: SystemDbType,
103
- }
104
- );
105
- return CommonResult.successRes(res1.getResModel());
106
- }
107
- }