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