mirror of
https://github.com/BTMuli/TeyvatGuide.git
synced 2025-12-12 09:18:14 +08:00
🤔 add(ds): 添加 ds 算法
This commit is contained in:
@@ -2,17 +2,21 @@
|
||||
* @file core utils TGUtils.ts
|
||||
* @description 应用用到的工具函数
|
||||
* @author BTMuli<bt-muli@outlook.com>
|
||||
* @since Alpha v0.1.2
|
||||
* @since Alpha v0.2.0
|
||||
*/
|
||||
|
||||
import { parseAnnoContent } from "./parseAnno";
|
||||
import { getAnnoCard } from "./getAnnoCard";
|
||||
import { getDS } from "./getDS";
|
||||
|
||||
const TGUtils = {
|
||||
Anno: {
|
||||
getCard: getAnnoCard,
|
||||
parseContent: parseAnnoContent,
|
||||
},
|
||||
User: {
|
||||
getDS,
|
||||
},
|
||||
};
|
||||
|
||||
export default TGUtils;
|
||||
|
||||
33
src/core/utils/getDS.ts
Normal file
33
src/core/utils/getDS.ts
Normal file
@@ -0,0 +1,33 @@
|
||||
/**
|
||||
* @description ds 算法
|
||||
* @since Alpha v0.2.0
|
||||
* @author BTMuli<bt-muli@outlook.com>
|
||||
* @since Alpha v0.2.0
|
||||
*/
|
||||
|
||||
// Node
|
||||
import { stringify } from "querystring";
|
||||
// Tauri.Genshin
|
||||
import { md5 } from "./tools";
|
||||
import TGConstant from "../constant/TGConstant";
|
||||
|
||||
/**
|
||||
* @description 获取 ds
|
||||
* @since Alpha v0.2.0
|
||||
* @version 2.34.1
|
||||
* @param {string} query 查询字符串
|
||||
* @param {string} body 请求体
|
||||
* @returns {string} ds
|
||||
*/
|
||||
export function getDS (query: string, body: string): string {
|
||||
const params = {
|
||||
salt: TGConstant.SALT.Other.X4,
|
||||
t: Math.floor(Date.now() / 1000).toString(),
|
||||
r: Math.floor(Math.random() * 900000 + 100000).toString(),
|
||||
b: body,
|
||||
q: query,
|
||||
};
|
||||
const md5Str = md5(stringify(params));
|
||||
const ds = `${params.t},${params.r},${md5Str}`;
|
||||
return ds;
|
||||
}
|
||||
@@ -2,9 +2,11 @@
|
||||
* @file core utils tools.ts
|
||||
* @description 应用用到的工具函数
|
||||
* @author BTMuli<bt-muli@outlook.com>
|
||||
* @since Alpha v0.1.2
|
||||
* @since Alpha v0.2.0
|
||||
*/
|
||||
|
||||
import crypto from "crypto";
|
||||
|
||||
/**
|
||||
* @description 转义正则表达式
|
||||
* @since Alpha v0.1.2
|
||||
@@ -23,3 +25,28 @@ export function decodeRegExp (data: string): string {
|
||||
res = res.replace(/&/g, "&");
|
||||
return res;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description 获取随机字符串
|
||||
* @since Alpha v0.2.0
|
||||
* @param {number} length 字符串长度
|
||||
* @returns {string} 随机字符串
|
||||
*/
|
||||
export function getRandomString (length: number): string {
|
||||
const str = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
|
||||
let res = "";
|
||||
for (let i = 0; i < length; i++) {
|
||||
res += str[Math.floor(Math.random() * str.length)];
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description md5 加密
|
||||
* @since Alpha v0.2.0
|
||||
* @param {string} data 要加密的内容
|
||||
* @returns {string} 加密后的内容
|
||||
*/
|
||||
export function md5 (data: string): string {
|
||||
return crypto.createHash("md5").update(data).digest("hex");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user