File tree Expand file tree Collapse file tree 5 files changed +51
-25
lines changed
Expand file tree Collapse file tree 5 files changed +51
-25
lines changed Original file line number Diff line number Diff line change 226226<script >
227227import {ref , onMounted , computed } from " vue" ;
228228import { useRouter } from ' vue-router'
229- import { getVisitorId } from ' @/utils/fingerprint '
229+ import { getVisitorId } from ' @/utils/visitorId '
230230import packageJson from " ../../../package.json" ;
231231
232232export default {
Original file line number Diff line number Diff line change @@ -21,7 +21,7 @@ import {createApp} from 'vue'
2121//import '@examaware-cs/player/dist/player.css'
2222
2323import messageService from './utils/message' ;
24- import { getVisitorId } from './utils/fingerprint ' ;
24+ import { getVisitorId } from './utils/visitorId ' ;
2525
2626const app = createApp ( App )
2727
Original file line number Diff line number Diff line change 2222
2323<script setup>
2424import { ref , onMounted } from ' vue'
25- import { getVisitorId , getFingerprintData } from ' @/utils/fingerprint '
25+ import { getVisitorId , getFingerprintData } from ' @/utils/visitorId '
2626
2727const visitorId = ref (' ' )
2828const fingerprintData = ref ({})
Load Diff This file was deleted.
Original file line number Diff line number Diff line change 1+ let fpPromise
2+
3+ const buildFallbackAgent = ( error ) => ( {
4+ get : async ( ) => ( {
5+ visitorId : 'unknown' ,
6+ error : error ?. message || String ( error || '' ) ,
7+ fallback : true ,
8+ } ) ,
9+ } )
10+
11+ const loadFingerprintLib = async ( ) => {
12+ try {
13+ const mod = await import ( '@fingerprintjs/fingerprintjs' )
14+ return mod ?. default || mod
15+ } catch ( err ) {
16+ console . warn ( 'Fingerprint library blocked or failed to load; using fallback agent.' , err )
17+ return null
18+ }
19+ }
20+
21+ export const loadFingerprint = ( ) => {
22+ if ( ! fpPromise ) {
23+ fpPromise = ( async ( ) => {
24+ const FingerprintJS = await loadFingerprintLib ( )
25+ if ( ! FingerprintJS ) return buildFallbackAgent ( new Error ( 'fingerprint module unavailable' ) )
26+
27+ try {
28+ return await FingerprintJS . load ( )
29+ } catch ( err ) {
30+ console . warn ( 'FingerprintJS.load failed, using fallback agent.' , err )
31+ return buildFallbackAgent ( err )
32+ }
33+ } ) ( )
34+ }
35+ return fpPromise
36+ }
37+
38+ export const getVisitorId = async ( ) => {
39+ const fp = await loadFingerprint ( )
40+ const result = await fp . get ( )
41+ return result ?. visitorId || 'unknown'
42+ }
43+
44+ export const getFingerprintData = async ( ) => {
45+ const fp = await loadFingerprint ( )
46+ const result = await fp . get ( )
47+ return result
48+ }
You can’t perform that action at this time.
0 commit comments