mirror of
https://github.com/BTMuli/TeyvatGuide.git
synced 2025-12-12 09:18:14 +08:00
🎨 GameAccount 字段变更,AppData 初始添加 cookie 项
This commit is contained in:
2
src/types/Game.d.ts
vendored
2
src/types/Game.d.ts
vendored
@@ -8,7 +8,7 @@
|
||||
declare namespace BTMuli.User.Game {
|
||||
/**
|
||||
* @description 游戏账号
|
||||
* @see TGRequest.User.byCookie.getGameAccounts
|
||||
* @see TGRequest.User.byCookie.getAccounts
|
||||
* @since Alpha v0.2.0
|
||||
* @property {string} game_biz 游戏 biz,例如 hk4e_cn
|
||||
* @property {string} game_uid 游戏 uid
|
||||
|
||||
@@ -40,16 +40,16 @@ function initGameAccountTable (): string[] {
|
||||
sqlRes.push(`
|
||||
CREATE TABLE IF NOT EXISTS GameAccount
|
||||
(
|
||||
gameBiz TEXT NOT NULL,
|
||||
gameUid TEXT NOT NULL,
|
||||
isChosen BOOLEAN DEFAULT 0,
|
||||
isOfficial BOOLEAN DEFAULT 0,
|
||||
game_biz TEXT NOT NULL,
|
||||
game_uid TEXT NOT NULL,
|
||||
is_chosen BOOLEAN DEFAULT 0,
|
||||
is_official BOOLEAN DEFAULT 0,
|
||||
level INTEGER DEFAULT 0,
|
||||
nickname TEXT DEFAULT NULL,
|
||||
region TEXT DEFAULT NULL,
|
||||
regionName TEXT DEFAULT NULL,
|
||||
region_name TEXT DEFAULT NULL,
|
||||
updated TEXT DEFAULT NULL,
|
||||
PRIMARY KEY (gameBiz, gameUid)
|
||||
PRIMARY KEY (game_biz, game_uid)
|
||||
);
|
||||
`);
|
||||
return sqlRes;
|
||||
@@ -191,6 +191,12 @@ async function initAppData (): Promise<string[]> {
|
||||
VALUES ('dataUpdated', '${dataUpdated}', datetime('now', 'localtime'))
|
||||
ON CONFLICT(key) DO UPDATE SET value = '${dataUpdated}', updated = datetime('now', 'localtime');
|
||||
`);
|
||||
// 初始化 cookie
|
||||
sqlRes.push(`
|
||||
INSERT INTO AppData (key, value, updated)
|
||||
VALUES ('cookie', '{}', datetime('now', 'localtime'))
|
||||
ON CONFLICT(key) DO NOTHING;
|
||||
`);
|
||||
return sqlRes;
|
||||
}
|
||||
|
||||
|
||||
@@ -69,54 +69,6 @@ class TGSqlite {
|
||||
return res;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description 封装-根据 table keys 获取数据
|
||||
* @memberOf TGSqlite
|
||||
* @since Alpha v0.2.0
|
||||
* @param {string} table 表名
|
||||
* @param {string} keyName 键名
|
||||
* @param {string} keyValue 键值
|
||||
* @returns {Promise<unknown[]>} 数据
|
||||
*/
|
||||
public async getDataByKey (table: string, keyName: string, keyValue: string): Promise<unknown[]> {
|
||||
const db = await Database.load(this.dbPath);
|
||||
const sql = `SELECT * FROM ${table} WHERE ${keyName}='${keyValue}';`;
|
||||
const res: unknown[] = await db.select(sql);
|
||||
await db.close();
|
||||
return res;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description 封装-保存数据
|
||||
* @memberOf TGSqlite
|
||||
* @since Alpha v0.2.0
|
||||
* @param {string} sql sql语句
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
public async saveData (sql: string): Promise<void> {
|
||||
const db = await Database.load(this.dbPath);
|
||||
await db.execute(sql);
|
||||
await db.close();
|
||||
}
|
||||
|
||||
/**
|
||||
* @description 输入 cookie
|
||||
* @memberOf TGSqlite
|
||||
* @since Alpha v0.2.0
|
||||
* @param {string} cookie
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
public async inputCookie (cookie: string): Promise<void> {
|
||||
const db = await Database.load(this.dbPath);
|
||||
const sql = `
|
||||
INSERT INTO AppData (key, value, updated)
|
||||
VALUES ('cookie', '${cookie}', datetime('now', 'localtime'))
|
||||
ON CONFLICT(key) DO UPDATE SET value = '${cookie}',updated = datetime('now', 'localtime');
|
||||
`;
|
||||
await db.execute(sql);
|
||||
await db.close();
|
||||
}
|
||||
|
||||
/**
|
||||
* @description 获取 cookie
|
||||
* @memberOf TGSqlite
|
||||
@@ -131,19 +83,6 @@ class TGSqlite {
|
||||
return JSON.parse(res[0].value);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description 获取 cookie 某项值
|
||||
* @memberOf TGSqlite
|
||||
* @since Alpha v0.2.0
|
||||
* @param {string} itemKey 项名
|
||||
* @returns {Promise<string>} 项值
|
||||
*/
|
||||
public async getCookieItem (itemKey: string): Promise<string> {
|
||||
const cookie = await this.getCookie();
|
||||
if (Object.keys(cookie).includes(itemKey)) return cookie[itemKey];
|
||||
return "";
|
||||
}
|
||||
|
||||
/**
|
||||
* @description 保存 appData
|
||||
* @memberOf TGSqlite
|
||||
|
||||
Reference in New Issue
Block a user