Skip to content

Commit

Permalink
✨ 手动输入CK&用户删除
Browse files Browse the repository at this point in the history
  • Loading branch information
BTMuli committed Sep 22, 2024
1 parent c8724ee commit fc43ed1
Show file tree
Hide file tree
Showing 3 changed files with 154 additions and 6 deletions.
1 change: 1 addition & 0 deletions src/components/app/t-sidebar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,7 @@ onUnmounted(() => themeListener());
.side-icon.paimon {
width: 32px;
height: 32px;
border-radius: 50%;
margin-right: 24px;
transform: translateX(-4px);
}
Expand Down
146 changes: 140 additions & 6 deletions src/components/config/tc-userBadge.vue
Original file line number Diff line number Diff line change
Expand Up @@ -64,19 +64,33 @@
/>
</template>
<v-list>
<v-list-item
v-for="account in accounts"
:key="account.uid"
@click="loadAccount(account.uid)"
>
<v-list-item v-for="account in accounts" :key="account.uid">
<v-list-item-title>{{ account.brief.nickname }}</v-list-item-title>
<v-list-item-subtitle>{{ account.brief.uid }}</v-list-item-subtitle>
<template #append>
<div v-if="account.uid === userStore.uid.value" title="当前登录账号">
<v-icon color="green">mdi-check</v-icon>
<v-icon color="green">mdi-account-check</v-icon>
</div>
<v-icon
v-else
size="small"
icon="mdi-account-convert"
title="切换用户"
@click="loadAccount(account.uid)"
/>
<v-icon
class="tcu-btn"
icon="mdi-delete"
title="删除用户"
size="small"
@click="clearUser(account)"
/>
</template>
</v-list-item>
<v-list-item @click="addByCookie()" append-icon="mdi-account-plus">
<v-list-item-title>手动添加</v-list-item-title>
<v-list-item-subtitle>手动输入Cookie</v-list-item-subtitle>
</v-list-item>
</v-list>
</v-menu>
</template>
Expand Down Expand Up @@ -416,10 +430,130 @@ async function showAccounts(): Promise<void> {
return;
}
}
async function addByCookie(): Promise<void> {
const ckInput = await showConfirm({
mode: "input",
title: "请输入cookie",
text: "Cookie:",
});
if (!ckInput) {
showSnackbar({ text: "已取消Cookie输入", color: "cancel" });
return;
}
if (ckInput === "") {
showSnackbar({ text: "请输入Cookie!", color: "warn" });
return;
}
const ckArr = ckInput.split(";");
let ckRes = { stoken: "", stuid: "", mid: "" };
for (const ck of ckArr) {
if (ck.startsWith("mid=")) ckRes.mid = ck.substring(4);
else if (ck.startsWith("stoken=")) ckRes.stoken = ck.substring(7);
else if (ck.startsWith("stuid=")) ckRes.stuid = ck.substring(6);
}
if (ckRes.mid === "" || ckRes.stoken === "" || ckRes.stuid === "") {
showSnackbar({ text: "解析Cookie失败", color: "error" });
await TGLogger.Error(`解析Cookie失败:${ckInput}`);
return;
}
loading.value = true;
emits("loadOuter", { show: true, title: "尝试刷新Cookie" });
const ck: TGApp.App.Account.Cookie = {
account_id: ckRes.stuid,
ltuid: ckRes.stuid,
stuid: ckRes.stuid,
mid: ckRes.mid,
cookie_token: "",
stoken: ckRes.stoken,
ltoken: "",
};
emits("loadOuter", { show: true, title: "正在获取 LToken" });
const ltokenRes = await TGRequest.User.bySToken.getLToken(ck.mid, ck.stoken);
if (typeof ltokenRes !== "string") {
showSnackbar({ text: `[${ltokenRes.retcode}]${ltokenRes.message}`, color: "error" });
await TGLogger.Error(`获取LToken失败:${ltokenRes.retcode}-${ltokenRes.message}`);
loading.value = false;
emits("loadOuter", { show: false });
return;
}
ck.ltoken = ltokenRes;
emits("loadOuter", { show: true, title: "正在获取 cookieToken " });
const cookieTokenRes = await TGRequest.User.bySToken.getCookieToken(ck.mid, ck.stoken);
if (typeof cookieTokenRes !== "string") {
showSnackbar({ text: `[${cookieTokenRes.retcode}]${cookieTokenRes.message}`, color: "error" });
await TGLogger.Error(
`获取CookieToken失败:${cookieTokenRes.retcode}-${cookieTokenRes.message}`,
);
loading.value = false;
emits("loadOuter", { show: false });
return;
}
ck.cookie_token = cookieTokenRes;
emits("loadOuter", { show: true, title: "正在获取用户信息" });
const briefRes = await TGRequest.User.byCookie.getUserInfo(ck.cookie_token, ck.account_id);
if ("retcode" in briefRes) {
showSnackbar({ text: `[${briefRes.retcode}]${briefRes.message}` });
await TGLogger.Error(`获取用户数据失败:${briefRes.retcode}-${briefRes.message}`);
loading.value = false;
emits("loadOuter", { show: false });
return;
}
const briefInfo: TGApp.App.Account.BriefInfo = {
nickname: briefRes.nickname,
uid: briefRes.uid,
avatar: briefRes.avatar_url,
desc: briefRes.introduce,
};
emits("loadOuter", { show: true, title: "正在保存用户数据" });
await TSUserAccount.account.saveAccount({
uid: briefInfo.uid,
cookie: ck,
brief: briefInfo,
updated: "",
});
emits("loadOuter", { show: true, title: "正在获取游戏账号" });
const gameRes = await TGRequest.User.bySToken.getAccounts(ck.stoken, ck.stuid);
if (!Array.isArray(gameRes)) {
loading.value = false;
emits("loadOuter", { show: false });
showSnackbar({ text: `[${gameRes.retcode}]${gameRes.message}` });
return;
}
await TSUserAccount.game.saveAccounts(briefInfo.uid, gameRes);
const curAccount = await TSUserAccount.game.getCurAccount(briefInfo.uid);
if (!curAccount) {
showSnackbar({ text: "未检测到游戏账号,请重新刷新", color: "warn" });
loading.value = false;
emits("loadOuter", { show: false });
return;
}
loading.value = false;
emits("loadOuter", { show: false });
showSnackbar({ text: "成功加载用户数据!" });
}
async function clearUser(user: TGApp.App.Account.User): Promise<void> {
if (user.uid === userStore.uid.value) {
showSnackbar({ text: "当前登录用户不许删除!", color: "warn" });
return;
}
const confirm = await showConfirm({ title: "确认删除", text: "将删除账号及其游戏账号数据" });
if (!confirm) {
showSnackbar({ text: "取消删除用户数据", color: "cancel" });
return;
}
await TSUserAccount.account.deleteAccount(user.uid);
showSnackbar({ text: "成功删除用户!", color: "success" });
}
</script>
<style lang="css" scoped>
.tcu-box {
border-radius: 10px;
background-image: linear-gradient(to right, #f78ca0 0%, #f9748f 19%, #fd868c 60%, #fe9a8b 100%);
}
.tcu-btn {
margin-left: 5px;
}
</style>
13 changes: 13 additions & 0 deletions src/plugins/Sqlite/modules/userAccount.ts
Original file line number Diff line number Diff line change
Expand Up @@ -216,13 +216,26 @@ async function saveGameAccount(
}
}

/**
* @description 删除游戏账户数据
* @since Beta v0.6.0
* @param {string} uid - 米社UID
* @returns {Promise<void>}
*/
async function deleteAccount(uid: string): Promise<void> {
const db = await TGSqlite.getDB();
await db.execute("DELETE FROM GameAccount WHERE uid = ?;", [uid]);
await db.execute("DELETE FROM UserAccount WHERE uid = ?;", [uid]);
}

const TSUserAccount = {
account: {
getAllUid: getAllAccountId,
getAllAccount,
getAccount: getUserAccount,
saveAccount,
copy: copyCookie,
deleteAccount,
},
game: {
getAccount: getGameAccount,
Expand Down

0 comments on commit fc43ed1

Please sign in to comment.