@peng_kai/kit 0.2.49 → 0.2.50
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,7 @@
|
|
|
1
1
|
import type { AxiosInterceptorManager } from 'axios';
|
|
2
2
|
import FingerprintJS from '@fingerprintjs/fingerprintjs';
|
|
3
3
|
import type { GetResult } from '@fingerprintjs/fingerprintjs';
|
|
4
|
+
import { toBase64 } from '../../utils/string';
|
|
4
5
|
|
|
5
6
|
/**
|
|
6
7
|
* 【请求拦截器】检索设备信息并在请求中设置“Device”头。
|
|
@@ -24,8 +25,16 @@ export function getDeviceInfo(callback: (base: Record<string, any>, all: GetResu
|
|
|
24
25
|
};
|
|
25
26
|
|
|
26
27
|
req.headers.set('Device', callback(base, result));
|
|
28
|
+
req.headers.set('Accept-Date', getCurrentTimeZone());
|
|
27
29
|
|
|
28
30
|
return req;
|
|
29
31
|
},
|
|
30
32
|
];
|
|
31
33
|
}
|
|
34
|
+
|
|
35
|
+
function getCurrentTimeZone() {
|
|
36
|
+
const now = new Date();
|
|
37
|
+
const [_, time, tz, describe] = now.toString().match(/(\w{3} \w{3} \d{2} \d{4} \d{2}:\d{2}:\d{2})? (GMT[+-]\d{4}) \((.*?)\)/) ?? [];
|
|
38
|
+
const tzOffset = now.getTimezoneOffset() / 60;
|
|
39
|
+
return toBase64([time, tz, tzOffset, describe].join('|'));
|
|
40
|
+
}
|
package/utils/string.ts
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import { Base64 } from 'crypto-es/lib/enc-base64';
|
|
2
|
+
import { Utf8 } from 'crypto-es/lib/core';
|
|
3
|
+
|
|
1
4
|
/**
|
|
2
5
|
* 字符串脱敏,省略中间字符串
|
|
3
6
|
* @param str 字符串
|
|
@@ -26,3 +29,14 @@ export function randomString(length: number) {
|
|
|
26
29
|
const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
|
|
27
30
|
return Array.from({ length }, () => characters[Math.floor(Math.random() * characters.length)]).join('');
|
|
28
31
|
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* 转为base64字符串
|
|
35
|
+
* @param str 值
|
|
36
|
+
*/
|
|
37
|
+
export function toBase64(str: string | number) {
|
|
38
|
+
if (!['string', 'number'].includes(typeof str) || !str)
|
|
39
|
+
return '';
|
|
40
|
+
|
|
41
|
+
return Base64.stringify(Utf8.parse(String(str)));
|
|
42
|
+
}
|