@onyx-p/imlib-web 2.3.7 → 2.3.8

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/index.esm.js CHANGED
@@ -7648,7 +7648,7 @@ function requireCryptoJs () {
7648
7648
  }
7649
7649
 
7650
7650
  var cryptoJsExports = requireCryptoJs();
7651
- var CryptoJS$1 = /*@__PURE__*/getDefaultExportFromCjs(cryptoJsExports);
7651
+ var CryptoJS = /*@__PURE__*/getDefaultExportFromCjs(cryptoJsExports);
7652
7652
 
7653
7653
  function getType(value) {
7654
7654
  return Object.prototype.toString.call(value).slice(8, -1);
@@ -7735,8 +7735,8 @@ const throttle = (fn, delay = 200) => {
7735
7735
  };
7736
7736
  };
7737
7737
 
7738
- const AesKey = CryptoJS$1.enc.Utf8.parse('skdjhfgc9829kslf');
7739
- const AesIv = CryptoJS$1.enc.Utf8.parse('qwdkshjf9838jsdf');
7738
+ const AesKey = CryptoJS.enc.Utf8.parse('skdjhfgc9829kslf');
7739
+ const AesIv = CryptoJS.enc.Utf8.parse('qwdkshjf9838jsdf');
7740
7740
  const isElectron = () => {
7741
7741
  return typeof process !== 'undefined' && typeof process.versions !== 'undefined' && !!process.versions.electron;
7742
7742
  };
@@ -7795,12 +7795,12 @@ const SecureStorageService = {
7795
7795
  return null;
7796
7796
  }
7797
7797
  if (isDef(value)) {
7798
- const encryptedHexStr = CryptoJS$1.enc.Hex.parse(value);
7799
- const srcs = CryptoJS$1.enc.Base64.stringify(encryptedHexStr);
7800
- const decrypt = CryptoJS$1.AES.decrypt(srcs, AesKey, {
7798
+ const encryptedHexStr = CryptoJS.enc.Hex.parse(value);
7799
+ const srcs = CryptoJS.enc.Base64.stringify(encryptedHexStr);
7800
+ const decrypt = CryptoJS.AES.decrypt(srcs, AesKey, {
7801
7801
  iv: AesIv
7802
7802
  });
7803
- value = decrypt.toString(CryptoJS$1.enc.Utf8);
7803
+ value = decrypt.toString(CryptoJS.enc.Utf8);
7804
7804
  }
7805
7805
  if (!isDef(value)) {
7806
7806
  return value;
@@ -7817,7 +7817,7 @@ const SecureStorageService = {
7817
7817
  this.remove(key);
7818
7818
  return;
7819
7819
  }
7820
- const encryptedData = CryptoJS$1.AES.encrypt(JSON.stringify(value), AesKey, {
7820
+ const encryptedData = CryptoJS.AES.encrypt(JSON.stringify(value), AesKey, {
7821
7821
  iv: AesIv
7822
7822
  });
7823
7823
  const encrytedStr = encryptedData.ciphertext.toString();
@@ -19554,18 +19554,18 @@ const aes256Encrypt = (message, secretKey) => {
19554
19554
  if (!notEmptyString(message)) {
19555
19555
  return '';
19556
19556
  }
19557
- const encryptedData = CryptoJS$1.AES.encrypt(message, CryptoJS$1.enc.Utf8.parse(secretKey.key), {
19558
- iv: isDef(secretKey.iv) ? CryptoJS$1.enc.Utf8.parse(secretKey.iv) : undefined
19557
+ const encryptedData = CryptoJS.AES.encrypt(message, CryptoJS.enc.Utf8.parse(secretKey.key), {
19558
+ iv: isDef(secretKey.iv) ? CryptoJS.enc.Utf8.parse(secretKey.iv) : undefined
19559
19559
  });
19560
19560
  return Array.from(wordToUInt8Array(encryptedData.ciphertext.words)).map(byte => byte.toString(16).padStart(2, '0')).join('');
19561
19561
  };
19562
19562
  const aes256Decrypt = (cipherHex, secretKey) => {
19563
19563
  const cipherData = new Uint8Array(cipherHex.match(/.{1,2}/g)?.map(byte => parseInt(byte, 16)) || []);
19564
19564
  const srcs = window.btoa(String.fromCharCode(...cipherData));
19565
- const decrypt = CryptoJS$1.AES.decrypt(srcs, CryptoJS$1.enc.Utf8.parse(secretKey.key), {
19566
- iv: isDef(secretKey.iv) ? CryptoJS$1.enc.Utf8.parse(secretKey.iv) : undefined
19565
+ const decrypt = CryptoJS.AES.decrypt(srcs, CryptoJS.enc.Utf8.parse(secretKey.key), {
19566
+ iv: isDef(secretKey.iv) ? CryptoJS.enc.Utf8.parse(secretKey.iv) : undefined
19567
19567
  });
19568
- return decrypt.toString(CryptoJS$1.enc.Utf8);
19568
+ return decrypt.toString(CryptoJS.enc.Utf8);
19569
19569
  };
19570
19570
  const wordToUInt8Array = wordArray => {
19571
19571
  const array = [];
@@ -20744,14 +20744,14 @@ class MessageCache {
20744
20744
  }
20745
20745
  generateEncryptKey(appKey, userId) {
20746
20746
  const saltedInput = `${this.SALT_PREFIX}${appKey}_${userId}${this.SALT_SUFFIX}`;
20747
- const keyMaterial = CryptoJS$1.SHA256(saltedInput).toString();
20747
+ const keyMaterial = CryptoJS.SHA256(saltedInput).toString();
20748
20748
  const iv = keyMaterial.substring(0, 16);
20749
20749
  const key = keyMaterial.substring(16, 48);
20750
- const additionalSalt = CryptoJS$1.SHA256(`${iv}:${this.SALT_PREFIX}:${userId}:${appKey}`).toString().substring(0, 8);
20751
- const finalKey = CryptoJS$1.PBKDF2(key, additionalSalt, {
20750
+ const additionalSalt = CryptoJS.SHA256(`${iv}:${this.SALT_PREFIX}:${userId}:${appKey}`).toString().substring(0, 8);
20751
+ const finalKey = CryptoJS.PBKDF2(key, additionalSalt, {
20752
20752
  keySize: 256 / 32,
20753
20753
  iterations: 1000,
20754
- hasher: CryptoJS$1.algo.SHA256
20754
+ hasher: CryptoJS.algo.SHA256
20755
20755
  }).toString();
20756
20756
  this.encryptKey = {
20757
20757
  key: finalKey.substring(0, 32),
@@ -28942,13 +28942,21 @@ async function createSendFunction(fileType, conversation, msgBody, hooks, sendOp
28942
28942
  }
28943
28943
  message1.content.user = msgBody.user;
28944
28944
  message1.content.extra = msgBody.extra;
28945
- const encryptKey = generateEncryptKey();
28945
+ const uploader = imConfig.getUploader();
28946
+ const prepareResult = await uploader.prepare(files);
28947
+ const uploadItems = files.map((file, i) => ({
28948
+ url: prepareResult.urls[i],
28949
+ file: file
28950
+ }));
28951
+ const mediaUploadParams = {
28952
+ encryptKey: prepareResult.encryptedKey,
28953
+ items: uploadItems
28954
+ };
28946
28955
  return internal_sendMessage(conversation, message1, sendOptions, {
28947
- files,
28948
- encryptKey: encryptKey,
28949
- task: (message2, toBeUploadedFiles) => {
28956
+ uploadItems: mediaUploadParams,
28957
+ task: (message2, uploadItems) => {
28950
28958
  return new Promise(resolve => {
28951
- imConfig.getUploader().upload(toBeUploadedFiles, encryptKey, {
28959
+ uploader.upload(uploadItems, {
28952
28960
  onProgress: progress => hooks?.onProgress?.(progress),
28953
28961
  onError: () => {
28954
28962
  resolve({
@@ -28969,7 +28977,7 @@ async function createSendFunction(fileType, conversation, msgBody, hooks, sendOp
28969
28977
  });
28970
28978
  }
28971
28979
  async function internal_sendMessage(conversation, message, options, uploadOptions) {
28972
- const checkResult = await beforeSend(conversation, message, options, uploadOptions);
28980
+ const checkResult = await beforeSend(conversation, message, options, uploadOptions?.uploadItems);
28973
28981
  if (checkResult.code !== ErrorCode.SUCCESS || !checkResult.message || !checkResult.sentArgs) {
28974
28982
  return {
28975
28983
  code: checkResult.code
@@ -28984,7 +28992,7 @@ async function internal_sendMessage(conversation, message, options, uploadOption
28984
28992
  sentArgs
28985
28993
  } = checkResult;
28986
28994
  if (isDef(uploadOptions)) {
28987
- const uploadResult = await uploadOptions.task(sentMessage, uploadOptions.files);
28995
+ const uploadResult = await uploadOptions.task(sentMessage, uploadOptions.uploadItems);
28988
28996
  sentMessage = uploadResult.message;
28989
28997
  if (!uploadResult.finished) {
28990
28998
  const receivedMessage = transSentAttrs2IReceivedMessage(checkResult.message, checkResult.sentArgs, SentStatus.FAILED);
@@ -29116,15 +29124,6 @@ async function saveSentMessage(receivedMessage, options) {
29116
29124
  logger.error('saveSentMessage -> ', error);
29117
29125
  }
29118
29126
  }
29119
- function generateEncryptKey() {
29120
- const data = new Uint8Array(16);
29121
- for (let i = 0; i < 16; i++) {
29122
- data[i] = 65 + Math.floor(Math.random() * 26);
29123
- }
29124
- const key = String.fromCharCode(...data);
29125
- const md5Hash = CryptoJS.MD5(key).toString();
29126
- return md5Hash;
29127
- }
29128
29127
 
29129
29128
  class IMClient extends EventEmitter {
29130
29129
  options;
@@ -30342,7 +30341,7 @@ const login = config => {
30342
30341
  return webSocketServer.request(0x30011011, {
30343
30342
  langCode: config.langCode,
30344
30343
  phoneNum: config.phone,
30345
- password: CryptoJS$1.SHA256(config.password).toString(),
30344
+ password: CryptoJS.SHA256(config.password).toString(),
30346
30345
  deviceType: 7,
30347
30346
  imei: '59bc678b-fe6d-4e67-87c6-b0692205134b',
30348
30347
  brand: 'Chrome',
package/index.umd.js CHANGED
@@ -7654,7 +7654,7 @@
7654
7654
  }
7655
7655
 
7656
7656
  var cryptoJsExports = requireCryptoJs();
7657
- var CryptoJS$1 = /*@__PURE__*/getDefaultExportFromCjs(cryptoJsExports);
7657
+ var CryptoJS = /*@__PURE__*/getDefaultExportFromCjs(cryptoJsExports);
7658
7658
 
7659
7659
  function getType(value) {
7660
7660
  return Object.prototype.toString.call(value).slice(8, -1);
@@ -7741,8 +7741,8 @@
7741
7741
  };
7742
7742
  };
7743
7743
 
7744
- const AesKey = CryptoJS$1.enc.Utf8.parse('skdjhfgc9829kslf');
7745
- const AesIv = CryptoJS$1.enc.Utf8.parse('qwdkshjf9838jsdf');
7744
+ const AesKey = CryptoJS.enc.Utf8.parse('skdjhfgc9829kslf');
7745
+ const AesIv = CryptoJS.enc.Utf8.parse('qwdkshjf9838jsdf');
7746
7746
  const isElectron = () => {
7747
7747
  return typeof process !== 'undefined' && typeof process.versions !== 'undefined' && !!process.versions.electron;
7748
7748
  };
@@ -7801,12 +7801,12 @@
7801
7801
  return null;
7802
7802
  }
7803
7803
  if (isDef(value)) {
7804
- const encryptedHexStr = CryptoJS$1.enc.Hex.parse(value);
7805
- const srcs = CryptoJS$1.enc.Base64.stringify(encryptedHexStr);
7806
- const decrypt = CryptoJS$1.AES.decrypt(srcs, AesKey, {
7804
+ const encryptedHexStr = CryptoJS.enc.Hex.parse(value);
7805
+ const srcs = CryptoJS.enc.Base64.stringify(encryptedHexStr);
7806
+ const decrypt = CryptoJS.AES.decrypt(srcs, AesKey, {
7807
7807
  iv: AesIv
7808
7808
  });
7809
- value = decrypt.toString(CryptoJS$1.enc.Utf8);
7809
+ value = decrypt.toString(CryptoJS.enc.Utf8);
7810
7810
  }
7811
7811
  if (!isDef(value)) {
7812
7812
  return value;
@@ -7823,7 +7823,7 @@
7823
7823
  this.remove(key);
7824
7824
  return;
7825
7825
  }
7826
- const encryptedData = CryptoJS$1.AES.encrypt(JSON.stringify(value), AesKey, {
7826
+ const encryptedData = CryptoJS.AES.encrypt(JSON.stringify(value), AesKey, {
7827
7827
  iv: AesIv
7828
7828
  });
7829
7829
  const encrytedStr = encryptedData.ciphertext.toString();
@@ -19560,18 +19560,18 @@
19560
19560
  if (!notEmptyString(message)) {
19561
19561
  return '';
19562
19562
  }
19563
- const encryptedData = CryptoJS$1.AES.encrypt(message, CryptoJS$1.enc.Utf8.parse(secretKey.key), {
19564
- iv: isDef(secretKey.iv) ? CryptoJS$1.enc.Utf8.parse(secretKey.iv) : undefined
19563
+ const encryptedData = CryptoJS.AES.encrypt(message, CryptoJS.enc.Utf8.parse(secretKey.key), {
19564
+ iv: isDef(secretKey.iv) ? CryptoJS.enc.Utf8.parse(secretKey.iv) : undefined
19565
19565
  });
19566
19566
  return Array.from(wordToUInt8Array(encryptedData.ciphertext.words)).map(byte => byte.toString(16).padStart(2, '0')).join('');
19567
19567
  };
19568
19568
  const aes256Decrypt = (cipherHex, secretKey) => {
19569
19569
  const cipherData = new Uint8Array(cipherHex.match(/.{1,2}/g)?.map(byte => parseInt(byte, 16)) || []);
19570
19570
  const srcs = window.btoa(String.fromCharCode(...cipherData));
19571
- const decrypt = CryptoJS$1.AES.decrypt(srcs, CryptoJS$1.enc.Utf8.parse(secretKey.key), {
19572
- iv: isDef(secretKey.iv) ? CryptoJS$1.enc.Utf8.parse(secretKey.iv) : undefined
19571
+ const decrypt = CryptoJS.AES.decrypt(srcs, CryptoJS.enc.Utf8.parse(secretKey.key), {
19572
+ iv: isDef(secretKey.iv) ? CryptoJS.enc.Utf8.parse(secretKey.iv) : undefined
19573
19573
  });
19574
- return decrypt.toString(CryptoJS$1.enc.Utf8);
19574
+ return decrypt.toString(CryptoJS.enc.Utf8);
19575
19575
  };
19576
19576
  const wordToUInt8Array = wordArray => {
19577
19577
  const array = [];
@@ -20750,14 +20750,14 @@
20750
20750
  }
20751
20751
  generateEncryptKey(appKey, userId) {
20752
20752
  const saltedInput = `${this.SALT_PREFIX}${appKey}_${userId}${this.SALT_SUFFIX}`;
20753
- const keyMaterial = CryptoJS$1.SHA256(saltedInput).toString();
20753
+ const keyMaterial = CryptoJS.SHA256(saltedInput).toString();
20754
20754
  const iv = keyMaterial.substring(0, 16);
20755
20755
  const key = keyMaterial.substring(16, 48);
20756
- const additionalSalt = CryptoJS$1.SHA256(`${iv}:${this.SALT_PREFIX}:${userId}:${appKey}`).toString().substring(0, 8);
20757
- const finalKey = CryptoJS$1.PBKDF2(key, additionalSalt, {
20756
+ const additionalSalt = CryptoJS.SHA256(`${iv}:${this.SALT_PREFIX}:${userId}:${appKey}`).toString().substring(0, 8);
20757
+ const finalKey = CryptoJS.PBKDF2(key, additionalSalt, {
20758
20758
  keySize: 256 / 32,
20759
20759
  iterations: 1000,
20760
- hasher: CryptoJS$1.algo.SHA256
20760
+ hasher: CryptoJS.algo.SHA256
20761
20761
  }).toString();
20762
20762
  this.encryptKey = {
20763
20763
  key: finalKey.substring(0, 32),
@@ -28948,13 +28948,21 @@
28948
28948
  }
28949
28949
  message1.content.user = msgBody.user;
28950
28950
  message1.content.extra = msgBody.extra;
28951
- const encryptKey = generateEncryptKey();
28951
+ const uploader = imConfig.getUploader();
28952
+ const prepareResult = await uploader.prepare(files);
28953
+ const uploadItems = files.map((file, i) => ({
28954
+ url: prepareResult.urls[i],
28955
+ file: file
28956
+ }));
28957
+ const mediaUploadParams = {
28958
+ encryptKey: prepareResult.encryptedKey,
28959
+ items: uploadItems
28960
+ };
28952
28961
  return internal_sendMessage(conversation, message1, sendOptions, {
28953
- files,
28954
- encryptKey: encryptKey,
28955
- task: (message2, toBeUploadedFiles) => {
28962
+ uploadItems: mediaUploadParams,
28963
+ task: (message2, uploadItems) => {
28956
28964
  return new Promise(resolve => {
28957
- imConfig.getUploader().upload(toBeUploadedFiles, encryptKey, {
28965
+ uploader.upload(uploadItems, {
28958
28966
  onProgress: progress => hooks?.onProgress?.(progress),
28959
28967
  onError: () => {
28960
28968
  resolve({
@@ -28975,7 +28983,7 @@
28975
28983
  });
28976
28984
  }
28977
28985
  async function internal_sendMessage(conversation, message, options, uploadOptions) {
28978
- const checkResult = await beforeSend(conversation, message, options, uploadOptions);
28986
+ const checkResult = await beforeSend(conversation, message, options, uploadOptions?.uploadItems);
28979
28987
  if (checkResult.code !== exports.ErrorCode.SUCCESS || !checkResult.message || !checkResult.sentArgs) {
28980
28988
  return {
28981
28989
  code: checkResult.code
@@ -28990,7 +28998,7 @@
28990
28998
  sentArgs
28991
28999
  } = checkResult;
28992
29000
  if (isDef(uploadOptions)) {
28993
- const uploadResult = await uploadOptions.task(sentMessage, uploadOptions.files);
29001
+ const uploadResult = await uploadOptions.task(sentMessage, uploadOptions.uploadItems);
28994
29002
  sentMessage = uploadResult.message;
28995
29003
  if (!uploadResult.finished) {
28996
29004
  const receivedMessage = transSentAttrs2IReceivedMessage(checkResult.message, checkResult.sentArgs, exports.SentStatus.FAILED);
@@ -29122,15 +29130,6 @@
29122
29130
  logger.error('saveSentMessage -> ', error);
29123
29131
  }
29124
29132
  }
29125
- function generateEncryptKey() {
29126
- const data = new Uint8Array(16);
29127
- for (let i = 0; i < 16; i++) {
29128
- data[i] = 65 + Math.floor(Math.random() * 26);
29129
- }
29130
- const key = String.fromCharCode(...data);
29131
- const md5Hash = CryptoJS.MD5(key).toString();
29132
- return md5Hash;
29133
- }
29134
29133
 
29135
29134
  class IMClient extends EventEmitter {
29136
29135
  options;
@@ -30348,7 +30347,7 @@
30348
30347
  return webSocketServer.request(0x30011011, {
30349
30348
  langCode: config.langCode,
30350
30349
  phoneNum: config.phone,
30351
- password: CryptoJS$1.SHA256(config.password).toString(),
30350
+ password: CryptoJS.SHA256(config.password).toString(),
30352
30351
  deviceType: 7,
30353
30352
  imei: '59bc678b-fe6d-4e67-87c6-b0692205134b',
30354
30353
  brand: 'Chrome',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@onyx-p/imlib-web",
3
- "version": "2.3.7",
3
+ "version": "2.3.8",
4
4
  "main": "index.umd.js",
5
5
  "module": "index.esm.js",
6
6
  "types": "types/index.d.ts",
package/types/types.d.ts CHANGED
@@ -130,10 +130,6 @@ export type IPushConfig = {
130
130
  */
131
131
  pushData?: string;
132
132
  };
133
- export interface IUploadMessageParams {
134
- files: Blob[];
135
- encryptKey: string;
136
- }
137
133
  /**
138
134
  * 发送消息时的可选项信息
139
135
  */
@@ -170,11 +166,22 @@ export interface IUploadHooks {
170
166
  /**
171
167
  * 文件上传完成回调,可通过修改返回值以修改待发布的消息内容,如实现自定义消息
172
168
  */
173
- onComplete?: (fileInfo: IUploadCompletedResult) => void | BaseMessage;
169
+ onComplete?: (result: IUploadCompletedResult) => void | BaseMessage;
170
+ }
171
+ export type IUploadPrepareResult = {
172
+ urls: string[];
173
+ encryptedKey: string;
174
+ };
175
+ export interface IUploadMessageParams {
176
+ items: {
177
+ url: string;
178
+ file: Blob;
179
+ }[];
180
+ encryptKey: string;
174
181
  }
175
182
  export type IUploadCompletedResult = {
176
183
  urls: string[];
177
- encryptedKey?: string;
184
+ encryptedKey: string;
178
185
  };
179
186
  export type IUploadCallback = {
180
187
  onProgress?: (progress: number) => void;
@@ -182,8 +189,9 @@ export type IUploadCallback = {
182
189
  onError?: (reason: string) => void;
183
190
  };
184
191
  export interface IUploader {
185
- upload(files: Blob[], encryptKey: string, callback: IUploadCallback): void;
192
+ upload(params: IUploadMessageParams, callback: IUploadCallback): void;
186
193
  cancel(): void;
194
+ prepare(files: Blob[]): Promise<IUploadPrepareResult>;
187
195
  }
188
196
  /**
189
197
  * 文件消息配置