♻️ 把已经测试过的请求给加上去了

This commit is contained in:
BTMuli
2023-05-19 14:48:43 +08:00
parent 43505b7d2f
commit 97ff6e1350
13 changed files with 468 additions and 261 deletions

View File

@@ -5,10 +5,10 @@
* @since Alpha v0.2.0
*/
import { parseAnnoContent } from "./parseAnno";
import { getAnnoCard } from "./getAnnoCard";
import { getRequestHeader } from "./getRequestHeader";
import { cookieToString, getServerByUid } from "./tools";
import { parseAnnoContent } from "./parseAnno";
import { transCookie, getServerByUid } from "./tools";
const TGUtils = {
Anno: {
@@ -19,7 +19,7 @@ const TGUtils = {
getHeader: getRequestHeader,
},
Tools: {
cookieToString,
transCookie,
getServerByUid,
},
};

View File

@@ -1,53 +0,0 @@
/**
* @file web utils getDS.ts
* @description ds 算法
* @author BTMuli<bt-muli@outlook.com>
* @since Alpha v0.2.0
*/
// Node
import md5 from "js-md5";
import qs from "qs";
// Tauri.Genshin
import { random } from "./tools";
import TGConstant from "../constant/TGConstant";
/**
* @description 获取 salt
* @since Alpha v0.2.0
* @version 2.49.1
* @param {string} saltType salt 类型
* @returns {string} salt
*/
function getSalt (saltType: string) {
switch (saltType) {
case "common":
return TGConstant.Salt.Other.X4;
case "prod":
return TGConstant.Salt.Other.prod;
default:
return TGConstant.Salt.Other.X4;
}
}
/**
* @description 获取 ds
* @since Alpha v0.2.0
* @version 2.49.1
* @param {string} saltType salt 类型
* @param {string} method 请求方法
* @param {string} data 请求数据
* @returns {string} ds
*/
export function getDS (method: string, data: string, saltType: string): string {
const salt = getSalt(saltType);
const params = {
salt,
t: Math.floor(Date.now() / 1000).toString(),
r: random(100000, 200000).toString(),
b: method === "GET" ? "" : data,
q: method === "GET" ? data : "",
};
const md5Str = md5.update(qs.stringify(params)).hex();
return `${params.t},${params.r},${md5Str}`;
}

View File

@@ -5,8 +5,62 @@
* @since Alpha v0.2.0
*/
// Node
import md5 from "js-md5";
import qs from "qs";
// Tauri.Genshin
import TGConstant from "../constant/TGConstant";
import { getDS } from "./getDS";
/**
* @description 获取 salt
* @since Alpha v0.2.0
* @version 2.49.1
* @param {string} saltType salt 类型
* @returns {string} salt
*/
function getSalt (saltType: string) {
switch (saltType) {
case "common":
return TGConstant.Salt.Other.X4;
case "prod":
return TGConstant.Salt.Other.prod;
default:
return TGConstant.Salt.Other.X4;
}
}
/**
* @description 获取随机数
* @since Alpha v0.2.0
* @param {number} min 最小值
* @param {number} max 最大值
* @returns {number} 随机数
*/
function random (min: number, max: number): number {
return Math.floor(Math.random() * (max - min + 1) + min);
}
/**
* @description 获取 ds
* @since Alpha v0.2.0
* @version 2.49.1
* @param {string} saltType salt 类型
* @param {string} method 请求方法
* @param {string} data 请求数据
* @returns {string} ds
*/
function getDS (method: string, data: string, saltType: string): string {
const salt = getSalt(saltType);
const params = {
salt,
t: Math.floor(Date.now() / 1000).toString(),
r: random(100000, 200000).toString(),
b: method === "GET" ? "" : data,
q: method === "GET" ? data : "",
};
const md5Str = md5.update(qs.stringify(params)).hex();
return `${params.t},${params.r},${md5Str}`;
}
/**
* @description 获取请求头

View File

@@ -5,8 +5,6 @@
* @since Alpha v0.2.0
*/
// Node
import { stringify } from "qs";
// TauriGenshin
import TGConstant from "../constant/TGConstant";
@@ -44,17 +42,6 @@ export function getRandomString (length: number): string {
return res;
}
/**
* @description 获取随机数
* @since Alpha v0.2.0
* @param {number} min 最小值
* @param {number} max 最大值
* @returns {number} 随机数
*/
export function random (min: number, max: number): number {
return Math.floor(Math.random() * (max - min + 1) + min);
}
/**
* @description object 转换为 query string
* @since Alpha v0.2.0