mirror of
https://github.com/BTMuli/TeyvatGuide.git
synced 2025-12-12 09:18:14 +08:00
👌 fix(ck): 输入 ck 时更新 token 顺带验证
This commit is contained in:
@@ -172,6 +172,7 @@ import { useAchievementsStore } from "../store/modules/achievements";
|
||||
// utils
|
||||
import { backupUiafData, restoreUiafData } from "../utils/UIAF";
|
||||
import TGSqlite from "../utils/TGSqlite";
|
||||
import TGRequest from "../core/request/TGRequest";
|
||||
|
||||
// Store
|
||||
const appStore = useAppStore();
|
||||
@@ -317,7 +318,6 @@ async function doConfirm (oper: string) {
|
||||
break;
|
||||
case "getCookie":
|
||||
await tauri.invoke("mys_login");
|
||||
tryConfirm("readCookie");
|
||||
break;
|
||||
case "readCookie":
|
||||
await readCookie();
|
||||
@@ -434,6 +434,8 @@ async function inputCookie () {
|
||||
snackbar.value = true;
|
||||
return;
|
||||
}
|
||||
loadingTitle.value = "正在保存 Cookie...";
|
||||
loading.value = true;
|
||||
// 格式为 key=value;key=value,去除多余空格
|
||||
const cookieArr = cookie.replace(/\s+/g, "").split(";");
|
||||
const cookieObj: any = {};
|
||||
@@ -443,9 +445,24 @@ async function inputCookie () {
|
||||
});
|
||||
// 保存到数据库
|
||||
await TGSqlite.inputCookie(JSON.stringify(cookieObj));
|
||||
snackbarText.value = "Cookie 已经保存到数据库!";
|
||||
snackbarColor.value = "success";
|
||||
snackbar.value = true;
|
||||
loadingTitle.value = "正在获取 tokens...";
|
||||
const tokenRes = await TGRequest.User.byLoginTicket.getLTokens(cookieObj);
|
||||
if (Array.isArray(tokenRes)) {
|
||||
loadingTitle.value = "正在保存 tokens...";
|
||||
const lToken = tokenRes.find((item) => item.name === "ltoken");
|
||||
const sToken = tokenRes.find((item) => item.name === "stoken");
|
||||
if (lToken) await TGSqlite.saveAppData("ltoken", lToken.token);
|
||||
if (sToken) await TGSqlite.saveAppData("stoken", sToken.token);
|
||||
loading.value = false;
|
||||
snackbarText.value = "Cookie 已保存!";
|
||||
snackbarColor.value = "success";
|
||||
snackbar.value = true;
|
||||
} else {
|
||||
loading.value = false;
|
||||
snackbarText.value = "Cookie 无效!";
|
||||
snackbarColor.value = "error";
|
||||
snackbar.value = true;
|
||||
}
|
||||
}
|
||||
|
||||
// 获取 Cookie
|
||||
|
||||
@@ -1,11 +1,8 @@
|
||||
<template>
|
||||
<h1>用户页</h1>
|
||||
<div class="testDiv">
|
||||
<v-btn @click="getTokens">
|
||||
获取 Tokens
|
||||
</v-btn>
|
||||
<v-btn @click="saveToken">
|
||||
保存 Token 到数据库
|
||||
<v-btn @click="updateTokens">
|
||||
更新 Tokens
|
||||
</v-btn>
|
||||
<v-btn @click="vertifyStoken">
|
||||
验证 stoken
|
||||
@@ -38,7 +35,6 @@ import TGSqlite from "../utils/TGSqlite";
|
||||
import TGUtils from "../core/utils/TGUtils";
|
||||
|
||||
const cookie = ref({} as BTMuli.User.Base.Cookie);
|
||||
const tokens = ref([] as BTMuli.User.Base.TokenItem[]);
|
||||
|
||||
export interface tokenRes {
|
||||
name: string;
|
||||
@@ -55,13 +51,15 @@ onMounted(async () => {
|
||||
});
|
||||
|
||||
// 根据获取到的 cookie.login_ticket 获取 stoken 和 ltoken
|
||||
async function getTokens () {
|
||||
async function updateTokens () {
|
||||
const tokenRes = await TGRequest.User.byLoginTicket.getLTokens(cookie.value);
|
||||
console.log(tokenRes);
|
||||
if (Array.isArray(tokenRes)) tokens.value = tokenRes;
|
||||
else {
|
||||
console.log(tokenRes);
|
||||
tokens.value = [];
|
||||
if (Array.isArray(tokenRes)) {
|
||||
const lToken = tokenRes.find((item) => item.name === "ltoken");
|
||||
const sToken = tokenRes.find((item) => item.name === "stoken");
|
||||
if (lToken) await TGSqlite.saveAppData("ltoken", lToken.token);
|
||||
if (sToken) await TGSqlite.saveAppData("stoken", sToken.token);
|
||||
} else {
|
||||
await dialog.message(
|
||||
tokenRes.message,
|
||||
{
|
||||
@@ -72,16 +70,6 @@ async function getTokens () {
|
||||
}
|
||||
}
|
||||
|
||||
// 将获取到的 token 保存到数据库
|
||||
async function saveToken () {
|
||||
console.log(tokens.value);
|
||||
const lToken = tokens.value.find((item) => item.name === "ltoken");
|
||||
const sToken = tokens.value.find((item) => item.name === "stoken");
|
||||
if (lToken) await TGSqlite.saveAppData("ltoken", lToken.token);
|
||||
if (sToken) await TGSqlite.saveAppData("stoken", sToken.token);
|
||||
console.log("保存成功");
|
||||
}
|
||||
|
||||
// 验证 stoken 的有效性
|
||||
async function vertifyStoken () {
|
||||
// 获取 stoken
|
||||
|
||||
Reference in New Issue
Block a user