mirror of
https://github.com/BTMuli/TeyvatGuide.git
synced 2026-03-15 03:53:16 +08:00
🐛 将ck更新逻辑移至首页,修正更新sql语句
This commit is contained in:
@@ -354,8 +354,6 @@ async function checkUserLoad(): Promise<void> {
|
||||
isLogin.value = false;
|
||||
return;
|
||||
}
|
||||
// 检测ck刷新
|
||||
await TSUserAccount.account.updateCk();
|
||||
if (!isLogin.value) isLogin.value = true;
|
||||
// 然后获取最近的UID
|
||||
if (uid.value === undefined || !uidDB.includes(uid.value)) {
|
||||
|
||||
@@ -77,7 +77,7 @@
|
||||
{{ props.pos.liben_detail.is_has_taken_special_reward ? "已" : "未" }}领取礼盒
|
||||
</span>
|
||||
</template>
|
||||
<!-- 处理累登活动 TODO:待完善 -->
|
||||
<!-- 处理累登活动 -->
|
||||
<template v-else-if="props.pos.type === gameEnum.actCalendarType.SignIn">
|
||||
<span>{{ props.pos.sign_in_detail.progress }}/{{ props.pos.sign_in_detail.total }}</span>
|
||||
<span>当天{{ props.pos.sign_in_detail.status === 1 ? "未领取" : "已领取" }}</span>
|
||||
|
||||
@@ -78,6 +78,7 @@ import PhCompCalendar from "@comp/pageHome/ph-comp-calendar.vue";
|
||||
import PhCompPool from "@comp/pageHome/ph-comp-pool.vue";
|
||||
import PhCompPosition from "@comp/pageHome/ph-comp-position.vue";
|
||||
import PhCompSign from "@comp/pageHome/ph-comp-sign.vue";
|
||||
import TSUserAccount from "@Sqlm/userAccount.js";
|
||||
import useAppStore from "@store/app.js";
|
||||
import useBBSStore from "@store/bbs.js";
|
||||
import useHomeStore from "@store/home.js";
|
||||
@@ -123,6 +124,7 @@ onMounted(async () => {
|
||||
const isProdEnv = import.meta.env.MODE === "production";
|
||||
if (isProdEnv && devMode.value) devMode.value = false;
|
||||
if (isLogin.value) {
|
||||
await TSUserAccount.account.updateCk();
|
||||
await showLoading.start("正在加载首页小部件");
|
||||
games.value = gameList.value.map((i) => ({ icon: i.app_icon, title: i.name, gid: i.id }));
|
||||
showItems.value = homeStore.getShowItems();
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/**
|
||||
* Sqlite 数据库操作类
|
||||
* @since Beta v0.9.1
|
||||
* @since Beta v0.9.5
|
||||
*/
|
||||
|
||||
import showSnackbar from "@comp/func/snackbar.js";
|
||||
@@ -164,7 +164,7 @@ class Sqlite {
|
||||
|
||||
/**
|
||||
* 重置数据库
|
||||
* @since Beta v0.9.1
|
||||
* @since Beta v0.9.5
|
||||
* @returns 无返回值
|
||||
*/
|
||||
public async reset(): Promise<void> {
|
||||
@@ -178,13 +178,12 @@ class Sqlite {
|
||||
await db.execute("BEGIN IMMEDIATE;");
|
||||
try {
|
||||
for (const item of this.tables) {
|
||||
const sql = `DROP TABLE IF EXISTS "${item}";`;
|
||||
await db.execute(sql);
|
||||
await db.execute("DROP TABLE IF EXISTS $1", [item]);
|
||||
}
|
||||
await db.execute("COMMIT;");
|
||||
} catch (innerErr) {
|
||||
await db.execute("ROLLBACK;");
|
||||
console.error(innerErr);
|
||||
await db.execute("ROLLBACK;");
|
||||
}
|
||||
await this.initDB();
|
||||
return;
|
||||
|
||||
@@ -132,7 +132,7 @@ async function saveAccount(data: TGApp.App.Account.User): Promise<void> {
|
||||
|
||||
/**
|
||||
* 检测并更新
|
||||
* @since Beta v0.9.2
|
||||
* @since Beta v0.9.5
|
||||
* @returns 无返回值
|
||||
*/
|
||||
async function updateAllAccountCk(): Promise<void> {
|
||||
@@ -142,25 +142,26 @@ async function updateAllAccountCk(): Promise<void> {
|
||||
for (const account of accounts) {
|
||||
const diffTime = Date.now() - new Date(account.updated).getTime();
|
||||
if (diffTime > checkTime) {
|
||||
await showLoading.start(`更新${account.uid}Cookie`, `上次更新:${account.updated}`);
|
||||
await TGLogger.Info(`更新${account.uid}Cookie,上次更新:${account.updated}`);
|
||||
const update = await updateAccountCk(account);
|
||||
if (update) {
|
||||
showSnackbar.success(`成功更新${account.uid}的Cookie`);
|
||||
await new Promise<void>((resolve) => setTimeout(resolve, 1000));
|
||||
cnt++;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (cnt > 0) await showLoading.end();
|
||||
if (cnt > 0) showSnackbar.success(`成功更新${cnt}位账户的Cookie`);
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新用户Cookie
|
||||
* @since Beta v0.9.2
|
||||
* @since Beta v0.9.5
|
||||
* @param data - 用户信息
|
||||
* @returns 是否更新成功
|
||||
*/
|
||||
async function updateAccountCk(data: TGApp.App.Account.User): Promise<boolean> {
|
||||
await showLoading.start("正在更新用户Cookie", `UID:${data.uid},上次更新:${data.updated}`);
|
||||
const ck = data.cookie;
|
||||
await showLoading.update("正在获取 LToken");
|
||||
const ltokenRes = await passportReq.lToken.get(ck);
|
||||
@@ -190,23 +191,27 @@ async function updateAccountCk(data: TGApp.App.Account.User): Promise<boolean> {
|
||||
await TGLogger.Error(`获取用户数据失败:${briefRes.retcode}-${briefRes.message}`);
|
||||
return false;
|
||||
}
|
||||
const briefInfo: TGApp.App.Account.BriefInfo = {
|
||||
nickname: briefRes.nickname,
|
||||
uid: briefRes.uid,
|
||||
avatar: briefRes.avatar_url,
|
||||
desc: briefRes.introduce,
|
||||
};
|
||||
const updated = timestampToDate(new Date().getTime());
|
||||
await showLoading.update("正在写入数据库");
|
||||
const db = await TGSqlite.getDB();
|
||||
try {
|
||||
// 让 SQLite 在遇到锁时等待(毫秒)
|
||||
await db.execute("PRAGMA busy_timeout = 1000;");
|
||||
// 立即获取写锁,减少中途被抢占的概率
|
||||
await db.execute("PRAGMA busy_timeout = 5000;");
|
||||
await db.execute("BEGIN IMMEDIATE;");
|
||||
await db.execute(
|
||||
"UPDATE UserAccount SET cookie = '?' AND brief = '?' AND updated = '?' WHERE uid = '?';",
|
||||
[JSON.stringify(ck), JSON.stringify(briefRes), updated, data.uid],
|
||||
"UPDATE UserAccount SET cookie = $1, brief = $2, updated = $3 WHERE uid = $4;",
|
||||
[JSON.stringify(ck), JSON.stringify(briefInfo), updated, data.uid],
|
||||
);
|
||||
await db.execute("COMMIT;");
|
||||
return true;
|
||||
} catch (innerErr) {
|
||||
await db.execute("ROLLBACK;");
|
||||
console.error(innerErr);
|
||||
await db.execute("ROLLBACK;");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user