zmdms-utils 0.0.88 → 0.0.90
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 +8 -1
- package/dist/es/request.js +3 -1
- package/package.json +1 -1
- package/src/file.ts +27 -18
- package/src/request.ts +3 -1
package/dist/es/file.js
CHANGED
|
@@ -396,8 +396,15 @@ function createDeleteFileLink(options) {
|
|
|
396
396
|
*/
|
|
397
397
|
function getBasicInfo(baseURL, token) {
|
|
398
398
|
var _a;
|
|
399
|
+
// 如果token有前缀,那么不需要处理 如果token没有前缀 添加bearer前缀
|
|
400
|
+
var newToken = token || getToken();
|
|
401
|
+
if (newToken &&
|
|
402
|
+
!newToken.startsWith("Bearer ") &&
|
|
403
|
+
!newToken.startsWith("bearer ")) {
|
|
404
|
+
newToken = "bearer ".concat(newToken);
|
|
405
|
+
}
|
|
399
406
|
return {
|
|
400
|
-
token:
|
|
407
|
+
token: newToken,
|
|
401
408
|
apiBaseURL: ((_a = baseURL === null || baseURL === void 0 ? void 0 : baseURL.endsWith) === null || _a === void 0 ? void 0 : _a.call(baseURL, "/"))
|
|
402
409
|
? baseURL.slice(0, baseURL.length - 1)
|
|
403
410
|
: baseURL,
|
package/dist/es/request.js
CHANGED
|
@@ -102,7 +102,9 @@ var AxiosRequest = /** @class */ (function () {
|
|
|
102
102
|
status === 200 &&
|
|
103
103
|
data &&
|
|
104
104
|
typeof data === "object" &&
|
|
105
|
-
(
|
|
105
|
+
(data === null || data === void 0 ? void 0 : data.code) !== 200 &&
|
|
106
|
+
(data === null || data === void 0 ? void 0 : data.code) !== 201 &&
|
|
107
|
+
(data === null || data === void 0 ? void 0 : data.success) === false) {
|
|
106
108
|
// 详细信息 再开发模式开启 之后上到别的环境会去掉
|
|
107
109
|
(_b = this.modalConfirm) === null || _b === void 0 ? void 0 : _b.call(this, "".concat((data === null || data === void 0 ? void 0 : data.msg) || "请求异常"));
|
|
108
110
|
return;
|
package/package.json
CHANGED
package/src/file.ts
CHANGED
|
@@ -33,7 +33,7 @@ const isZmdmsFileService = FILE_SERVICE === "zmdms";
|
|
|
33
33
|
export function downloadFile(
|
|
34
34
|
fileId: string,
|
|
35
35
|
fileName: string,
|
|
36
|
-
options: IDownloadOptions
|
|
36
|
+
options: IDownloadOptions,
|
|
37
37
|
) {
|
|
38
38
|
const {
|
|
39
39
|
API_BASEURL,
|
|
@@ -53,13 +53,13 @@ export function downloadFile(
|
|
|
53
53
|
xhr.open(
|
|
54
54
|
"GET",
|
|
55
55
|
`${apiBaseURL}/api/${BASIC_KEY}-resource/oss/endpoint/public/download-file/${fileId}`,
|
|
56
|
-
true
|
|
56
|
+
true,
|
|
57
57
|
);
|
|
58
58
|
} else {
|
|
59
59
|
xhr.open(
|
|
60
60
|
"GET",
|
|
61
61
|
`${apiBaseURL}/api/${BASIC_KEY}-resource/oss/endpoint/download-file/${fileId}?${TOKEN_KEY}=${token}&addWaterMark=${waterMark}`,
|
|
62
|
-
true
|
|
62
|
+
true,
|
|
63
63
|
);
|
|
64
64
|
}
|
|
65
65
|
xhr.responseType = "blob";
|
|
@@ -133,7 +133,7 @@ export function batchDownloadFiles(
|
|
|
133
133
|
attachName: string;
|
|
134
134
|
[props: string]: string;
|
|
135
135
|
}[],
|
|
136
|
-
options: IBatchDownloadOptions
|
|
136
|
+
options: IBatchDownloadOptions,
|
|
137
137
|
) {
|
|
138
138
|
const {
|
|
139
139
|
API_BASEURL,
|
|
@@ -149,7 +149,7 @@ export function batchDownloadFiles(
|
|
|
149
149
|
xhr.open(
|
|
150
150
|
"POST",
|
|
151
151
|
`${apiBaseURL}/api/${BASIC_KEY}-resource/oss/endpoint/batch-download-file`,
|
|
152
|
-
true
|
|
152
|
+
true,
|
|
153
153
|
);
|
|
154
154
|
xhr.responseType = "blob";
|
|
155
155
|
xhr.onload = function () {
|
|
@@ -211,7 +211,7 @@ export function batchDownloadFiles(
|
|
|
211
211
|
fileIds = encodeFileId(fileIds, 2);
|
|
212
212
|
}
|
|
213
213
|
xhr.send(
|
|
214
|
-
`attachIds=${fileIds}&fileNames=${fileNames}&zipName=${zipName}&addWaterMark=${waterMark}
|
|
214
|
+
`attachIds=${fileIds}&fileNames=${fileNames}&zipName=${zipName}&addWaterMark=${waterMark}`,
|
|
215
215
|
);
|
|
216
216
|
});
|
|
217
217
|
}
|
|
@@ -229,13 +229,13 @@ export function batchDownloadFiles(
|
|
|
229
229
|
export function previewFile(
|
|
230
230
|
fileId: string,
|
|
231
231
|
fileName: string,
|
|
232
|
-
options: IPreviewOptions
|
|
232
|
+
options: IPreviewOptions,
|
|
233
233
|
) {
|
|
234
234
|
const { API_BASEURL, authToken, fileList = [] } = options;
|
|
235
235
|
// 获取请求基础数据
|
|
236
236
|
const { token, apiBaseURL } = getBasicInfo(
|
|
237
237
|
FILE_PRVIEW_SERVICE_URL || API_BASEURL,
|
|
238
|
-
authToken
|
|
238
|
+
authToken,
|
|
239
239
|
);
|
|
240
240
|
// 处理附件名中的一些特殊字符
|
|
241
241
|
let previewFileName = dangerouslyXss(fileName);
|
|
@@ -254,7 +254,7 @@ export function previewFile(
|
|
|
254
254
|
if (!isZmdmsFileService) {
|
|
255
255
|
// 2023-12-30 修改成数字中心预览
|
|
256
256
|
window.open(
|
|
257
|
-
`${apiBaseURL}/api/${BASIC_KEY}-resource/attach/filePreview?attachId=${fileId}&${TOKEN_KEY}=${token}
|
|
257
|
+
`${apiBaseURL}/api/${BASIC_KEY}-resource/attach/filePreview?attachId=${fileId}&${TOKEN_KEY}=${token}`,
|
|
258
258
|
);
|
|
259
259
|
return;
|
|
260
260
|
}
|
|
@@ -279,7 +279,7 @@ export function previewFile(
|
|
|
279
279
|
// 批量图片预览
|
|
280
280
|
window.open(
|
|
281
281
|
`${apiBaseURL}/picturesAttchPreview?attachIds=${fileIds}&${TOKEN_KEY}=${token}` +
|
|
282
|
-
(fileName ? `&titleName=${encodeURIComponent(previewFileName)}` : "")
|
|
282
|
+
(fileName ? `&titleName=${encodeURIComponent(previewFileName)}` : ""),
|
|
283
283
|
);
|
|
284
284
|
} else {
|
|
285
285
|
if (isZmdmsFileService) {
|
|
@@ -288,7 +288,7 @@ export function previewFile(
|
|
|
288
288
|
// 普通预览
|
|
289
289
|
window.open(
|
|
290
290
|
`${apiBaseURL}/attchPreview?attachId=${fileId}&${TOKEN_KEY}=${token}&officePreviewType=pdf` +
|
|
291
|
-
(fileName ? `&titleName=${encodeURIComponent(previewFileName)}` : "")
|
|
291
|
+
(fileName ? `&titleName=${encodeURIComponent(previewFileName)}` : ""),
|
|
292
292
|
);
|
|
293
293
|
}
|
|
294
294
|
}
|
|
@@ -325,7 +325,7 @@ export function exportBolb(response: AxiosResponse, fileName?: string) {
|
|
|
325
325
|
const [name, extension] = getFileExtension(fileName);
|
|
326
326
|
if (copyName) {
|
|
327
327
|
const [, copyExtension] = getFileExtension(
|
|
328
|
-
decodeURIComponent(copyName)
|
|
328
|
+
decodeURIComponent(copyName),
|
|
329
329
|
);
|
|
330
330
|
elink.download =
|
|
331
331
|
extension === copyExtension
|
|
@@ -373,7 +373,7 @@ export function exportBolb(response: AxiosResponse, fileName?: string) {
|
|
|
373
373
|
*/
|
|
374
374
|
export function createDownloadLink(
|
|
375
375
|
fileId: string,
|
|
376
|
-
options: IDownloadLinkOptions = {}
|
|
376
|
+
options: IDownloadLinkOptions = {},
|
|
377
377
|
) {
|
|
378
378
|
const { API_BASEURL, authToken, open } = options;
|
|
379
379
|
const { token, apiBaseURL } = getBasicInfo(API_BASEURL || "", authToken);
|
|
@@ -399,12 +399,12 @@ export function createDownloadLink(
|
|
|
399
399
|
export function createOriginalLink(
|
|
400
400
|
fileId: string,
|
|
401
401
|
fileName: string,
|
|
402
|
-
options: IOriginLinkOptions = {}
|
|
402
|
+
options: IOriginLinkOptions = {},
|
|
403
403
|
) {
|
|
404
404
|
const { API_BASEURL, authToken, encodeNum = 1 } = options;
|
|
405
405
|
const { token, apiBaseURL } = getBasicInfo(
|
|
406
406
|
FILE_PRVIEW_SERVICE_URL || API_BASEURL || "",
|
|
407
|
-
authToken
|
|
407
|
+
authToken,
|
|
408
408
|
);
|
|
409
409
|
// 处理附件名中的一些特殊字符
|
|
410
410
|
let previewFileName = dangerouslyXss(fileName);
|
|
@@ -446,7 +446,7 @@ export function createOriginalLink(
|
|
|
446
446
|
export function createThumbnailLink(
|
|
447
447
|
fileId: string,
|
|
448
448
|
fileName: string,
|
|
449
|
-
options: IThumbnailLinkOptions
|
|
449
|
+
options: IThumbnailLinkOptions,
|
|
450
450
|
) {
|
|
451
451
|
const { API_BASEURL, authToken, scale = 0.5 } = options;
|
|
452
452
|
const { token, apiBaseURL } = getBasicInfo(API_BASEURL || "", authToken);
|
|
@@ -485,8 +485,17 @@ export function createDeleteFileLink(options: IOptions) {
|
|
|
485
485
|
* @returns
|
|
486
486
|
*/
|
|
487
487
|
function getBasicInfo(baseURL: string, token?: string) {
|
|
488
|
+
// 如果token有前缀,那么不需要处理 如果token没有前缀 添加bearer前缀
|
|
489
|
+
let newToken = token || getToken();
|
|
490
|
+
if (
|
|
491
|
+
newToken &&
|
|
492
|
+
!newToken.startsWith("Bearer ") &&
|
|
493
|
+
!newToken.startsWith("bearer ")
|
|
494
|
+
) {
|
|
495
|
+
newToken = `bearer ${newToken}`;
|
|
496
|
+
}
|
|
488
497
|
return {
|
|
489
|
-
token:
|
|
498
|
+
token: newToken,
|
|
490
499
|
apiBaseURL: baseURL?.endsWith?.("/")
|
|
491
500
|
? baseURL.slice(0, baseURL.length - 1)
|
|
492
501
|
: baseURL,
|
|
@@ -543,7 +552,7 @@ interface IThumbnailLinkOptions extends Partial<IOptions> {
|
|
|
543
552
|
export function encodeFileId(fileId: string, encodeNum: number = 1) {
|
|
544
553
|
const crypto = new Crypto(
|
|
545
554
|
(window as any).__CRYPTO_AES_KEY__,
|
|
546
|
-
(window as any).__CRYPTO_DES_KEY__
|
|
555
|
+
(window as any).__CRYPTO_DES_KEY__,
|
|
547
556
|
);
|
|
548
557
|
if (encodeNum === 0) {
|
|
549
558
|
return crypto.encrypt(fileId);
|
package/src/request.ts
CHANGED
|
@@ -138,7 +138,9 @@ export class AxiosRequest {
|
|
|
138
138
|
status === 200 &&
|
|
139
139
|
data &&
|
|
140
140
|
typeof data === "object" &&
|
|
141
|
-
|
|
141
|
+
data?.code !== 200 &&
|
|
142
|
+
data?.code !== 201 &&
|
|
143
|
+
data?.success === false
|
|
142
144
|
) {
|
|
143
145
|
// 详细信息 再开发模式开启 之后上到别的环境会去掉
|
|
144
146
|
this.modalConfirm?.(`${data?.msg || "请求异常"}`);
|