@bbki.ng/site 5.5.0 → 5.5.2
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/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,21 @@
|
|
|
1
1
|
# @bbki.ng/site
|
|
2
2
|
|
|
3
|
+
## 5.5.2
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 039575f: fix hash str
|
|
8
|
+
- Updated dependencies [039575f]
|
|
9
|
+
- @bbki.ng/ui@0.2.2
|
|
10
|
+
|
|
11
|
+
## 5.5.1
|
|
12
|
+
|
|
13
|
+
### Patch Changes
|
|
14
|
+
|
|
15
|
+
- 3c2834a: track device activity
|
|
16
|
+
- Updated dependencies [3c2834a]
|
|
17
|
+
- @bbki.ng/ui@0.2.1
|
|
18
|
+
|
|
3
19
|
## 5.5.0
|
|
4
20
|
|
|
5
21
|
### Minor Changes
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bbki.ng/site",
|
|
3
|
-
"version": "5.5.
|
|
3
|
+
"version": "5.5.2",
|
|
4
4
|
"description": "code behind bbki.ng",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
"react-dom": "^18.0.0",
|
|
15
15
|
"react-router-dom": "6",
|
|
16
16
|
"swr": "^2.2.5",
|
|
17
|
-
"@bbki.ng/ui": "0.2.
|
|
17
|
+
"@bbki.ng/ui": "0.2.2"
|
|
18
18
|
},
|
|
19
19
|
"devDependencies": {
|
|
20
20
|
"@eslint/compat": "^1.0.0",
|
|
@@ -2,13 +2,13 @@ import { useRef } from 'react';
|
|
|
2
2
|
import { useFingerprint } from '@/hooks/use_fingerprint';
|
|
3
3
|
|
|
4
4
|
export const useFingerprintUniforms = () => {
|
|
5
|
-
const {
|
|
5
|
+
const { deviceId, loading } = useFingerprint();
|
|
6
6
|
|
|
7
7
|
const charsRef = useRef<number[] | null>(null);
|
|
8
8
|
const appliedRef = useRef(false);
|
|
9
9
|
|
|
10
|
-
if (!loading &&
|
|
11
|
-
const hash =
|
|
10
|
+
if (!loading && deviceId && !charsRef.current) {
|
|
11
|
+
const hash = deviceId;
|
|
12
12
|
const chars = [...hash].map(c => parseInt(c, 16) || 0);
|
|
13
13
|
while (chars.length < 16) chars.push(0);
|
|
14
14
|
charsRef.current = chars;
|
|
@@ -42,13 +42,6 @@ export const useFingerprintUniforms = () => {
|
|
|
42
42
|
inst.uniforms.uFpChars4.value[2] = chars[14];
|
|
43
43
|
inst.uniforms.uFpChars4.value[3] = chars[15];
|
|
44
44
|
|
|
45
|
-
// console.log('[Fingerprint] Uniforms set:', {
|
|
46
|
-
// uFpChars1: inst.uniforms.uFpChars1.value,
|
|
47
|
-
// uFpChars2: inst.uniforms.uFpChars2.value,
|
|
48
|
-
// uFpChars3: inst.uniforms.uFpChars3.value,
|
|
49
|
-
// uFpChars4: inst.uniforms.uFpChars4.value,
|
|
50
|
-
// });
|
|
51
|
-
|
|
52
45
|
appliedRef.current = true;
|
|
53
46
|
};
|
|
54
47
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { useEffect, useState, useCallback } from 'react';
|
|
2
|
-
import {
|
|
2
|
+
import { getStableDeviceId, FingerprintData } from '@/utils/fingerprints';
|
|
3
3
|
|
|
4
4
|
interface UseFingerprintReturn {
|
|
5
5
|
deviceId: string | null;
|
|
@@ -330,12 +330,11 @@ export async function getStableDeviceId(): Promise<{ id: string; fp: Fingerprint
|
|
|
330
330
|
|
|
331
331
|
// 生成新ID
|
|
332
332
|
const fp = await getFingerprint();
|
|
333
|
-
const id = `dev_${fp.hash.slice(0, 16)}_${Date.now().toString(36)}`;
|
|
334
333
|
|
|
335
334
|
localStorage.setItem(
|
|
336
335
|
STORAGE_KEY,
|
|
337
336
|
JSON.stringify({
|
|
338
|
-
id,
|
|
337
|
+
id: fp.hash.slice(0, 16),
|
|
339
338
|
ts: Date.now(),
|
|
340
339
|
ua: navigator.userAgent.slice(0, 50),
|
|
341
340
|
})
|
package/src/blog/utils/index.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { API_ENDPOINT } from '@/constants/routes';
|
|
2
2
|
import { FontType } from '@/types/font';
|
|
3
|
+
import { getFingerprint, getStableDeviceId } from './fingerprints';
|
|
3
4
|
|
|
4
5
|
type Fetcher = (resource: string, init?: any) => Promise<any>;
|
|
5
6
|
|
|
@@ -7,10 +8,13 @@ export const floatNumberToPercentageString = (num: number): string => {
|
|
|
7
8
|
return `${num * 100}%`;
|
|
8
9
|
};
|
|
9
10
|
|
|
10
|
-
export const baseFetcher = (resource: string, init: RequestInit = {}) =>
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
export const baseFetcher = async (resource: string, init: RequestInit = {}) => {
|
|
12
|
+
const headers = new Headers(init.headers || {});
|
|
13
|
+
const fp = await getFingerprint();
|
|
14
|
+
headers.set('X-Device-Fingerprint', fp.hash);
|
|
15
|
+
return fetch(resource, {
|
|
13
16
|
...init,
|
|
17
|
+
headers,
|
|
14
18
|
mode: 'cors',
|
|
15
19
|
}).then(res => {
|
|
16
20
|
if (!res.ok) {
|
|
@@ -19,6 +23,7 @@ export const baseFetcher = (resource: string, init: RequestInit = {}) =>
|
|
|
19
23
|
|
|
20
24
|
return res.json();
|
|
21
25
|
});
|
|
26
|
+
};
|
|
22
27
|
|
|
23
28
|
export const withBBApi =
|
|
24
29
|
(fetcher: Fetcher) =>
|