mirror of
https://github.com/BTMuli/TeyvatGuide.git
synced 2025-12-12 09:18:14 +08:00
✨ 添加游戏账号获取
This commit is contained in:
@@ -477,21 +477,29 @@ async function refreshUser () {
|
||||
await TGSqlite.saveAppData("cookie", JSON.stringify(ck));
|
||||
await userStore.initCookie(ck);
|
||||
console.log(JSON.stringify(ck));
|
||||
loadingTitle.value = "刷新成功!正在获取用户信息";
|
||||
loadingTitle.value = "刷新成功!正在获取用户头像、昵称信息";
|
||||
} else {
|
||||
loadingTitle.value = "刷新失败!正在获取用户信息";
|
||||
loadingTitle.value = "刷新失败!正在获取用户头像、昵称信息";
|
||||
failCount++;
|
||||
}
|
||||
const infoRes = await TGRequest.User.byCookie.getUserInfo(ck.cookie_token, ck.account_id);
|
||||
if (infoRes.hasOwnProperty("nickname")) {
|
||||
const info = infoRes as BTMuli.User.Base.BriefInfo;
|
||||
userStore.setBriefInfo(info);
|
||||
loadingTitle.value = "获取成功!正在获取用户游戏账号信息";
|
||||
} else {
|
||||
loadingTitle.value = "获取失败!正在获取用户游戏账号信息";
|
||||
failCount++;
|
||||
}
|
||||
const accountRes = await TGRequest.User.byCookie.getAccounts(ck.cookie_token, ck.account_id);
|
||||
if (Array.isArray(accountRes)) {
|
||||
await TGSqlite.insertAccount(accountRes);
|
||||
loadingTitle.value = "获取成功!";
|
||||
} else {
|
||||
loadingTitle.value = "获取失败!";
|
||||
failCount++;
|
||||
}
|
||||
if (failCount === 3) {
|
||||
if (failCount > 0) {
|
||||
snackbarText.value = "刷新失败!请重新输入 cookie!";
|
||||
snackbarColor.value = "error";
|
||||
snackbar.value = true;
|
||||
@@ -529,13 +537,17 @@ async function inputCookie () {
|
||||
await userStore.initCookie(ck);
|
||||
loadingTitle.value = "正在获取用户信息...";
|
||||
const cookie_token = userStore.getCookieItem("cookie_token");
|
||||
const res = await TGRequest.User.byCookie.getUserInfo(cookie_token, uid);
|
||||
const resUser = await TGRequest.User.byCookie.getUserInfo(cookie_token, uid);
|
||||
// . 判断返回是否为 BTMuli.User.Base.BriefInfo
|
||||
if (res.hasOwnProperty("nickname")) {
|
||||
const info = res as BTMuli.User.Base.BriefInfo;
|
||||
if (resUser.hasOwnProperty("nickname")) {
|
||||
const info = resUser as BTMuli.User.Base.BriefInfo;
|
||||
userStore.setBriefInfo(info);
|
||||
appStore.isLogin = true;
|
||||
}
|
||||
const resAccounts = await TGRequest.User.byCookie.getAccounts(cookie_token, uid);
|
||||
if (Array.isArray(resAccounts)) {
|
||||
await TGSqlite.insertAccount(resAccounts);
|
||||
}
|
||||
loading.value = false;
|
||||
snackbarText.value = "Cookie 已保存!";
|
||||
snackbarColor.value = "success";
|
||||
|
||||
@@ -83,6 +83,51 @@ class TGSqlite {
|
||||
return JSON.parse(res[0].value);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description 插入 Account 数据
|
||||
* @memberOf TGSqlite
|
||||
* @since Alpha v0.2.0
|
||||
* @param {BTMuli.User.Game.Account[]} accounts
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
public async insertAccount (accounts: BTMuli.User.Game.Account[]): Promise<void> {
|
||||
const db = await Database.load(this.dbPath);
|
||||
for (const a of accounts) {
|
||||
const is_chosen = a.is_chosen ? 1 : 0;
|
||||
const is_official = a.is_official ? 1 : 0;
|
||||
const sql = `
|
||||
INSERT INTO GameAccount (game_biz, game_uid, is_chosen, is_official, level, nickname, region, region_name, updated)
|
||||
VALUES ('${a.game_biz}', '${a.game_uid}', ${is_chosen}, ${is_official}, '${a.level}', '${a.nickname}',
|
||||
'${a.region}', '${a.region_name}', datetime('now', 'localtime'))
|
||||
ON CONFLICT(game_biz, game_uid) DO UPDATE SET
|
||||
is_chosen = ${is_chosen},
|
||||
is_official = ${is_official},
|
||||
level = ${a.level},
|
||||
nickname = '${a.nickname}',
|
||||
region = '${a.region}',
|
||||
region_name = '${a.region_name}',
|
||||
updated = datetime('now', 'localtime');
|
||||
`;
|
||||
console.log(sql);
|
||||
await db.execute(sql);
|
||||
}
|
||||
await db.close();
|
||||
}
|
||||
|
||||
/**
|
||||
* @description 获取当前选择的游戏账号
|
||||
* @memberOf TGSqlite
|
||||
* @since Alpha v0.2.0
|
||||
* @returns {Promise<BTMuli.User.Game.Account|false>}
|
||||
*/
|
||||
public async getCurAccount (): Promise<BTMuli.User.Game.Account | false> {
|
||||
const db = await Database.load(this.dbPath);
|
||||
const sql = "SELECT * FROM GameAccount WHERE is_chosen=1;";
|
||||
const res: BTMuli.User.Game.Account[] = await db.select(sql);
|
||||
await db.close();
|
||||
return res.length === 0 ? false : res[0];
|
||||
}
|
||||
|
||||
/**
|
||||
* @description 保存 appData
|
||||
* @memberOf TGSqlite
|
||||
@@ -155,22 +200,6 @@ class TGSqlite {
|
||||
await this.init();
|
||||
}
|
||||
|
||||
/**
|
||||
* @description 获取数据库版本及构建时间
|
||||
* @memberOf TGSqlite
|
||||
* @since Alpha v0.1.4
|
||||
* @returns {Promise<{ version: string, buildTime: string }>}
|
||||
*/
|
||||
public async getMetadata (): Promise<{ version: string, buildTime: string }> {
|
||||
const db = await Database.load(this.dbPath);
|
||||
const sql = "SELECT * FROM AppData WHERE key='appVersion' OR key='dataUpdated';";
|
||||
const res: Array<{ key: string, value: string }> = await db.select(sql);
|
||||
const version = res.find((item) => item.key === "appVersion")?.value ?? "0.0.0";
|
||||
const buildTime = res.find((item) => item.key === "dataUpdated")?.value ?? "1970-01-01 00:00:00";
|
||||
await db.close();
|
||||
return { version, buildTime };
|
||||
}
|
||||
|
||||
/**
|
||||
* @description 获取成就系列列表
|
||||
* @memberOf TGSqlite
|
||||
|
||||
@@ -8,8 +8,8 @@
|
||||
// utils
|
||||
import TGSqlite from "../../utils/TGSqlite";
|
||||
// request
|
||||
import { getTokensByLoginTicket } from "./getTokens";
|
||||
import { getCookieTokenBySToken } from "./getCookieToken";
|
||||
import { getTokensByLoginTicket } from "./getTokens";
|
||||
import { verifyLToken } from "./verifyLToken";
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user