@kevisual/api 0.0.6 → 0.0.7

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kevisual/api",
3
- "version": "0.0.6",
3
+ "version": "0.0.7",
4
4
  "description": "",
5
5
  "main": "mod.ts",
6
6
  "scripts": {
@@ -35,5 +35,11 @@
35
35
  "@kevisual/load": "^0.0.6",
36
36
  "es-toolkit": "^1.43.0",
37
37
  "nanoid": "^5.1.6"
38
+ },
39
+ "exports": {
40
+ ".": "./mod.ts",
41
+ "./login": "./query/query-login/query-login-browser.ts",
42
+ "./login-node": "./query/query-login/query-login-node.ts",
43
+ "./query/**/*.ts": "./query/**/*.ts"
38
44
  }
39
45
  }
@@ -425,15 +425,23 @@ import MD5 from 'crypto-js/md5.js';
425
425
  import jsonwebtoken from 'jsonwebtoken';
426
426
 
427
427
  */
428
- loginWithWeb(baseURL: string, { MD5, jsonwebtoken }: { MD5: any; jsonwebtoken: any }) {
428
+ loginWithWeb(baseURL: string, { MD5, jsonwebtoken }: { MD5?: any; jsonwebtoken?: any }) {
429
429
  const randomId = Math.random().toString(36).substring(2, 15);
430
430
  const timestamp = Date.now();
431
431
  const tokenSecret = 'xiao' + randomId;
432
- const sign = MD5(`${tokenSecret}${timestamp}`).toString();
433
- const token = jsonwebtoken.sign({ randomId, timestamp, sign }, tokenSecret, {
434
- // 10分钟过期
435
- expiresIn: 60 * 10, // 10分钟
436
- });
432
+ let sign = '';
433
+ if (MD5) {
434
+ sign = MD5(`${tokenSecret}${timestamp}`).toString();
435
+ }
436
+ let token = '';
437
+ if (jsonwebtoken) {
438
+ token = jsonwebtoken.sign({ randomId, timestamp, sign }, tokenSecret, {
439
+ // 10分钟过期
440
+ expiresIn: 60 * 10, // 10分钟
441
+ });
442
+ } else {
443
+ token = tokenSecret;
444
+ }
437
445
  const url = `${baseURL}/api/router?path=user&key=webLogin&p&loginToken=${token}&sign=${sign}&randomId=${randomId}`;
438
446
  return { url, token, tokenSecret };
439
447
  }