zmdms-utils 0.0.66 → 0.0.67
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/es/file.js +39 -2
- package/package.json +1 -1
- package/src/file.ts +43 -4
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
3
|
import { BASIC_KEY, TOKEN_KEY, FILE_SERVICE } 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
|
}
|
|
@@ -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(
|
|
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
|
}
|
|
@@ -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
package/src/file.ts
CHANGED
|
@@ -10,7 +10,9 @@ import {
|
|
|
10
10
|
} from "./common";
|
|
11
11
|
import { TOKEN_KEY, BASIC_KEY, FILE_SERVICE } from "./constants";
|
|
12
12
|
import { AxiosResponse } from "axios";
|
|
13
|
+
import { Crypto } from "./crypto";
|
|
13
14
|
|
|
15
|
+
// 是否是中拓的附件服务
|
|
14
16
|
const isZmdmsFileService = FILE_SERVICE === "zmdms";
|
|
15
17
|
|
|
16
18
|
/**
|
|
@@ -29,6 +31,9 @@ export function downloadFile(
|
|
|
29
31
|
options: IDownloadOptions
|
|
30
32
|
) {
|
|
31
33
|
const { API_BASEURL, authToken, waterMark = true, open } = options;
|
|
34
|
+
if (isZmdmsFileService) {
|
|
35
|
+
fileId = encodeFileId(fileId, 2);
|
|
36
|
+
}
|
|
32
37
|
return new Promise((resolve, reject) => {
|
|
33
38
|
const xhr = new XMLHttpRequest();
|
|
34
39
|
// 获取请求基础数据
|
|
@@ -131,8 +136,11 @@ export function batchDownloadFiles(
|
|
|
131
136
|
};
|
|
132
137
|
xhr.setRequestHeader(TOKEN_KEY, token || "");
|
|
133
138
|
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
|
|
134
|
-
|
|
139
|
+
let fileIds = fileList?.map?.((item) => item.attachId)?.join?.(",");
|
|
135
140
|
const fileNames = fileList?.map?.((item) => item.attachName)?.join?.(",");
|
|
141
|
+
if (isZmdmsFileService) {
|
|
142
|
+
fileIds = encodeFileId(fileIds, 2);
|
|
143
|
+
}
|
|
136
144
|
xhr.send(
|
|
137
145
|
`attachIds=${fileIds}&fileNames=${fileNames}&zipName=${zipName}&addWaterMark=${waterMark}`
|
|
138
146
|
);
|
|
@@ -180,6 +188,7 @@ export function previewFile(
|
|
|
180
188
|
}
|
|
181
189
|
|
|
182
190
|
// 如果是图片 走批量预览接口
|
|
191
|
+
|
|
183
192
|
const isImage = isImageExtension(fileExtension);
|
|
184
193
|
if (isImage) {
|
|
185
194
|
const imgFiles = fileList.filter((item) => {
|
|
@@ -191,14 +200,19 @@ export function previewFile(
|
|
|
191
200
|
return false;
|
|
192
201
|
});
|
|
193
202
|
let attachIds = imgFiles.map((item) => item.attachId).join(",");
|
|
203
|
+
let fileIds = attachIds ? `${fileId},${attachIds}` : fileId;
|
|
204
|
+
if (isZmdmsFileService) {
|
|
205
|
+
fileIds = encodeFileId(fileIds, 1);
|
|
206
|
+
}
|
|
194
207
|
// 批量图片预览
|
|
195
208
|
window.open(
|
|
196
|
-
`${apiBaseURL}/picturesAttchPreview?attachIds=${
|
|
197
|
-
attachIds ? `${fileId},${attachIds}` : fileId
|
|
198
|
-
}&${TOKEN_KEY}=${token}` +
|
|
209
|
+
`${apiBaseURL}/picturesAttchPreview?attachIds=${fileIds}&${TOKEN_KEY}=${token}` +
|
|
199
210
|
(fileName ? `&titleName=${encodeURIComponent(previewFileName)}` : "")
|
|
200
211
|
);
|
|
201
212
|
} else {
|
|
213
|
+
if (isZmdmsFileService) {
|
|
214
|
+
fileId = encodeFileId(fileId, 1);
|
|
215
|
+
}
|
|
202
216
|
// 普通预览
|
|
203
217
|
window.open(
|
|
204
218
|
`${apiBaseURL}/attchPreview?attachId=${fileId}&${TOKEN_KEY}=${token}&officePreviewType=pdf` +
|
|
@@ -291,6 +305,9 @@ export function createDownloadLink(
|
|
|
291
305
|
) {
|
|
292
306
|
const { API_BASEURL, authToken, open } = options;
|
|
293
307
|
const { token, apiBaseURL } = getBasicInfo(API_BASEURL || "", authToken);
|
|
308
|
+
if (isZmdmsFileService) {
|
|
309
|
+
fileId = encodeFileId(fileId, 2);
|
|
310
|
+
}
|
|
294
311
|
if (open) {
|
|
295
312
|
return `${apiBaseURL}/api/${BASIC_KEY}-resource/oss/endpoint/public/download-file/${fileId}`;
|
|
296
313
|
}
|
|
@@ -331,6 +348,9 @@ export function createOriginalLink(
|
|
|
331
348
|
if (!isZmdmsFileService) {
|
|
332
349
|
return `${apiBaseURL}/api/cicoms-cicohr-org/cicomscicohr/v1/common/filePreview?attachId=${fileId}&${TOKEN_KEY}=${token}`;
|
|
333
350
|
}
|
|
351
|
+
if (isZmdmsFileService) {
|
|
352
|
+
fileId = encodeFileId(fileId, 2);
|
|
353
|
+
}
|
|
334
354
|
return (
|
|
335
355
|
`${apiBaseURL}/attchPreview?attachId=${fileId}&${TOKEN_KEY}=${token}&officePreviewType=pdf` +
|
|
336
356
|
(fileName ? `&titleName=${encodeURIComponent(previewFileName)}` : "")
|
|
@@ -430,3 +450,22 @@ interface IThumbnailLinkOptions extends Partial<IOptions> {
|
|
|
430
450
|
/** 缩放比例 */
|
|
431
451
|
scale?: number;
|
|
432
452
|
}
|
|
453
|
+
|
|
454
|
+
/**
|
|
455
|
+
* 加密附件ID
|
|
456
|
+
* @param fileId 附件ID
|
|
457
|
+
* @description 加密方式
|
|
458
|
+
* 1. 都会通过encrypt加密一次
|
|
459
|
+
* 2. 如果参数是通过地址栏传输的,附件预览:encode一次;附件下载:encode两次;
|
|
460
|
+
* 3. 如果参数是通过body传输的,只需要encode一次
|
|
461
|
+
*/
|
|
462
|
+
export function encodeFileId(fileId: string, encodeNum: number = 1) {
|
|
463
|
+
const crypto = new Crypto(
|
|
464
|
+
(window as any).__CRYPTO_AES_KEY__,
|
|
465
|
+
(window as any).__CRYPTO_DES_KEY__
|
|
466
|
+
);
|
|
467
|
+
if (encodeNum === 1) {
|
|
468
|
+
return encodeURIComponent(crypto.encrypt(fileId));
|
|
469
|
+
}
|
|
470
|
+
return encodeURIComponent(encodeURIComponent(crypto.encrypt(fileId)));
|
|
471
|
+
}
|