From f8960aa3bcdaa0ae6e2d387675910d62aaa26534 Mon Sep 17 00:00:00 2001 From: Shen Junzheng Date: Thu, 17 Apr 2025 01:01:05 +0800 Subject: [PATCH] server command --- internal/chatlog/http/service.go | 15 ++++++++ internal/chatlog/manager.go | 41 +++++++++++++++++++++ internal/wechat/process/windows/detector.go | 4 +- 3 files changed, 58 insertions(+), 2 deletions(-) diff --git a/internal/chatlog/http/service.go b/internal/chatlog/http/service.go index 8be622a..f92d77b 100644 --- a/internal/chatlog/http/service.go +++ b/internal/chatlog/http/service.go @@ -77,6 +77,21 @@ func (s *Service) Start() error { return nil } +func (s *Service) ListenAndServe() error { + + if s.ctx.HTTPAddr == "" { + s.ctx.HTTPAddr = DefalutHTTPAddr + } + + s.server = &http.Server{ + Addr: s.ctx.HTTPAddr, + Handler: s.router, + } + + log.Info().Msg("Starting HTTP server on " + s.ctx.HTTPAddr) + return s.server.ListenAndServe() +} + func (s *Service) Stop() error { if s.server == nil { diff --git a/internal/chatlog/manager.go b/internal/chatlog/manager.go index d0b7766..8192dbd 100644 --- a/internal/chatlog/manager.go +++ b/internal/chatlog/manager.go @@ -306,3 +306,44 @@ func (m *Manager) CommandDecrypt(dataDir string, workDir string, key string, pla return nil } + +func (m *Manager) CommandHTTPServer(addr string, dataDir string, workDir string, platform string, version int) error { + + if addr == "" { + addr = "127.0.0.1:5030" + } + + if workDir == "" { + return fmt.Errorf("workDir is required") + } + + if platform == "" { + return fmt.Errorf("platform is required") + } + + if version == 0 { + return fmt.Errorf("version is required") + } + + m.ctx.HTTPAddr = addr + m.ctx.DataDir = dataDir + m.ctx.WorkDir = workDir + m.ctx.Platform = platform + m.ctx.Version = version + + // 如果是 4.0 版本,更新下 xorkey + if m.ctx.Version == 4 && m.ctx.DataDir != "" { + go dat2img.ScanAndSetXorKey(m.ctx.DataDir) + } + + // 按依赖顺序启动服务 + if err := m.db.Start(); err != nil { + return err + } + + if err := m.mcp.Start(); err != nil { + return err + } + + return m.http.ListenAndServe() +} diff --git a/internal/wechat/process/windows/detector.go b/internal/wechat/process/windows/detector.go index ccec205..6da58e4 100644 --- a/internal/wechat/process/windows/detector.go +++ b/internal/wechat/process/windows/detector.go @@ -13,8 +13,8 @@ import ( const ( V3ProcessName = "WeChat" V4ProcessName = "Weixin" - V3DBFile = "Msg\\Misc.db" - V4DBFile = "db_storage\\message\\message_0.db" + V3DBFile = `Msg\Misc.db` + V4DBFile = `db_storage\session\session.db` ) // Detector 实现 Windows 平台的进程检测器