Browse Source

change get clientId

master
godo 5 months ago
parent
commit
ba97bc2c79
  1. 2
      frontend/src/stores/notify.ts
  2. 61
      frontend/src/system/config.ts
  3. 97
      frontend/src/util/clientid.ts

2
frontend/src/stores/notify.ts

@ -19,7 +19,7 @@ export const useNotifyStore = defineStore('notifyStore', () => {
if (config.userType == 'person') {
return
}
const complition = await fetchGet(config.userInfo.url + '/news/list?page=' + page.value.current + '&limit=' + page.value.size)
const complition = await fetchGet(config.userInfo.url + '/user/news/list?page=' + page.value.current + '&limit=' + page.value.size)
if (!complition.ok) {
return;
}

61
frontend/src/system/config.ts

@ -1,6 +1,7 @@
import { generateRandomString } from "../util/common.ts";
export const configStoreType = localStorage.getItem('GodoOS-storeType') || 'local';
import { parseAiConfig } from "./aiconfig.ts";
import { getClientId } from "../util/clientid.ts";
/**
*
*
@ -329,36 +330,36 @@ export const clearSystemConfig = () => {
}
//localStorage.removeItem('GodoOS-config');
};
function bin2hex(s: string) {
s = encodeURI(s);//只会有0-127的ascii不转化
let m: any = s.match(/%[\dA-F]{2}/g), a: any = s.split(/%[\dA-F]{2}/), i, j, n, t;
m.push("")
for (i in a) {
if (a[i] === "") { a[i] = m[i]; continue }
n = ""
for (j in a[i]) {
t = a[i][j].charCodeAt().toString(16).toUpperCase()
if (t.length === 1) t = "0" + t
n += "%" + t
}
a[i] = n + m[i]
}
return a.join("").split("%").join("")
}
export const getClientId = () => {
let uuid: any = localStorage.getItem("ClientID");
if (!uuid) {
let canvas = document.createElement('canvas');
let ctx: any = canvas.getContext('2d');
ctx.fillStyle = '#FF0000';
ctx.fillRect(0, 0, 8, 10);
let b64 = canvas.toDataURL().replace("data:image/png;base64,", "");
let bin = window.atob(b64);
uuid = bin2hex(bin.slice(-16, -12));
localStorage.setItem("ClientID", uuid);
}
return uuid;
}
// function bin2hex(s: string) {
// s = encodeURI(s);//只会有0-127的ascii不转化
// let m: any = s.match(/%[\dA-F]{2}/g), a: any = s.split(/%[\dA-F]{2}/), i, j, n, t;
// m.push("")
// for (i in a) {
// if (a[i] === "") { a[i] = m[i]; continue }
// n = ""
// for (j in a[i]) {
// t = a[i][j].charCodeAt().toString(16).toUpperCase()
// if (t.length === 1) t = "0" + t
// n += "%" + t
// }
// a[i] = n + m[i]
// }
// return a.join("").split("%").join("")
// }
// export const getClientId = () => {
// let uuid: any = localStorage.getItem("ClientID");
// if (!uuid) {
// let canvas = document.createElement('canvas');
// let ctx: any = canvas.getContext('2d');
// ctx.fillStyle = '#FF0000';
// ctx.fillRect(0, 0, 8, 10);
// let b64 = canvas.toDataURL().replace("data:image/png;base64,", "");
// let bin = window.atob(b64);
// uuid = bin2hex(bin.slice(-16, -12));
// localStorage.setItem("ClientID", uuid);
// }
// return uuid;
// }
// export const getClientId = () => {
// let uuid: any = localStorage.getItem("godoosClientId");
// if (!uuid) {

97
frontend/src/util/clientid.ts

@ -0,0 +1,97 @@
function getOSInfo() {
const userAgent = navigator.userAgent;
if (/windows phone/i.test(userAgent)) {
return 'Windows Phone';
}
if (/win/i.test(userAgent)) {
return 'Windows';
}
if (/mac/i.test(userAgent)) {
return 'Mac';
}
if (/x11/i.test(userAgent)) {
return 'UNIX';
}
if (/android/i.test(userAgent)) {
return 'Android';
}
if (/iphone|ipad|ipod/i.test(userAgent)) {
return 'iOS';
}
return 'Unknown';
}
function bin2hex(s:any) {
s = encodeURI(s);//只会有0-127的ascii不转化
let m = s.match(/%[\dA-F]{2}/g), a = s.split(/%[\dA-F]{2}/), i, j, n, t;
m.push("")
for (i in a) {
if (a[i] === "") { a[i] = m[i]; continue }
n = ""
for (j in a[i]) {
t = a[i][j].charCodeAt().toString(16).toUpperCase()
if (t.length === 1) t = "0" + t
n += "%" + t
}
a[i] = n + m[i]
}
return a.join("").split("%").join("")
}
function getBrowserFingerprint() {
const canvas = document.createElement('canvas');
const ctx:any = canvas.getContext('2d');
const txt = window.location.hostname;
ctx.textBaseline = 'top';
ctx.font = '14px \'Arial\'';
ctx.textBaseline = 'alphabetic';
ctx.fillStyle = '#f60';
ctx.fillRect(125, 1, 62, 20);
ctx.fillStyle = '#069';
ctx.fillText(txt, 2, 15);
ctx.fillStyle = 'rgba(102, 204, 0, 0.7)';
ctx.fillText(txt, 4, 17);
const b64 = canvas.toDataURL().replace("data:image/png;base64,", "");
const bin = window.atob(b64);
const hash = bin2hex(bin.slice(-16, -12));
const fingerprint = [
navigator.platform,
navigator.product,
navigator.productSub,
navigator.appName,
navigator.appVersion,
navigator.javaEnabled(),
navigator.userAgent,
screen.width,
screen.height,
new Date().getTimezoneOffset(),
hash,
screen.colorDepth,
navigator.language,
navigator.hardwareConcurrency,
getOSInfo(),
navigator.maxTouchPoints,
navigator.doNotTrack,
navigator.cookieEnabled
].join('|');
return fingerprint;
}
function djb2Hash(str:string) {
let hash = 5381;
for (let i = 0; i < str.length; i++) {
const char = str.charCodeAt(i);
hash = ((hash << 5) + hash) + char; /* hash * 33 + c */
}
return hash.toString(36); // Convert to base 36 for shorter string
}
export const getClientId = () => {
let uuid = localStorage.getItem("ClientID");
if (!uuid) {
const fingerprint = getBrowserFingerprint();
uuid = djb2Hash(fingerprint).slice(0, 36);
localStorage.setItem("ClientID", uuid);
}
return uuid;
}
Loading…
Cancel
Save