♻️ 完善 fp 获取,添加强制更新入口

This commit is contained in:
目棃
2024-01-17 20:09:38 +08:00
parent 5e9773832a
commit efd0a49ea3
4 changed files with 122 additions and 38 deletions

View File

@@ -105,7 +105,12 @@
/>
</template>
</v-list-item>
<v-list-item prepend-icon="mdi-refresh" title="刷新设备信息" @click="confirmUpdateDevice" />
<v-list-item prepend-icon="mdi-refresh">
<v-list-item-title @click="confirmUpdateDevice()">刷新设备信息</v-list-item-title>
<template #append>
<v-icon @click="confirmUpdateDevice(true)">mdi-bug</v-icon>
</template>
</v-list-item>
<v-list-item prepend-icon="mdi-database-remove" title="清除缓存" @click="confirmDelCache" />
<v-list-item
v-show="showReset"
@@ -120,12 +125,20 @@
prepend-icon="mdi-folder-key"
title="本地数据库路径"
:subtitle="appStore.dataPath.dbDataPath"
/>
>
<template #append>
<v-icon @click="copyPath('db')">mdi-content-copy</v-icon>
</template>
</v-list-item>
<v-list-item
prepend-icon="mdi-folder-account"
title="本地用户数据路径"
:subtitle="appStore.dataPath.userDataDir"
/>
>
<template #append>
<v-icon @click="copyPath('user')">mdi-content-copy</v-icon>
</template>
</v-list-item>
</v-list>
<TAppBadge />
</div>
@@ -147,7 +160,7 @@ import { useAppStore } from "../../store/modules/app";
import { useHomeStore } from "../../store/modules/home";
import { useUserStore } from "../../store/modules/user";
import { getBuildTime } from "../../utils/TGBuild";
import { bytesToSize, getCacheDir, getDeviceInfo } from "../../utils/toolFunc";
import { bytesToSize, getCacheDir, getDeviceInfo, getRandomString } from "../../utils/toolFunc";
import { backupUiafData, restoreUiafData } from "../../utils/UIAF";
import { getDeviceFp } from "../../web/request/getDeviceFp";
import TGRequest from "../../web/request/TGRequest";
@@ -448,7 +461,33 @@ async function confirmUpdate(title?: string): Promise<void> {
}
// 更新设备信息
async function confirmUpdateDevice(): Promise<void> {
async function confirmUpdateDevice(force?: boolean): Promise<void> {
if (force !== undefined && force) {
const resF = await showConfirm({
title: "确认强制更新设备信息吗?",
text: `DeviceFp:${appStore.deviceInfo.device_fp}`,
});
if (!resF) {
showSnackbar({
text: "已取消强制更新设备信息",
color: "cancel",
});
return;
}
appStore.deviceInfo = await TGRequest.Device.getFp();
if (appStore.deviceInfo.device_fp === "0000000000000") {
appStore.deviceInfo.device_fp = getRandomString(13, "hex");
showSnackbar({
text: `设备信息获取失败!已使用随机值 ${appStore.deviceInfo.device_fp} 代替`,
color: "warn",
});
} else {
showSnackbar({
text: "设备信息已更新! DeviceFp: " + appStore.deviceInfo.device_fp,
});
}
return;
}
const localFp = getDeviceInfo("device_fp");
if (localFp !== "0000000000000") {
const res = await showConfirm({
@@ -463,7 +502,16 @@ async function confirmUpdateDevice(): Promise<void> {
return;
}
}
console.log(appStore.deviceInfo);
appStore.deviceInfo = await TGRequest.Device.getFp(appStore.deviceInfo);
console.log(appStore.deviceInfo);
if (appStore.deviceInfo.device_fp === "0000000000000") {
appStore.deviceInfo.device_fp = getRandomString(13, "hex");
showSnackbar({
text: "设备信息获取失败!已使用随机值代替",
});
return;
}
showSnackbar({
text: "设备信息已更新! DeviceFp: " + appStore.deviceInfo.device_fp,
});
@@ -613,6 +661,15 @@ function submitHome(): void {
homeStore.setShowValue(show);
showSnackbar({ text: "已修改!" });
}
function copyPath(type: "db" | "user"): void {
const path = type === "db" ? appStore.dataPath.dbDataPath : appStore.dataPath.userDataDir;
navigator.clipboard.writeText(path);
const content = type === "db" ? "数据库" : "用户数据";
showSnackbar({
text: `${content}路径已复制!`,
});
}
</script>
<style lang="css" scoped>

View File

@@ -1,22 +1,23 @@
/**
* @file types/App/Device.d.ts
* @description App 设备信息类型定义文件
* @since Beta v0.3.6
* @since Beta v0.4.1
*/
/**
* @description App 设备信息类型 namespace
* @since Beta v0.3.6
* @since Beta v0.4.1
* @namespace TGApp.App.Device
* @memberof TGApp.App
*/
declare namespace TGApp.App.Device {
/**
* @description 设备信息
* @since Beta v0.3.6
* @since Beta v0.4.1
* @interface DeviceInfo
* @property {string} device_id - 设备 ID
* @property {string} model - 设备型号
* @property {string} product - 产品
* @property {string} device_name - 设备名称
* @property {string} seed_id - 种子 ID
* @property {string} seed_time - 种子时间
* @property {string} device_fp - 设备指纹
@@ -24,7 +25,8 @@ declare namespace TGApp.App.Device {
*/
interface DeviceInfo {
device_id: string;
model: string;
product: string;
device_name: string;
seed_id: string;
seed_time: string;
device_fp: string;

View File

@@ -1,7 +1,7 @@
/**
* @file utils/toolFunc.ts
* @description 一些工具函数
* @since Beta v0.3.9
* @since Beta v0.4.1
*/
import { os, path } from "@tauri-apps/api";
@@ -60,13 +60,14 @@ export function getNowStr(): string {
/**
* @description 获取设备信息(初始化时)
* @since Beta v0.3.6
* @since Beta v0.4.1
* @returns {TGApp.App.Device.DeviceInfo} 设备信息
*/
export function getInitDeviceInfo(): TGApp.App.Device.DeviceInfo {
return {
device_id: v4(),
model: getRandomString(6),
product: getRandomString(6, "upperNumber"),
device_name: getRandomString(12, "upperNumber"),
seed_id: v4(),
seed_time: Date.now().toString(),
device_fp: "0000000000000",
@@ -125,7 +126,7 @@ export async function getCacheDir(): Promise<string[] | false> {
/**
* @description 获取随机字符串
* @since Beta v0.3.6
* @since Beta v0.4.1
* @param {number} length 字符串长度
* @param {string} type
* @returns {string} 随机字符串
@@ -147,6 +148,9 @@ export function getRandomString(length: number, type: string = "all"): string {
case "upper":
str = char.toUpperCase();
break;
case "upperNumber":
str = char.toUpperCase() + num;
break;
case "letter":
str = char + char.toUpperCase();
break;

View File

@@ -1,7 +1,7 @@
/**
* @file src/web/request/getDeviceFp.ts
* @description 获取设备指纹
* @since Beta v0.3.6
* @since Beta v0.4.1
*/
import { http } from "@tauri-apps/api";
@@ -11,7 +11,7 @@ import TGConstant from "../constant/TGConstant";
/**
* @description 获取设备指纹
* @since Beta v0.3.6
* @since Beta v0.4.1
* @param {TGApp.App.Device.DeviceInfo} Info - 设备信息
* @returns {Promise<string>} 设备指纹
*/
@@ -20,38 +20,59 @@ export async function getDeviceFp(
): Promise<TGApp.App.Device.DeviceInfo> {
const info = Info ?? getInitDeviceInfo();
const deviceFPHeader = {
cpuType: "arm64-v8a",
proxyStatus: 0,
isRoot: 0,
romCapacity: "512",
productName: info.model,
romRemain: "256",
manufacturer: "Xiaomi",
appMemory: "512",
deviceName: info.device_name,
productName: info.product,
romRemain: "512",
hostname: "dg02-pool03-kvm87",
screenSize: "1080x1920",
osVersion: "13",
screenSize: "1440x2905",
isTablet: 0,
aaid: "",
vendor: "中国移动",
accelerometer: "true",
buildTags: "release-keys",
model: info.model,
model: info.device_name,
brand: "Xiaomi",
oaid: "",
hardware: "qcom",
deviceType: "OP5913L1",
devId: "unknown",
serialNumber: "unknown",
buildTime: "1588876800000", // 2020-05-08
buildUser: "root",
ramCapacity: "2048",
magnetometer: "true",
display: `OP5913L1-user ${info.model} 10 QKQ1.190825.002 V12.0.1.0.QFJCNXM release-keys`,
ramRemain: "1024",
deviceInfo: "unknown",
gyroscope: "true",
sdCardCapacity: 512215,
buildTime: "1693626947000",
buildUser: "android-build",
simState: "5",
ramRemain: "239814",
appUpdateTimeDiff: 1702604034882,
deviceInfo: `XiaoMi ${info.device_name} OP5913L1:13 SKQ1.221119.001 T.118e6c7-5aa23-73911:user release-keys`,
vaid: "",
buildType: "user",
sdkVersion: "29",
board: "sdm660",
sdkVersion: "34",
ui_mode: "UI_MODE_TYPE_NORMAL",
isMockLocation: 0,
cpuType: "arm64-v8a",
isAirMode: 0,
ringMode: 2,
chargeStatus: 1,
manufacturer: "XiaoMi",
emulatorStatus: 0,
appMemory: "512",
osVersion: "14",
vendor: "unknown",
accelerometer: "1.4883357x9.80665x-0.1963501", // 这边与 hutao 数据不一致
sdRemain: 239600,
buildTags: "release-keys",
packageName: "com.mihoyo.hyperion",
networkType: "WiFi",
oaid: "",
debugStatus: 1,
ramCapacity: "469679",
magnetometer: "20.081251x-27.457501x2.1937501",
display: `${info.product}_13.1.0.181(CN01)`,
appInstallTimeDiff: 1688455751496,
packageVersion: "2.20.1",
gyroscope: "0.030226856x-0.014647375x-0.0013732915", // 这边与 hutao 数据不一致
batteryStatus: 100,
hasKeyboard: 0,
board: "taro",
};
const url = "https://public-data-api.mihoyo.com/device-fp/api/getFp";
const data = {