From 2ef81fff8fe537f109e6f25015ee08ad9ec1c8f0 Mon Sep 17 00:00:00 2001 From: digua Date: Thu, 8 Jan 2026 23:00:34 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20member=E8=A1=A8=E6=94=AF=E6=8C=81?= =?UTF-8?q?=E8=A7=92=E8=89=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- electron/main/database/core.ts | 8 ++++--- electron/main/database/migrations.ts | 24 +++++++++++--------- electron/main/parser/formats/chatlab.ts | 2 ++ electron/main/worker/import/streamImport.ts | 14 +++++++----- src/types/base.ts | 25 +++++++++++++++++++++ src/types/format.ts | 3 ++- 6 files changed, 56 insertions(+), 20 deletions(-) diff --git a/electron/main/database/core.ts b/electron/main/database/core.ts index 86f9f6d..190fe8a 100644 --- a/electron/main/database/core.ts +++ b/electron/main/database/core.ts @@ -84,7 +84,8 @@ function createDatabase(sessionId: string): Database.Database { account_name TEXT, group_nickname TEXT, aliases TEXT DEFAULT '[]', - avatar TEXT + avatar TEXT, + roles TEXT DEFAULT '[]' ); CREATE TABLE IF NOT EXISTS member_name_history ( @@ -174,7 +175,7 @@ export function importData(parseResult: ParseResult): string { ) const insertMember = db.prepare(` - INSERT OR IGNORE INTO member (platform_id, account_name, group_nickname, avatar) VALUES (?, ?, ?, ?) + INSERT OR IGNORE INTO member (platform_id, account_name, group_nickname, avatar, roles) VALUES (?, ?, ?, ?, ?) `) const getMemberId = db.prepare(` SELECT id FROM member WHERE platform_id = ? @@ -187,7 +188,8 @@ export function importData(parseResult: ParseResult): string { member.platformId, member.accountName || null, member.groupNickname || null, - member.avatar || null + member.avatar || null, + member.roles ? JSON.stringify(member.roles) : '[]' ) const row = getMemberId.get(member.platformId) as { id: number } memberIdMap.set(member.platformId, row.id) diff --git a/electron/main/database/migrations.ts b/electron/main/database/migrations.ts index ffd2930..3126f10 100644 --- a/electron/main/database/migrations.ts +++ b/electron/main/database/migrations.ts @@ -34,7 +34,7 @@ export interface MigrationInfo { } /** 当前 schema 版本(最新迁移的版本号) */ -export const CURRENT_SCHEMA_VERSION = 1 +export const CURRENT_SCHEMA_VERSION = 2 /** * 迁移脚本列表 @@ -54,15 +54,19 @@ const migrations: Migration[] = [ } }, }, - // 未来的迁移示例: - // { - // version: 2, - // description: '添加 xxx 字段', - // userMessage: '新功能说明', - // up: (db) => { - // db.exec('ALTER TABLE xxx ADD COLUMN yyy TEXT') - // }, - // }, + { + version: 2, + description: '添加 roles 字段到 member 表', + userMessage: '支持成员角色(群主、管理员等)', + up: (db) => { + // 检查 roles 列是否已存在(防止重复执行) + const tableInfo = db.prepare('PRAGMA table_info(member)').all() as Array<{ name: string }> + const hasRolesColumn = tableInfo.some((col) => col.name === 'roles') + if (!hasRolesColumn) { + db.exec("ALTER TABLE member ADD COLUMN roles TEXT DEFAULT '[]'") + } + }, + }, ] /** diff --git a/electron/main/parser/formats/chatlab.ts b/electron/main/parser/formats/chatlab.ts index 998792c..502542d 100644 --- a/electron/main/parser/formats/chatlab.ts +++ b/electron/main/parser/formats/chatlab.ts @@ -73,6 +73,7 @@ interface ChatLabMember { groupNickname?: string // 群昵称 aliases?: string[] avatar?: string // 头像(base64 Data URL) + roles?: Array<{ id: string; name?: string }> // 成员角色 } // ==================== 解析器实现 ==================== @@ -159,6 +160,7 @@ async function* parseChatLab(options: ParseOptions): AsyncGenerator