@haluo/util 2.0.22 → 2.0.23

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.
@@ -12,6 +12,7 @@
12
12
  *
13
13
  * // 创建上传实例,传入业务相关的API函数
14
14
  * const ossUploader = createAliOssUploader({
15
+ * getSts: (params) => api.getSts(params),
15
16
  * getAliyunSts: (params) => api.getAliyunSts(params),
16
17
  * darkWaterUploadImage: (params) => api.darkWaterUploadImage(params),
17
18
  * multiTransferImage: (params) => api.multiTransferImage(params),
@@ -54,18 +55,28 @@
54
55
  * 不同的businessType对应不同的OSS bucket和水印策略
55
56
  */
56
57
  export declare enum BusinessType {
57
- NO_WATER = 0,
58
- AVATAR = 1,
59
- GIF = 4,
60
- VIDEO = 6,
61
- UNPROTECT = 8,
62
- ARTICLE = 1000,
63
- PRIVATE = 1199,
64
- ENCRYPTED = 1299,
65
- DEFAULT = 1500
58
+ CREDIT = 130541736,
59
+ CONTENT = 101300784,
60
+ AVATAR = 134539448,
61
+ USED_CAR = 171978237,
62
+ MALL = 115259415,
63
+ HOOP = 155669648,
64
+ USER = 170244368,
65
+ CYCLING = 165103952,
66
+ MOTORCYCLE = 151637735,
67
+ RENTALCAR = 149095014,
68
+ SHOP = 172655993,
69
+ FINANCE = 188717541,
70
+ FEEDBACK = 182411383,
71
+ DRIVING_SCHOOL = 172137757,
72
+ REPLY = 195929698,
73
+ FACTORY = 118733601,
74
+ CYCLING_DATA = 148681294,
75
+ GIF = 191290831,
76
+ OTHER = 100694193
66
77
  }
67
78
  /**
68
- * 图片类型后缀枚举
79
+ * bucket 图片类型后缀枚举
69
80
  */
70
81
  export declare const SuffixEnum: {
71
82
  readonly nowater: "!nowater";
@@ -109,13 +120,12 @@ export interface UploadResult {
109
120
  */
110
121
  export interface UploadOption {
111
122
  file: File;
123
+ businessType?: BusinessType | number;
112
124
  imageType?: ImageType | string;
113
125
  quality?: number;
114
- businessType?: BusinessType | number;
115
126
  batchTransfer?: boolean;
116
127
  notCompress?: boolean;
117
128
  idCard?: boolean;
118
- imggeCarType?: any;
119
129
  isVideo?: boolean;
120
130
  isUnProtect?: boolean;
121
131
  isDocument?: boolean;
@@ -139,10 +149,16 @@ interface ApiResponse<T = any> {
139
149
  * 业务相关的API通过此接口传入,实现业务逻辑解耦
140
150
  */
141
151
  export interface AliOssApiConfig {
142
- /** 获取阿里云STS临时凭证 - 必需 */
152
+ /** 获取STS,POST V4签名独有的表单元素- 必需 */
153
+ /** businessType: 业务编码(必传), docType: 文件格式如png(必传),size: _1024_567(可选) */
154
+ getSts: (params: {
155
+ businessType: BusinessType;
156
+ docType: string;
157
+ size?: string;
158
+ }) => Promise<ApiResponse<OSSClientParams>>;
159
+ /** 获取阿里云STS临时凭证 - 旧版非必需 */
143
160
  getAliyunSts: (params: {
144
161
  businessType: number;
145
- imggeCarType?: any;
146
162
  }) => Promise<ApiResponse<OSSClientParams>>;
147
163
  /** 暗水印上传接口 - 可选,用于carport类型 */
148
164
  darkWaterUploadImage?: (params: {
@@ -183,19 +199,37 @@ export declare class AliOssClass {
183
199
  private apiConfig;
184
200
  private clientCache;
185
201
  constructor(apiConfig: AliOssApiConfig);
202
+ /**
203
+ * 通过V4签名上传
204
+ * @param file 上传的文件
205
+ * @param businessType 业务类型
206
+ * @param size 文件的尺寸
207
+ * @returns 上传图片结果
208
+ */
209
+ upload(file: any, businessType: BusinessType, size?: string): Promise<any>;
186
210
  /**
187
211
  * 创建OSS客户端
188
212
  * @param businessType 业务类型
189
- * @param imggeCarType 车辆图片类型(可选,用于特定业务)
190
213
  * @returns OSS客户端实例
191
214
  */
192
- createOssClient(businessType: number, imggeCarType?: any): Promise<any>;
215
+ createOssClient(businessType: number): Promise<any>;
216
+ /**
217
+ * 执行OSS上传
218
+ * @param client OSS客户端
219
+ * @param fileName 文件名
220
+ * @param file 文件对象
221
+ * @param year 年份
222
+ * @param mimeType MIME类型
223
+ * @param onProgress 进度回调
224
+ * @returns 上传结果
225
+ */
226
+ private performOssUpload;
193
227
  /**
194
228
  * 预加载图片获取尺寸
195
229
  * @param file 文件对象
196
230
  * @returns 图片对象
197
231
  */
198
- imgUpload(file: File): Promise<HTMLImageElement>;
232
+ getImageInfo(file: File): Promise<HTMLImageElement>;
199
233
  /**
200
234
  * 生成文件名
201
235
  * @param imageType 图片类型
@@ -210,17 +244,6 @@ export declare class AliOssClass {
210
244
  * @returns 是否为长图
211
245
  */
212
246
  private isLongImage;
213
- /**
214
- * 执行OSS上传
215
- * @param client OSS客户端
216
- * @param fileName 文件名
217
- * @param file 文件对象
218
- * @param year 年份
219
- * @param mimeType MIME类型
220
- * @param onProgress 进度回调
221
- * @returns 上传结果
222
- */
223
- private performOssUpload;
224
247
  /**
225
248
  * 确定业务类型
226
249
  * @param option 上传选项
@@ -12,6 +12,7 @@
12
12
  *
13
13
  * // 创建上传实例,传入业务相关的API函数
14
14
  * const ossUploader = createAliOssUploader({
15
+ * getSts: (params) => api.getSts(params),
15
16
  * getAliyunSts: (params) => api.getAliyunSts(params),
16
17
  * darkWaterUploadImage: (params) => api.darkWaterUploadImage(params),
17
18
  * multiTransferImage: (params) => api.multiTransferImage(params),
@@ -53,7 +54,12 @@ import OSS from 'ali-oss';
53
54
  import lrz from 'lrz';
54
55
  // ==================== 常量定义 ====================
55
56
  /** 支持的图片格式 */
56
- const SUPPORTED_IMAGE_TYPES = ['image/png', 'image/gif', 'image/jpg', 'image/jpeg'];
57
+ const SUPPORTED_IMAGE_TYPES = [
58
+ 'image/png',
59
+ 'image/gif',
60
+ 'image/jpg',
61
+ 'image/jpeg',
62
+ ];
57
63
  /** 小图片阈值(KB) */
58
64
  const SMALL_IMAGE_THRESHOLD = 100;
59
65
  /** 长图宽高比阈值 */
@@ -79,18 +85,37 @@ const OSS_META_PEOPLE = 'x-oss-meta-motor';
79
85
  */
80
86
  export var BusinessType;
81
87
  (function (BusinessType) {
82
- BusinessType[BusinessType["NO_WATER"] = 0] = "NO_WATER";
83
- BusinessType[BusinessType["AVATAR"] = 1] = "AVATAR";
84
- BusinessType[BusinessType["GIF"] = 4] = "GIF";
85
- BusinessType[BusinessType["VIDEO"] = 6] = "VIDEO";
86
- BusinessType[BusinessType["UNPROTECT"] = 8] = "UNPROTECT";
87
- BusinessType[BusinessType["ARTICLE"] = 1000] = "ARTICLE";
88
- BusinessType[BusinessType["PRIVATE"] = 1199] = "PRIVATE";
89
- BusinessType[BusinessType["ENCRYPTED"] = 1299] = "ENCRYPTED";
90
- BusinessType[BusinessType["DEFAULT"] = 1500] = "DEFAULT"; // 默认
88
+ // NO_WATER = 0, // 不打水印
89
+ // AVATAR = 1, // 头像
90
+ // GIF = 4, // GIF图片
91
+ // VIDEO = 6, // 视频
92
+ // UNPROTECT = 8, // UnProtect(不受保护)
93
+ // ARTICLE = 1000, // 文章图片
94
+ // PRIVATE = 1199, // 私有
95
+ // ENCRYPTED = 1299, // 加密
96
+ // DEFAULT = 1500, // 默认
97
+ BusinessType[BusinessType["CREDIT"] = 130541736] = "CREDIT";
98
+ BusinessType[BusinessType["CONTENT"] = 101300784] = "CONTENT";
99
+ BusinessType[BusinessType["AVATAR"] = 134539448] = "AVATAR";
100
+ BusinessType[BusinessType["USED_CAR"] = 171978237] = "USED_CAR";
101
+ BusinessType[BusinessType["MALL"] = 115259415] = "MALL";
102
+ BusinessType[BusinessType["HOOP"] = 155669648] = "HOOP";
103
+ BusinessType[BusinessType["USER"] = 170244368] = "USER";
104
+ BusinessType[BusinessType["CYCLING"] = 165103952] = "CYCLING";
105
+ BusinessType[BusinessType["MOTORCYCLE"] = 151637735] = "MOTORCYCLE";
106
+ BusinessType[BusinessType["RENTALCAR"] = 149095014] = "RENTALCAR";
107
+ BusinessType[BusinessType["SHOP"] = 172655993] = "SHOP";
108
+ BusinessType[BusinessType["FINANCE"] = 188717541] = "FINANCE";
109
+ BusinessType[BusinessType["FEEDBACK"] = 182411383] = "FEEDBACK";
110
+ BusinessType[BusinessType["DRIVING_SCHOOL"] = 172137757] = "DRIVING_SCHOOL";
111
+ BusinessType[BusinessType["REPLY"] = 195929698] = "REPLY";
112
+ BusinessType[BusinessType["FACTORY"] = 118733601] = "FACTORY";
113
+ BusinessType[BusinessType["CYCLING_DATA"] = 148681294] = "CYCLING_DATA";
114
+ BusinessType[BusinessType["GIF"] = 191290831] = "GIF";
115
+ BusinessType[BusinessType["OTHER"] = 100694193] = "OTHER";
91
116
  })(BusinessType || (BusinessType = {}));
92
117
  /**
93
- * 图片类型后缀枚举
118
+ * bucket 图片类型后缀枚举
94
119
  */
95
120
  export const SuffixEnum = {
96
121
  nowater: '!nowater',
@@ -99,7 +124,7 @@ export const SuffixEnum = {
99
124
  forum: '!forum',
100
125
  avatar: '!avatar',
101
126
  square: '!square',
102
- carport: '!carport' // 车库、经销商水印
127
+ carport: '!carport', // 车库、经销商水印
103
128
  };
104
129
  /** 不打水印的图片类型 */
105
130
  const NO_WATER_IMAGE_TYPES = ['nowater', 'forum'];
@@ -124,7 +149,7 @@ function randomString(length) {
124
149
  */
125
150
  function filterUndefined(obj) {
126
151
  const result = {};
127
- Object.keys(obj).forEach(key => {
152
+ Object.keys(obj).forEach((key) => {
128
153
  if (obj[key] !== undefined) {
129
154
  result[key] = obj[key];
130
155
  }
@@ -175,19 +200,75 @@ export class AliOssClass {
175
200
  this.apiConfig = apiConfig;
176
201
  this.clientCache = new Map();
177
202
  }
203
+ /**
204
+ * 通过V4签名上传
205
+ * @param file 上传的文件
206
+ * @param businessType 业务类型
207
+ * @param size 文件的尺寸
208
+ * @returns 上传图片结果
209
+ */
210
+ async upload(file, businessType, size) {
211
+ try {
212
+ // -------------------------- 步骤 1:请求后端获取所有签名字段 --------------------------
213
+ const signResponse = await this.apiConfig.getSts({
214
+ businessType,
215
+ docType: file.type,
216
+ size, // _1024_567(可选)
217
+ });
218
+ if (signResponse.data.code !== 0) {
219
+ console.error(signResponse);
220
+ throw new Error(`获取签名失败:${signResponse.data.message}`);
221
+ }
222
+ const signData = await signResponse.data.data;
223
+ console.log('后端返回的签名字段:', signData);
224
+ // -------------------------- 步骤 2:构造 FormData(字段名必须和后端返回一致)--------------------------
225
+ const formData = new FormData();
226
+ formData.append('autherid', signData['autherid']); // 业务字段(原样传)
227
+ formData.append('uid', signData['uid']); // 业务字段(原样传)
228
+ formData.append('key', signData['key']);
229
+ formData.append('policy', signData['policy']);
230
+ formData.append('success_action_status', '200');
231
+ formData.append('x-oss-credential', signData['credential']);
232
+ formData.append('x-oss-date', signData['date']);
233
+ if (signData['securityToken']) {
234
+ formData.append('x-oss-security-token', signData['securityToken']);
235
+ }
236
+ formData.append('x-oss-signature', signData['signature']);
237
+ formData.append('x-oss-signature-version', signData['signatureVersion']);
238
+ formData.append('file', file);
239
+ // -------------------------- 步骤 3:发送 POST 请求到 OSS --------------------------
240
+ const uploadResponse = await fetch(signData.uploadUrl, {
241
+ method: 'POST',
242
+ body: formData,
243
+ // 重点:不要手动设置 Content-Type!浏览器会自动处理为 multipart/form-data 并带边界符
244
+ headers: { Accept: '*/*' },
245
+ });
246
+ // -------------------------- 步骤 4:处理上传结果 --------------------------
247
+ const responseText = await uploadResponse.text();
248
+ console.log('responseText', responseText);
249
+ if (uploadResponse.ok) {
250
+ console.log('上传成功,文件路径:', signData['key'], signData['fileUrl']);
251
+ }
252
+ else {
253
+ throw new Error(`上传失败(OSS 返回 ${uploadResponse.status}):${responseText}`);
254
+ }
255
+ }
256
+ catch (err) {
257
+ console.error('详细错误:', err);
258
+ }
259
+ }
178
260
  /**
179
261
  * 创建OSS客户端
180
262
  * @param businessType 业务类型
181
- * @param imggeCarType 车辆图片类型(可选,用于特定业务)
182
263
  * @returns OSS客户端实例
183
264
  */
184
- async createOssClient(businessType, imggeCarType) {
185
- const cacheKey = `${businessType}_${imggeCarType || 'default'}`;
265
+ async createOssClient(businessType) {
266
+ const cacheKey = `${businessType}`;
186
267
  // 注释:某些项目使用缓存,某些不使用。这里提供可选的缓存机制
187
268
  // if (this.clientCache.has(cacheKey)) {
188
269
  // return this.clientCache.get(cacheKey)
189
270
  // }
190
- const res = await this.apiConfig.getAliyunSts({ businessType, imggeCarType });
271
+ const res = await this.apiConfig.getAliyunSts({ businessType });
191
272
  if (res.data.code !== 0) {
192
273
  throw new Error('获取OSS配置失败');
193
274
  }
@@ -197,23 +278,42 @@ export class AliOssClass {
197
278
  const filteredParams = filterUndefined(clientParams);
198
279
  const client = new OSS({
199
280
  region: DEFAULT_OSS_REGION,
200
- ...filteredParams
281
+ ...filteredParams,
201
282
  });
202
283
  // 保存客户端选项供后续使用
203
284
  client.options = {
204
285
  ...client.options,
205
286
  realmName: clientParams.realmName,
206
- suffix: clientParams.suffix
287
+ suffix: clientParams.suffix,
207
288
  };
208
289
  this.clientCache.set(cacheKey, client);
209
290
  return client;
210
291
  }
292
+ /**
293
+ * 执行OSS上传
294
+ * @param client OSS客户端
295
+ * @param fileName 文件名
296
+ * @param file 文件对象
297
+ * @param year 年份
298
+ * @param mimeType MIME类型
299
+ * @param onProgress 进度回调
300
+ * @returns 上传结果
301
+ */
302
+ async performOssUpload(client, fileName, file, year, mimeType, onProgress) {
303
+ return await client.multipartUpload(fileName, file, {
304
+ progress: (p) => {
305
+ onProgress?.({ percent: Math.floor(p * 100) });
306
+ },
307
+ meta: { year, people: OSS_META_PEOPLE },
308
+ mime: mimeType,
309
+ });
310
+ }
211
311
  /**
212
312
  * 预加载图片获取尺寸
213
313
  * @param file 文件对象
214
314
  * @returns 图片对象
215
315
  */
216
- imgUpload(file) {
316
+ getImageInfo(file) {
217
317
  return new Promise((resolve, reject) => {
218
318
  const URL = window.URL || window.webkitURL;
219
319
  const image = new Image();
@@ -255,25 +355,6 @@ export class AliOssClass {
255
355
  const minDimension = Math.min(width, height);
256
356
  return maxDimension / minDimension > LONG_IMAGE_RATIO;
257
357
  }
258
- /**
259
- * 执行OSS上传
260
- * @param client OSS客户端
261
- * @param fileName 文件名
262
- * @param file 文件对象
263
- * @param year 年份
264
- * @param mimeType MIME类型
265
- * @param onProgress 进度回调
266
- * @returns 上传结果
267
- */
268
- async performOssUpload(client, fileName, file, year, mimeType, onProgress) {
269
- return await client.multipartUpload(fileName, file, {
270
- progress: (p) => {
271
- onProgress?.({ percent: Math.floor(p * 100) });
272
- },
273
- meta: { year, people: OSS_META_PEOPLE },
274
- mime: mimeType
275
- });
276
- }
277
358
  /**
278
359
  * 确定业务类型
279
360
  * @param option 上传选项
@@ -295,9 +376,9 @@ export class AliOssClass {
295
376
  return BusinessType.AVATAR;
296
377
  }
297
378
  if (isNoWaterImageType(imageType)) {
298
- return BusinessType.NO_WATER;
379
+ return BusinessType.OTHER;
299
380
  }
300
- return BusinessType.DEFAULT;
381
+ return BusinessType.OTHER;
301
382
  }
302
383
  /**
303
384
  * 加载图片并返回结果
@@ -368,7 +449,7 @@ export class AliOssClass {
368
449
  const callbacks = {
369
450
  onError: option.onError || (() => { }),
370
451
  onSuccess: option.onSuccess || (() => { }),
371
- onProgress: option.onProgress || (() => { })
452
+ onProgress: option.onProgress || (() => { }),
372
453
  };
373
454
  option.onError = callbacks.onError;
374
455
  option.onSuccess = callbacks.onSuccess;
@@ -382,27 +463,28 @@ export class AliOssClass {
382
463
  return new Promise(async (resolve, reject) => {
383
464
  try {
384
465
  const imageType = option.imageType || DEFAULT_IMAGE_TYPE;
385
- const suffix = SuffixEnum[imageType] || SuffixEnum.official;
466
+ const suffix = SuffixEnum[imageType] ||
467
+ SuffixEnum.official;
386
468
  // 生成文件名
387
469
  const extensionName = `.${file.name.split('.').pop()}`;
388
470
  const { year, fileName } = this.generateFileName(imageType, extensionName);
389
471
  // 注释:小图片(≤100KB)不压缩,quality设为1 (MAIN-2481)
390
472
  const isSmallImage = getFileSizeInKB(file.size) <= SMALL_IMAGE_THRESHOLD;
391
- let quality = isSmallImage ? 1 : (option.quality || DEFAULT_QUALITY);
473
+ let quality = isSmallImage ? 1 : option.quality || DEFAULT_QUALITY;
392
474
  const isGif = file.type === 'image/gif';
393
475
  const idCard = option.idCard || false;
394
476
  // 确定业务类型
395
477
  const businessType = this.determineBusinessType(option, isGif);
396
478
  // 注释:特殊业务类型1299(加密)直接返回bucket路径,不加载图片
397
- if (businessType === BusinessType.ENCRYPTED) {
398
- const client = await this.createOssClient(businessType, option.imggeCarType);
479
+ if (businessType === BusinessType.OTHER) {
480
+ const client = await this.createOssClient(businessType);
399
481
  const result = await this.performOssUpload(client, fileName, file, year, file.type, callbacks.onProgress);
400
482
  if (result.res.statusCode === 200) {
401
483
  const val = {
402
484
  ...result,
403
485
  imgUrl: `${result.bucket}://${result.name}`,
404
486
  imgOrgUrl: `${result.bucket}://${result.name}`,
405
- fileName: file.name
487
+ fileName: file.name,
406
488
  };
407
489
  callbacks.onSuccess(val);
408
490
  resolve(val);
@@ -424,7 +506,7 @@ export class AliOssClass {
424
506
  option,
425
507
  file,
426
508
  resolve,
427
- reject
509
+ reject,
428
510
  });
429
511
  }
430
512
  else {
@@ -434,7 +516,8 @@ export class AliOssClass {
434
516
  return;
435
517
  }
436
518
  // 注释:carport类型需要打暗水印
437
- if (option.imageType === 'carport' && this.apiConfig.darkWaterUploadImage) {
519
+ if (option.imageType === 'carport' &&
520
+ this.apiConfig.darkWaterUploadImage) {
438
521
  const res = await this.apiConfig.darkWaterUploadImage({ file });
439
522
  if (res.data.code === 0) {
440
523
  this.loadImage({
@@ -444,7 +527,7 @@ export class AliOssClass {
444
527
  option,
445
528
  file,
446
529
  resolve,
447
- reject
530
+ reject,
448
531
  });
449
532
  }
450
533
  else {
@@ -454,7 +537,7 @@ export class AliOssClass {
454
537
  return;
455
538
  }
456
539
  // 预加载图片获取尺寸
457
- const image = await this.imgUpload(file);
540
+ const image = await this.getImageInfo(file);
458
541
  // 图片压缩
459
542
  const rst = await lrz(file, { quality });
460
543
  // 注释:长图压缩有问题,长宽比>2:1的图片不压缩
@@ -481,13 +564,12 @@ export class AliOssClass {
481
564
  if (!postFile.name) {
482
565
  Object.defineProperty(postFile, 'name', {
483
566
  value: file.name,
484
- writable: false
567
+ writable: false,
485
568
  });
486
569
  }
487
570
  // 注释:根据不同场景选择不同的OSS客户端
488
571
  // GIF -> UnProtect(8), idCard -> Private(1199), nowater/forum -> NoWater(0), 其他 -> 默认
489
- const client = await this.createOssClient(businessType, option.imggeCarType);
490
- // 执行上传
572
+ const client = await this.createOssClient(businessType);
491
573
  const result = await this.performOssUpload(client, fileName, postFile, year, postFile.type, callbacks.onProgress);
492
574
  if (result.res.statusCode !== 200) {
493
575
  callbacks.onError('上传失败');
@@ -498,7 +580,7 @@ export class AliOssClass {
498
580
  if (idCard && this.apiConfig.generatePrePresignedUrl) {
499
581
  const res = await this.apiConfig.generatePrePresignedUrl({
500
582
  objectId: result.name,
501
- expireMils: PRESIGNED_URL_EXPIRE_TIME
583
+ expireMils: PRESIGNED_URL_EXPIRE_TIME,
502
584
  });
503
585
  if (res.data.code === 0) {
504
586
  this.loadImageNew({
@@ -507,7 +589,7 @@ export class AliOssClass {
507
589
  file: postFile,
508
590
  option,
509
591
  resolve,
510
- reject
592
+ reject,
511
593
  });
512
594
  }
513
595
  else {
@@ -520,7 +602,7 @@ export class AliOssClass {
520
602
  if (imageType === 'avatar' && this.apiConfig.aliyunPersist) {
521
603
  const res = await this.apiConfig.aliyunPersist({
522
604
  object: `${result.bucket}://${result.name}`,
523
- businessType: BusinessType.AVATAR
605
+ businessType: BusinessType.AVATAR,
524
606
  });
525
607
  if (res.data.code === 0) {
526
608
  this.loadImageNew({
@@ -529,7 +611,7 @@ export class AliOssClass {
529
611
  file: postFile,
530
612
  option,
531
613
  resolve,
532
- reject
614
+ reject,
533
615
  });
534
616
  }
535
617
  else {
@@ -549,7 +631,7 @@ export class AliOssClass {
549
631
  option,
550
632
  resolve,
551
633
  reject,
552
- isGif
634
+ isGif,
553
635
  });
554
636
  }
555
637
  catch (error) {
@@ -574,7 +656,7 @@ export class AliOssClass {
574
656
  const callbacks = {
575
657
  onError: option.onError || (() => { }),
576
658
  onSuccess: option.onSuccess || (() => { }),
577
- onProgress: option.onProgress || (() => { })
659
+ onProgress: option.onProgress || (() => { }),
578
660
  };
579
661
  option.onError = callbacks.onError;
580
662
  option.onSuccess = callbacks.onSuccess;
@@ -593,21 +675,20 @@ export class AliOssClass {
593
675
  let businessType = option.businessType;
594
676
  if (!businessType) {
595
677
  if (isUnProtect) {
596
- businessType = BusinessType.UNPROTECT;
678
+ businessType = BusinessType.OTHER;
597
679
  }
598
680
  else if (isVideo || isDocument) {
599
- businessType = BusinessType.VIDEO; // 视频和文档都使用6
681
+ businessType = BusinessType.OTHER; // 视频和文档都使用6
600
682
  }
601
683
  else {
602
- businessType = BusinessType.DEFAULT;
684
+ businessType = BusinessType.OTHER;
603
685
  }
604
686
  }
605
687
  // 注释:文档上传可能需要先调用uploadConf获取配置
606
688
  if (isDocument && this.apiConfig.uploadConf) {
607
689
  await this.apiConfig.uploadConf(businessType);
608
690
  }
609
- const client = await this.createOssClient(businessType, option.imggeCarType);
610
- // 执行上传
691
+ const client = await this.createOssClient(businessType);
611
692
  const result = await this.performOssUpload(client, fileName, file, year, file.type, callbacks.onProgress);
612
693
  if (result.res.statusCode === 200) {
613
694
  const clientParams = client.options;
@@ -615,7 +696,7 @@ export class AliOssClass {
615
696
  const uploadResult = {
616
697
  ...result,
617
698
  url,
618
- fileName: file.name
699
+ fileName: file.name,
619
700
  };
620
701
  callbacks.onSuccess(uploadResult);
621
702
  resolve(uploadResult);
@@ -647,7 +728,7 @@ export class AliOssClass {
647
728
  const callbacks = {
648
729
  onError: option.onError || (() => { }),
649
730
  onSuccess: option.onSuccess || (() => { }),
650
- onProgress: option.onProgress || (() => { })
731
+ onProgress: option.onProgress || (() => { }),
651
732
  };
652
733
  option.onError = callbacks.onError;
653
734
  option.onSuccess = callbacks.onSuccess;
@@ -668,15 +749,15 @@ export class AliOssClass {
668
749
  return;
669
750
  }
670
751
  // 预加载图片(虽然不需要尺寸,但保持原有逻辑)
671
- await this.imgUpload(file);
752
+ await this.getImageInfo(file);
672
753
  const imageType = option.imageType || DEFAULT_IMAGE_TYPE;
673
- const suffix = SuffixEnum[imageType] || SuffixEnum.official;
754
+ const suffix = SuffixEnum[imageType] ||
755
+ SuffixEnum.official;
674
756
  // 生成文件名
675
757
  const extensionName = `.${file.name.split('.').pop()}`;
676
758
  const { year, fileName } = this.generateFileName(imageType, extensionName);
677
759
  // 使用NoWater客户端
678
- const client = await this.createOssClient(BusinessType.NO_WATER, option.imggeCarType);
679
- // 执行上传
760
+ const client = await this.createOssClient(BusinessType.OTHER);
680
761
  const result = await this.performOssUpload(client, fileName, file, year, file.type, callbacks.onProgress);
681
762
  if (result.res.statusCode === 200) {
682
763
  const clientParams = client.options;
@@ -688,7 +769,7 @@ export class AliOssClass {
688
769
  file,
689
770
  option,
690
771
  resolve,
691
- reject
772
+ reject,
692
773
  });
693
774
  }
694
775
  else {
@@ -731,5 +812,5 @@ export function createAliOssUploader(apiConfig) {
731
812
  export default {
732
813
  createAliOssUploader,
733
814
  BusinessType,
734
- SuffixEnum
815
+ SuffixEnum,
735
816
  };