mirror of
https://github.com/BTMuli/TeyvatGuide.git
synced 2026-05-09 00:34:07 +08:00
🎨 代码格式化
This commit is contained in:
@@ -14,7 +14,7 @@ import { fs, path } from "@tauri-apps/api";
|
||||
* @param {Record<string, string>} cookie cookie
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
export async function backupCookieData (cookie: Record<string, string>): Promise<void> {
|
||||
export async function backupCookieData(cookie: Record<string, string>): Promise<void> {
|
||||
const savePath = `${await path.appLocalDataDir()}\\userData\\cookie.json`;
|
||||
await fs.writeTextFile(savePath, JSON.stringify(cookie, null, 2));
|
||||
}
|
||||
@@ -25,7 +25,7 @@ export async function backupCookieData (cookie: Record<string, string>): Promise
|
||||
* @param {TGApp.Sqlite.Abyss.SingleTable[]} abyssData 深渊数据
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
export async function backupAbyssData (abyssData: TGApp.Sqlite.Abyss.SingleTable[]): Promise<void> {
|
||||
export async function backupAbyssData(abyssData: TGApp.Sqlite.Abyss.SingleTable[]): Promise<void> {
|
||||
const savePath = `${await path.appLocalDataDir()}\\userData\\abyss.json`;
|
||||
await fs.writeTextFile(savePath, JSON.stringify(abyssData, null, 2));
|
||||
}
|
||||
|
||||
@@ -14,7 +14,9 @@ const defaultCover = "/source/UI/defaultCover.webp";
|
||||
* @param {TGApp.BBS.Announcement.ListData[]} data 公告数据
|
||||
* @returns {TGApp.App.Announcement.ListCard[]} 渲染用的卡片
|
||||
*/
|
||||
export function getAnnoCard (data: TGApp.BBS.Announcement.ListData): TGApp.App.Announcement.ListCard[] {
|
||||
export function getAnnoCard(
|
||||
data: TGApp.BBS.Announcement.ListData,
|
||||
): TGApp.App.Announcement.ListCard[] {
|
||||
const cards: TGApp.App.Announcement.ListCard[] = [];
|
||||
data.list.map((annoList: TGApp.BBS.Announcement.ListItem) => {
|
||||
return annoList.list.map((anno: TGApp.BBS.Announcement.AnnoSingle) => {
|
||||
|
||||
@@ -18,7 +18,7 @@ import { transCookie, transParams } from "./tools";
|
||||
* @param {string} saltType salt 类型
|
||||
* @returns {string} salt
|
||||
*/
|
||||
function getSalt (saltType: string) {
|
||||
function getSalt(saltType: string) {
|
||||
switch (saltType) {
|
||||
case "common":
|
||||
return TGConstant.Salt.Other.X4;
|
||||
@@ -36,7 +36,7 @@ function getSalt (saltType: string) {
|
||||
* @param {number} max 最大值
|
||||
* @returns {number} 随机数
|
||||
*/
|
||||
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 @@ function getRandomNumber (min: number, max: number): number {
|
||||
* @param {number} length 字符串长度
|
||||
* @returns {string} 随机字符串
|
||||
*/
|
||||
export function getRandomString (length: number): string {
|
||||
export function getRandomString(length: number): string {
|
||||
const str = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
|
||||
let res = "";
|
||||
for (let i = 0; i < length; i++) {
|
||||
@@ -65,7 +65,7 @@ export function getRandomString (length: number): string {
|
||||
* @param {boolean} isSign 是否为签名
|
||||
* @returns {string} ds
|
||||
*/
|
||||
function getDS (method: string, data: string, saltType: string, isSign: boolean = false): string {
|
||||
function getDS(method: string, data: string, saltType: string, isSign: boolean = false): string {
|
||||
const salt = getSalt(saltType);
|
||||
const time = Math.floor(Date.now() / 1000).toString();
|
||||
let random = getRandomNumber(100000, 200000).toString();
|
||||
@@ -86,7 +86,12 @@ function getDS (method: string, data: string, saltType: string, isSign: boolean
|
||||
* @param {string} saltType salt 类型
|
||||
* @returns {Record<string, string>} 请求头
|
||||
*/
|
||||
export function getRequestHeader (cookie: Record<string, string>, method: string, data: Record<string, string | number> | string, saltType: string): Record<string, string> {
|
||||
export function getRequestHeader(
|
||||
cookie: Record<string, string>,
|
||||
method: string,
|
||||
data: Record<string, string | number> | string,
|
||||
saltType: string,
|
||||
): Record<string, string> {
|
||||
let ds;
|
||||
if (typeof data === "string") {
|
||||
ds = getDS(method, data, saltType);
|
||||
@@ -113,7 +118,12 @@ export function getRequestHeader (cookie: Record<string, string>, method: string
|
||||
* @param {string} saltType salt 类型
|
||||
* @returns {Record<string, string>} 请求头
|
||||
*/
|
||||
export function getRequestSignHeader (cookie: Record<string, string>, method: string, data: Record<string, string | number>, saltType: string): Record<string, string> {
|
||||
export function getRequestSignHeader(
|
||||
cookie: Record<string, string>,
|
||||
method: string,
|
||||
data: Record<string, string | number>,
|
||||
saltType: string,
|
||||
): Record<string, string> {
|
||||
return {
|
||||
"User-Agent": TGConstant.BBS.USER_AGENT,
|
||||
"x-rpc-app_version": TGConstant.BBS.VERSION,
|
||||
|
||||
@@ -14,7 +14,7 @@ import { saveImgLocal } from "../../utils/TGShare";
|
||||
* @param {string} data 游戏内公告数据
|
||||
* @returns {Promise<string>} 解析后的数据
|
||||
*/
|
||||
export async function parseAnnoContent (data: string): Promise<string> {
|
||||
export async function parseAnnoContent(data: string): Promise<string> {
|
||||
const htmlBase = new DOMParser().parseFromString(data, "text/html");
|
||||
htmlBase.querySelectorAll("span").forEach((span) => {
|
||||
if (span.style.fontSize) {
|
||||
|
||||
@@ -15,9 +15,9 @@ import TGSqlite from "../../plugins/Sqlite";
|
||||
* @since Alpha v0.2.0
|
||||
* @returns {Promise<boolean>}
|
||||
*/
|
||||
export async function restoreCookieData (): Promise<boolean> {
|
||||
export async function restoreCookieData(): Promise<boolean> {
|
||||
const cookiePath = `${await path.appLocalDataDir()}\\userData\\cookie.json`;
|
||||
if (!await fs.exists(cookiePath)) return false;
|
||||
if (!(await fs.exists(cookiePath))) return false;
|
||||
const cookieData = await fs.readTextFile(cookiePath);
|
||||
await TGSqlite.saveAppData("cookie", JSON.stringify(JSON.parse(cookieData)));
|
||||
return true;
|
||||
@@ -28,9 +28,9 @@ export async function restoreCookieData (): Promise<boolean> {
|
||||
* @since Alpha v0.2.0
|
||||
* @returns {Promise<boolean>}
|
||||
*/
|
||||
export async function restoreAbyssData (): Promise<boolean> {
|
||||
export async function restoreAbyssData(): Promise<boolean> {
|
||||
const abyssPath = `${await path.appLocalDataDir()}\\userData\\abyss.json`;
|
||||
if (!await fs.exists(abyssPath)) return false;
|
||||
if (!(await fs.exists(abyssPath))) return false;
|
||||
const abyssData = await fs.readTextFile(abyssPath);
|
||||
await TGSqlite.restoreAbyss(JSON.parse(abyssData));
|
||||
return true;
|
||||
|
||||
@@ -14,14 +14,14 @@ import TGConstant from "../constant/TGConstant";
|
||||
* @param {string} data 内容
|
||||
* @returns {string} 转义后的内容
|
||||
*/
|
||||
export function decodeRegExp (data: string): string {
|
||||
export function decodeRegExp(data: string): string {
|
||||
let res = data;
|
||||
if (res.length === 0) return res;
|
||||
res = res.replace(/</g, "<");
|
||||
res = res.replace(/>/g, ">");
|
||||
res = res.replace(/ /g, " ");
|
||||
res = res.replace(/'/g, "'");
|
||||
res = res.replace(/"/g, "\"");
|
||||
res = res.replace(/"/g, '"');
|
||||
res = res.replace(/'/g, "'");
|
||||
res = res.replace(/&/g, "&");
|
||||
return res;
|
||||
@@ -33,7 +33,7 @@ export function decodeRegExp (data: string): string {
|
||||
* @param {Record<string, string>} cookie cookie
|
||||
* @returns {string} 转换后的 cookie
|
||||
*/
|
||||
export function transCookie (cookie: Record<string, string>) {
|
||||
export function transCookie(cookie: Record<string, string>) {
|
||||
let res = "";
|
||||
for (const key of Object.keys(cookie).sort()) {
|
||||
res += `${key}=${cookie[key]};`;
|
||||
@@ -47,7 +47,7 @@ export function transCookie (cookie: Record<string, string>) {
|
||||
* @param {Record<string, string|number>} obj object
|
||||
* @returns {string} query string
|
||||
*/
|
||||
export function transParams (obj: Record<string, string | number>): string {
|
||||
export function transParams(obj: Record<string, string | number>): string {
|
||||
let res = "";
|
||||
const keys = Object.keys(obj).sort();
|
||||
for (const key of keys) {
|
||||
@@ -62,7 +62,7 @@ export function transParams (obj: Record<string, string | number>): string {
|
||||
* @param {string} uid uid
|
||||
* @returns {string} server
|
||||
*/
|
||||
export function getServerByUid (uid: string): string {
|
||||
export function getServerByUid(uid: string): string {
|
||||
// 获取第一个字符
|
||||
const first = uid[0];
|
||||
// 1-4 为国服-天空岛
|
||||
|
||||
Reference in New Issue
Block a user