From fc3d417961a339db9b1e7014378c188928fe040e Mon Sep 17 00:00:00 2001 From: BTMuli Date: Thu, 16 Nov 2023 14:36:56 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=8E=A8=20=E5=BE=AE=E8=B0=83=E9=80=BB?= =?UTF-8?q?=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/pages/common/Config.vue | 5 ++--- src/utils/TGClient.ts | 10 +++++++--- src/web/request/getDeviceFp.ts | 11 +++++++---- 3 files changed, 16 insertions(+), 10 deletions(-) diff --git a/src/pages/common/Config.vue b/src/pages/common/Config.vue index d6d5f934..9540c60b 100644 --- a/src/pages/common/Config.vue +++ b/src/pages/common/Config.vue @@ -460,10 +460,9 @@ async function confirmUpdateDevice(): Promise { return; } } - await TGRequest.Device.getFp(); - appStore.deviceInfo.device_fp = getDeviceInfo("device_fp"); + appStore.deviceInfo = await TGRequest.Device.getFp(appStore.deviceInfo); showSnackbar({ - text: "设备信息已更新! DeviceFp: " + getDeviceInfo("device_fp"), + text: "设备信息已更新! DeviceFp: " + appStore.deviceInfo.device_fp, }); } diff --git a/src/utils/TGClient.ts b/src/utils/TGClient.ts index c036fd13..ba7d797b 100644 --- a/src/utils/TGClient.ts +++ b/src/utils/TGClient.ts @@ -9,6 +9,7 @@ import type { Event } from "@tauri-apps/api/event"; import { WebviewWindow } from "@tauri-apps/api/window"; import { getDeviceInfo } from "./toolFunc"; +import { useAppStore } from "../store/modules/app"; import { useUserStore } from "../store/modules/user"; import TGConstant from "../web/constant/TGConstant"; import TGRequest from "../web/request/TGRequest"; @@ -328,13 +329,16 @@ class TGClient { */ async getHTTPRequestHeaders(callback: string): Promise { const localFp = getDeviceInfo("device_fp"); - if (localFp === "0000000000000") await TGRequest.Device.getFp(); + let deviceInfo = useAppStore().deviceInfo; + if (localFp === "0000000000000") { + deviceInfo = await TGRequest.Device.getFp(deviceInfo); + } const data = { "user-agent": TGConstant.BBS.UA_MOBILE, "x-rpc-client_type": "5", - "x-rpc-device_id": getDeviceInfo("device_id"), + "x-rpc-device_id": deviceInfo.device_id, "x-rpc-app_version": TGConstant.BBS.VERSION, - "x-rpc-device_fp": getDeviceInfo("device_fp"), + "x-rpc-device_fp": deviceInfo.device_fp, }; await this.callback(callback, data); } diff --git a/src/web/request/getDeviceFp.ts b/src/web/request/getDeviceFp.ts index 91d23fc8..aeb43342 100644 --- a/src/web/request/getDeviceFp.ts +++ b/src/web/request/getDeviceFp.ts @@ -12,10 +12,13 @@ import TGConstant from "../constant/TGConstant"; /** * @description 获取设备指纹 * @since Beta v0.3.6 - * @returns {Promise} 设备指纹 + * @param {TGApp.App.Device.DeviceInfo} Info - 设备信息 + * @returns {Promise} 设备指纹 */ -export async function getDeviceFp(): Promise { - const info = getInitDeviceInfo(); +export async function getDeviceFp( + Info?: TGApp.App.Device.DeviceInfo, +): Promise { + const info = Info ?? getInitDeviceInfo(); const deviceFPHeader = { cpuType: "arm64-v8a", romCapacity: "512", @@ -78,5 +81,5 @@ export async function getDeviceFp(): Promise { if (res.data.data.code === 200) return res.data.data.device_fp; return "0000000000000"; }); - localStorage.setItem("deviceInfo", JSON.stringify({ deviceInfo: info })); + return info; }