From b6ce30945536d968b41579fd3cf99201d0fbffa6 Mon Sep 17 00:00:00 2001 From: BTMuli Date: Mon, 22 May 2023 16:14:25 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=8E=A8=20GameAccount=20=E5=AD=97=E6=AE=B5?= =?UTF-8?q?=E5=8F=98=E6=9B=B4=EF=BC=8CAppData=20=E5=88=9D=E5=A7=8B?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=20cookie=20=E9=A1=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/types/Game.d.ts | 2 +- src/utils/TGSql.ts | 18 ++++++++----- src/utils/TGSqlite.ts | 61 ------------------------------------------- 3 files changed, 13 insertions(+), 68 deletions(-) diff --git a/src/types/Game.d.ts b/src/types/Game.d.ts index 8959153b..281d8d64 100644 --- a/src/types/Game.d.ts +++ b/src/types/Game.d.ts @@ -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 diff --git a/src/utils/TGSql.ts b/src/utils/TGSql.ts index ff70c481..8f276042 100644 --- a/src/utils/TGSql.ts +++ b/src/utils/TGSql.ts @@ -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 { 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; } diff --git a/src/utils/TGSqlite.ts b/src/utils/TGSqlite.ts index 696494b0..f6a54abc 100644 --- a/src/utils/TGSqlite.ts +++ b/src/utils/TGSqlite.ts @@ -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} 数据 - */ - public async getDataByKey (table: string, keyName: string, keyValue: string): Promise { - 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} - */ - public async saveData (sql: string): Promise { - 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} - */ - public async inputCookie (cookie: string): Promise { - 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} 项值 - */ - public async getCookieItem (itemKey: string): Promise { - const cookie = await this.getCookie(); - if (Object.keys(cookie).includes(itemKey)) return cookie[itemKey]; - return ""; - } - /** * @description 保存 appData * @memberOf TGSqlite