mirror of
https://github.com/BTMuli/TeyvatGuide.git
synced 2025-12-13 09:28:14 +08:00
🎨 完善页面处理
This commit is contained in:
@@ -1,27 +1,14 @@
|
||||
/**
|
||||
* @file src web request operVerification.ts
|
||||
* @description 验证码操作请求函数
|
||||
* @since Beta v0.3.3
|
||||
* @since Beta v0.3.4
|
||||
*/
|
||||
|
||||
import { http } from "@tauri-apps/api";
|
||||
import { v4 } from "uuid";
|
||||
|
||||
import { getDeviceID } from "../../utils/toolFunc";
|
||||
import TGUtils from "../utils/TGUtils";
|
||||
|
||||
/**
|
||||
* @description 获取 deviceId
|
||||
* @since Beta v0.3.3
|
||||
* @return {string} deviceId
|
||||
*/
|
||||
function getDeviceId(): string {
|
||||
const local = localStorage.getItem("deviceId");
|
||||
if (local) return local;
|
||||
const id = v4();
|
||||
localStorage.setItem("deviceId", id);
|
||||
return id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description 发起验证请求
|
||||
* @since Beta v0.3.3
|
||||
@@ -79,7 +66,7 @@ export async function submitVerification(
|
||||
"sec-fetch-dest": "empty",
|
||||
"sec-fetch-mode": "cors",
|
||||
"sec-fetch-site": "same-site",
|
||||
"x-rpc-device_id": getDeviceId(),
|
||||
"x-rpc-device_id": getDeviceID(),
|
||||
"x-rpc-page": "3.1.3_#/ys",
|
||||
};
|
||||
console.log(reqHeader);
|
||||
|
||||
@@ -5,9 +5,9 @@
|
||||
*/
|
||||
|
||||
import { getAnnoCard } from "./getAnnoCard";
|
||||
import { getRequestHeader, getRandomString, getRandomNumber } from "./getRequestHeader";
|
||||
import { getRequestHeader } from "./getRequestHeader";
|
||||
import { parseAnnoContent } from "./parseAnno";
|
||||
import { getServerByUid, transCookie, transParams } from "./tools";
|
||||
import { getServerByUid, transCookie } from "./tools";
|
||||
|
||||
const TGUtils = {
|
||||
Anno: {
|
||||
@@ -20,9 +20,6 @@ const TGUtils = {
|
||||
Tools: {
|
||||
getServerByUid,
|
||||
transCookie,
|
||||
getRandomString,
|
||||
getRandomNumber,
|
||||
transParams,
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/**
|
||||
* @file web utils getRequestHeader.ts
|
||||
* @description 获取请求头
|
||||
* @since Beta v0.3.3
|
||||
* @since Beta v0.3.4
|
||||
*/
|
||||
|
||||
import Md5 from "js-md5";
|
||||
@@ -36,7 +36,7 @@ function getSalt(saltType: string): string {
|
||||
* @param {number} max 最大值
|
||||
* @returns {number} 随机数
|
||||
*/
|
||||
export function getRandomNumber(min: number, max: number): number {
|
||||
function getRandomNumber(min: number, max: number): number {
|
||||
return Math.floor(Math.random() * (max - min + 1) + min);
|
||||
}
|
||||
|
||||
@@ -46,7 +46,7 @@ export function getRandomNumber(min: number, max: number): number {
|
||||
* @param {number} length 字符串长度
|
||||
* @returns {string} 随机字符串
|
||||
*/
|
||||
export function getRandomString(length: number): string {
|
||||
function getRandomString(length: number): string {
|
||||
const str = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
|
||||
let res = "";
|
||||
for (let i = 0; i < length; i++) {
|
||||
@@ -111,3 +111,49 @@ export function getRequestHeader(
|
||||
cookie: transCookie(cookie),
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* @description 获取 DS
|
||||
* @since Beta v0.3.4
|
||||
* @param {string} saltType salt 类型
|
||||
* @param {number} dsType ds 类型
|
||||
* @param {Record<string, string|number>|string} body
|
||||
* @param {Record<string, string|number>|string} query
|
||||
* @returns {string} DS
|
||||
*/
|
||||
export function getDS4JS(
|
||||
saltType: string,
|
||||
dsType: 1 | 2,
|
||||
body: undefined,
|
||||
query: undefined,
|
||||
): string;
|
||||
export function getDS4JS(
|
||||
saltType: string,
|
||||
dsType: 2,
|
||||
body: Record<string, string | number> | string,
|
||||
query: Record<string, string | number> | string,
|
||||
): string;
|
||||
export function getDS4JS(
|
||||
saltType: string,
|
||||
dsType: 1 | 2,
|
||||
body?: Record<string, string | number> | string,
|
||||
query?: Record<string, string | number> | string,
|
||||
): string {
|
||||
const salt = getSalt(saltType);
|
||||
const time = Math.floor(Date.now() / 1000).toString();
|
||||
let random = getRandomNumber(100000, 200000).toString();
|
||||
let hashStr = "";
|
||||
let md5Str = "";
|
||||
if (dsType === 1) {
|
||||
random = getRandomString(6);
|
||||
hashStr = `salt=${salt}&t=${time}&r=${random}`;
|
||||
} else {
|
||||
body = body ?? "";
|
||||
query = query ?? "";
|
||||
const bodyStr = typeof body === "string" ? body : transParams(body);
|
||||
const queryStr = typeof query === "string" ? query : transParams(query);
|
||||
hashStr = `salt=${salt}&t=${time}&r=${random}&b=${bodyStr}&q=${queryStr}`;
|
||||
}
|
||||
md5Str = Md5.md5.update(hashStr).hex();
|
||||
return `${time},${random},${md5Str}`;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user