zmdms-utils 0.0.66 → 0.0.68

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.
@@ -27,5 +27,7 @@ var TOKEN_KEY = window.__TOKEN_KEY__ || "Cicoms-Auth";
27
27
  var BASIC_KEY = window.__BASIC_KEY__ || "cicoms";
28
28
  // 附件相关服务
29
29
  var FILE_SERVICE = window.__FILE_SERVICE__ || "cicoms";
30
+ // 默认的附件预览服务地址
31
+ var FILE_PRVIEW_SERVICE_URL = window.__FILE_PRVIEW_SERVICE_URL__ || "";
30
32
 
31
- export { BASIC_KEY, EMITTER_CCP_KEY, EMITTER_PCC_KEY, EMITTER_TYPE, FILE_SERVICE, PERSONNEL_CENTER_APPNAME, SALARY_CENTER_APPNAME, TOKEN_KEY };
33
+ export { BASIC_KEY, EMITTER_CCP_KEY, EMITTER_PCC_KEY, EMITTER_TYPE, FILE_PRVIEW_SERVICE_URL, FILE_SERVICE, PERSONNEL_CENTER_APPNAME, SALARY_CENTER_APPNAME, TOKEN_KEY };
package/dist/es/file.js CHANGED
@@ -1,10 +1,12 @@
1
1
  import { getToken } from './auth.js';
2
2
  import { dangerouslyXss, specialString, getFileExtension, isImageExtension } from './common.js';
3
- import { BASIC_KEY, TOKEN_KEY, FILE_SERVICE } from './constants.js';
3
+ import { BASIC_KEY, TOKEN_KEY, FILE_SERVICE, FILE_PRVIEW_SERVICE_URL } from './constants.js';
4
+ import { Crypto } from './crypto.js';
4
5
 
5
6
  /**
6
7
  * 附件相关接口
7
8
  */
9
+ // 是否是中拓的附件服务
8
10
  var isZmdmsFileService = FILE_SERVICE === "zmdms";
9
11
  /**
10
12
  * 附件下载方法
@@ -18,6 +20,9 @@ var isZmdmsFileService = FILE_SERVICE === "zmdms";
18
20
  */
19
21
  function downloadFile(fileId, fileName, options) {
20
22
  var API_BASEURL = options.API_BASEURL, authToken = options.authToken, _a = options.waterMark, waterMark = _a === void 0 ? true : _a, open = options.open;
23
+ if (isZmdmsFileService) {
24
+ fileId = encodeFileId(fileId, 2);
25
+ }
21
26
  return new Promise(function (resolve, reject) {
22
27
  var xhr = new XMLHttpRequest();
23
28
  // 获取请求基础数据
@@ -96,6 +101,9 @@ function batchDownloadFiles(fileList, options) {
96
101
  xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
97
102
  var fileIds = (_c = (_b = (_a = fileList === null || fileList === void 0 ? void 0 : fileList.map) === null || _a === void 0 ? void 0 : _a.call(fileList, function (item) { return item.attachId; })) === null || _b === void 0 ? void 0 : _b.join) === null || _c === void 0 ? void 0 : _c.call(_b, ",");
98
103
  var fileNames = (_f = (_e = (_d = fileList === null || fileList === void 0 ? void 0 : fileList.map) === null || _d === void 0 ? void 0 : _d.call(fileList, function (item) { return item.attachName; })) === null || _e === void 0 ? void 0 : _e.join) === null || _f === void 0 ? void 0 : _f.call(_e, ",");
104
+ if (isZmdmsFileService) {
105
+ fileIds = encodeFileId(fileIds, 2);
106
+ }
99
107
  xhr.send("attachIds=".concat(fileIds, "&fileNames=").concat(fileNames, "&zipName=").concat(zipName, "&addWaterMark=").concat(waterMark));
100
108
  });
101
109
  }
@@ -112,7 +120,7 @@ function batchDownloadFiles(fileList, options) {
112
120
  function previewFile(fileId, fileName, options) {
113
121
  var API_BASEURL = options.API_BASEURL, authToken = options.authToken, _a = options.fileList, fileList = _a === void 0 ? [] : _a;
114
122
  // 获取请求基础数据
115
- var _b = getBasicInfo(API_BASEURL, authToken), token = _b.token, apiBaseURL = _b.apiBaseURL;
123
+ var _b = getBasicInfo(FILE_PRVIEW_SERVICE_URL || API_BASEURL, authToken), token = _b.token, apiBaseURL = _b.apiBaseURL;
116
124
  // 处理附件名中的一些特殊字符
117
125
  var previewFileName = dangerouslyXss(fileName);
118
126
  try {
@@ -144,11 +152,18 @@ function previewFile(fileId, fileName, options) {
144
152
  return false;
145
153
  });
146
154
  var attachIds = imgFiles.map(function (item) { return item.attachId; }).join(",");
155
+ var fileIds = attachIds ? "".concat(fileId, ",").concat(attachIds) : fileId;
156
+ if (isZmdmsFileService) {
157
+ fileIds = encodeFileId(fileIds, 1);
158
+ }
147
159
  // 批量图片预览
148
- window.open("".concat(apiBaseURL, "/picturesAttchPreview?attachIds=").concat(attachIds ? "".concat(fileId, ",").concat(attachIds) : fileId, "&").concat(TOKEN_KEY, "=").concat(token) +
160
+ window.open("".concat(apiBaseURL, "/picturesAttchPreview?attachIds=").concat(fileIds, "&").concat(TOKEN_KEY, "=").concat(token) +
149
161
  (fileName ? "&titleName=".concat(encodeURIComponent(previewFileName)) : ""));
150
162
  }
151
163
  else {
164
+ if (isZmdmsFileService) {
165
+ fileId = encodeFileId(fileId, 1);
166
+ }
152
167
  // 普通预览
153
168
  window.open("".concat(apiBaseURL, "/attchPreview?attachId=").concat(fileId, "&").concat(TOKEN_KEY, "=").concat(token, "&officePreviewType=pdf") +
154
169
  (fileName ? "&titleName=".concat(encodeURIComponent(previewFileName)) : ""));
@@ -237,6 +252,9 @@ function createDownloadLink(fileId, options) {
237
252
  if (options === void 0) { options = {}; }
238
253
  var API_BASEURL = options.API_BASEURL, authToken = options.authToken, open = options.open;
239
254
  var _a = getBasicInfo(API_BASEURL || "", authToken), token = _a.token, apiBaseURL = _a.apiBaseURL;
255
+ if (isZmdmsFileService) {
256
+ fileId = encodeFileId(fileId, 2);
257
+ }
240
258
  if (open) {
241
259
  return "".concat(apiBaseURL, "/api/").concat(BASIC_KEY, "-resource/oss/endpoint/public/download-file/").concat(fileId);
242
260
  }
@@ -255,7 +273,7 @@ function createDownloadLink(fileId, options) {
255
273
  function createOriginalLink(fileId, fileName, options) {
256
274
  if (options === void 0) { options = {}; }
257
275
  var API_BASEURL = options.API_BASEURL, authToken = options.authToken;
258
- var _a = getBasicInfo(API_BASEURL || "", authToken), token = _a.token, apiBaseURL = _a.apiBaseURL;
276
+ var _a = getBasicInfo(FILE_PRVIEW_SERVICE_URL || API_BASEURL || "", authToken), token = _a.token, apiBaseURL = _a.apiBaseURL;
259
277
  // 处理附件名中的一些特殊字符
260
278
  var previewFileName = dangerouslyXss(fileName);
261
279
  try {
@@ -274,6 +292,9 @@ function createOriginalLink(fileId, fileName, options) {
274
292
  if (!isZmdmsFileService) {
275
293
  return "".concat(apiBaseURL, "/api/cicoms-cicohr-org/cicomscicohr/v1/common/filePreview?attachId=").concat(fileId, "&").concat(TOKEN_KEY, "=").concat(token);
276
294
  }
295
+ if (isZmdmsFileService) {
296
+ fileId = encodeFileId(fileId, 2);
297
+ }
277
298
  return ("".concat(apiBaseURL, "/attchPreview?attachId=").concat(fileId, "&").concat(TOKEN_KEY, "=").concat(token, "&officePreviewType=pdf") +
278
299
  (fileName ? "&titleName=".concat(encodeURIComponent(previewFileName)) : ""));
279
300
  }
@@ -332,5 +353,21 @@ function getBasicInfo(baseURL, token) {
332
353
  : baseURL,
333
354
  };
334
355
  }
356
+ /**
357
+ * 加密附件ID
358
+ * @param fileId 附件ID
359
+ * @description 加密方式
360
+ * 1. 都会通过encrypt加密一次
361
+ * 2. 如果参数是通过地址栏传输的,附件预览:encode一次;附件下载:encode两次;
362
+ * 3. 如果参数是通过body传输的,只需要encode一次
363
+ */
364
+ function encodeFileId(fileId, encodeNum) {
365
+ if (encodeNum === void 0) { encodeNum = 1; }
366
+ var crypto = new Crypto(window.__CRYPTO_AES_KEY__, window.__CRYPTO_DES_KEY__);
367
+ if (encodeNum === 1) {
368
+ return encodeURIComponent(crypto.encrypt(fileId));
369
+ }
370
+ return encodeURIComponent(encodeURIComponent(crypto.encrypt(fileId)));
371
+ }
335
372
 
336
- export { batchDownloadFiles, createDeleteFileLink, createDownloadLink, createOriginalLink, createThumbnailLink, createUploadFileLink, downloadFile, exportBolb, previewFile };
373
+ export { batchDownloadFiles, createDeleteFileLink, createDownloadLink, createOriginalLink, createThumbnailLink, createUploadFileLink, downloadFile, encodeFileId, exportBolb, previewFile };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zmdms-utils",
3
- "version": "0.0.66",
3
+ "version": "0.0.68",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.js",
package/src/constants.ts CHANGED
@@ -34,3 +34,7 @@ export const BASIC_KEY = (window as any).__BASIC_KEY__ || "cicoms";
34
34
 
35
35
  // 附件相关服务
36
36
  export const FILE_SERVICE = (window as any).__FILE_SERVICE__ || "cicoms";
37
+
38
+ // 默认的附件预览服务地址
39
+ export const FILE_PRVIEW_SERVICE_URL =
40
+ (window as any).__FILE_PRVIEW_SERVICE_URL__ || "";
package/src/file.ts CHANGED
@@ -8,9 +8,16 @@ import {
8
8
  getFileExtension,
9
9
  isImageExtension,
10
10
  } from "./common";
11
- import { TOKEN_KEY, BASIC_KEY, FILE_SERVICE } from "./constants";
11
+ import {
12
+ TOKEN_KEY,
13
+ BASIC_KEY,
14
+ FILE_SERVICE,
15
+ FILE_PRVIEW_SERVICE_URL,
16
+ } from "./constants";
12
17
  import { AxiosResponse } from "axios";
18
+ import { Crypto } from "./crypto";
13
19
 
20
+ // 是否是中拓的附件服务
14
21
  const isZmdmsFileService = FILE_SERVICE === "zmdms";
15
22
 
16
23
  /**
@@ -29,6 +36,9 @@ export function downloadFile(
29
36
  options: IDownloadOptions
30
37
  ) {
31
38
  const { API_BASEURL, authToken, waterMark = true, open } = options;
39
+ if (isZmdmsFileService) {
40
+ fileId = encodeFileId(fileId, 2);
41
+ }
32
42
  return new Promise((resolve, reject) => {
33
43
  const xhr = new XMLHttpRequest();
34
44
  // 获取请求基础数据
@@ -131,8 +141,11 @@ export function batchDownloadFiles(
131
141
  };
132
142
  xhr.setRequestHeader(TOKEN_KEY, token || "");
133
143
  xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
134
- const fileIds = fileList?.map?.((item) => item.attachId)?.join?.(",");
144
+ let fileIds = fileList?.map?.((item) => item.attachId)?.join?.(",");
135
145
  const fileNames = fileList?.map?.((item) => item.attachName)?.join?.(",");
146
+ if (isZmdmsFileService) {
147
+ fileIds = encodeFileId(fileIds, 2);
148
+ }
136
149
  xhr.send(
137
150
  `attachIds=${fileIds}&fileNames=${fileNames}&zipName=${zipName}&addWaterMark=${waterMark}`
138
151
  );
@@ -156,7 +169,10 @@ export function previewFile(
156
169
  ) {
157
170
  const { API_BASEURL, authToken, fileList = [] } = options;
158
171
  // 获取请求基础数据
159
- const { token, apiBaseURL } = getBasicInfo(API_BASEURL, authToken);
172
+ const { token, apiBaseURL } = getBasicInfo(
173
+ FILE_PRVIEW_SERVICE_URL || API_BASEURL,
174
+ authToken
175
+ );
160
176
  // 处理附件名中的一些特殊字符
161
177
  let previewFileName = dangerouslyXss(fileName);
162
178
  try {
@@ -180,6 +196,7 @@ export function previewFile(
180
196
  }
181
197
 
182
198
  // 如果是图片 走批量预览接口
199
+
183
200
  const isImage = isImageExtension(fileExtension);
184
201
  if (isImage) {
185
202
  const imgFiles = fileList.filter((item) => {
@@ -191,14 +208,19 @@ export function previewFile(
191
208
  return false;
192
209
  });
193
210
  let attachIds = imgFiles.map((item) => item.attachId).join(",");
211
+ let fileIds = attachIds ? `${fileId},${attachIds}` : fileId;
212
+ if (isZmdmsFileService) {
213
+ fileIds = encodeFileId(fileIds, 1);
214
+ }
194
215
  // 批量图片预览
195
216
  window.open(
196
- `${apiBaseURL}/picturesAttchPreview?attachIds=${
197
- attachIds ? `${fileId},${attachIds}` : fileId
198
- }&${TOKEN_KEY}=${token}` +
217
+ `${apiBaseURL}/picturesAttchPreview?attachIds=${fileIds}&${TOKEN_KEY}=${token}` +
199
218
  (fileName ? `&titleName=${encodeURIComponent(previewFileName)}` : "")
200
219
  );
201
220
  } else {
221
+ if (isZmdmsFileService) {
222
+ fileId = encodeFileId(fileId, 1);
223
+ }
202
224
  // 普通预览
203
225
  window.open(
204
226
  `${apiBaseURL}/attchPreview?attachId=${fileId}&${TOKEN_KEY}=${token}&officePreviewType=pdf` +
@@ -291,6 +313,9 @@ export function createDownloadLink(
291
313
  ) {
292
314
  const { API_BASEURL, authToken, open } = options;
293
315
  const { token, apiBaseURL } = getBasicInfo(API_BASEURL || "", authToken);
316
+ if (isZmdmsFileService) {
317
+ fileId = encodeFileId(fileId, 2);
318
+ }
294
319
  if (open) {
295
320
  return `${apiBaseURL}/api/${BASIC_KEY}-resource/oss/endpoint/public/download-file/${fileId}`;
296
321
  }
@@ -313,7 +338,10 @@ export function createOriginalLink(
313
338
  options: IOriginLinkOptions = {}
314
339
  ) {
315
340
  const { API_BASEURL, authToken } = options;
316
- const { token, apiBaseURL } = getBasicInfo(API_BASEURL || "", authToken);
341
+ const { token, apiBaseURL } = getBasicInfo(
342
+ FILE_PRVIEW_SERVICE_URL || API_BASEURL || "",
343
+ authToken
344
+ );
317
345
  // 处理附件名中的一些特殊字符
318
346
  let previewFileName = dangerouslyXss(fileName);
319
347
  try {
@@ -331,6 +359,9 @@ export function createOriginalLink(
331
359
  if (!isZmdmsFileService) {
332
360
  return `${apiBaseURL}/api/cicoms-cicohr-org/cicomscicohr/v1/common/filePreview?attachId=${fileId}&${TOKEN_KEY}=${token}`;
333
361
  }
362
+ if (isZmdmsFileService) {
363
+ fileId = encodeFileId(fileId, 2);
364
+ }
334
365
  return (
335
366
  `${apiBaseURL}/attchPreview?attachId=${fileId}&${TOKEN_KEY}=${token}&officePreviewType=pdf` +
336
367
  (fileName ? `&titleName=${encodeURIComponent(previewFileName)}` : "")
@@ -430,3 +461,22 @@ interface IThumbnailLinkOptions extends Partial<IOptions> {
430
461
  /** 缩放比例 */
431
462
  scale?: number;
432
463
  }
464
+
465
+ /**
466
+ * 加密附件ID
467
+ * @param fileId 附件ID
468
+ * @description 加密方式
469
+ * 1. 都会通过encrypt加密一次
470
+ * 2. 如果参数是通过地址栏传输的,附件预览:encode一次;附件下载:encode两次;
471
+ * 3. 如果参数是通过body传输的,只需要encode一次
472
+ */
473
+ export function encodeFileId(fileId: string, encodeNum: number = 1) {
474
+ const crypto = new Crypto(
475
+ (window as any).__CRYPTO_AES_KEY__,
476
+ (window as any).__CRYPTO_DES_KEY__
477
+ );
478
+ if (encodeNum === 1) {
479
+ return encodeURIComponent(crypto.encrypt(fileId));
480
+ }
481
+ return encodeURIComponent(encodeURIComponent(crypto.encrypt(fileId)));
482
+ }