Files
chatlog_alpha/internal/wechatdb/datasource/datasource.go
lx1056758714-glitch caf4f817db Add SNS (Moments) database support with intelligent XML parsing
Features:
- Add sns.db database integration and auto-detection
- Implement XML content parser for moments data (internal/model/sns.go)
  - Extract basic info: create time, nickname, content description
  - Parse location data: city, coordinates, POI name, address
  - Recognize media types: image, video, article, finder (video account)
  - Extract structured data: image count, video duration, article info
- Add "朋友圈检索" (Moments Search) page in HTTP UI
- Support multiple output formats:
  - JSON: Structured data for programmatic access
  - Plain text: Human-readable format with emoji icons
  - Raw XML: Original XML content for debugging
  - CSV/Excel: Export for data analysis
- Support query features: filter by username, limit, offset pagination
- Database browser integration: SNS database visible in decrypted DB list

Technical changes:
- internal/wechatdb/datasource/v4/datasource.go: Add SNS group config and query methods
- internal/wechatdb/datasource/datasource.go: Add SNS interface methods
- internal/wechatdb/wechatdb.go: Add GetSNSTimeline and GetSNSCount
- internal/chatlog/database/service.go: Add SNS service layer methods
- internal/chatlog/http/route.go: Add /api/v1/sns endpoint with format support
- internal/chatlog/http/static/index.htm: Add moments search tab and UI
- .gitignore: Ignore tmpclaude directories and sns.md test file
- README.md: Update changelog for 2026-01-14

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-01-14 10:12:32 +08:00

62 lines
1.8 KiB
Go

package datasource
import (
"context"
"time"
"github.com/fsnotify/fsnotify"
"github.com/sjzar/chatlog/internal/errors"
"github.com/sjzar/chatlog/internal/model"
v4 "github.com/sjzar/chatlog/internal/wechatdb/datasource/v4"
)
type DataSource interface {
// 消息
GetMessages(ctx context.Context, startTime, endTime time.Time, talker string, sender string, keyword string, limit, offset int) ([]*model.Message, error)
GetMessage(ctx context.Context, talker string, seq int64) (*model.Message, error)
// 联系人
GetContacts(ctx context.Context, key string, limit, offset int) ([]*model.Contact, error)
// 群聊
GetChatRooms(ctx context.Context, key string, limit, offset int) ([]*model.ChatRoom, error)
// 最近会话
GetSessions(ctx context.Context, key string, limit, offset int) ([]*model.Session, error)
// 媒体
GetMedia(ctx context.Context, _type string, key string) (*model.Media, error)
// 朋友圈
GetSNSTimeline(ctx context.Context, username string, limit, offset int) ([]map[string]interface{}, error)
GetSNSCount(ctx context.Context, username string) (int, error)
// 设置回调函数
SetCallback(group string, callback func(event fsnotify.Event) error) error
// 获取数据库列表
GetDBs() (map[string][]string, error)
// 获取指定数据库的表列表
GetTables(group, file string) ([]string, error)
// 获取指定表的数据
GetTableData(group, file, table string, limit, offset int, keyword string) ([]map[string]interface{}, error)
// 执行 SQL 查询
ExecuteSQL(group, file, query string) ([]map[string]interface{}, error)
Close() error
}
func New(path string, platform string, version int) (DataSource, error) {
switch {
case platform == "windows" && version == 4:
return v4.New(path)
default:
return nil, errors.PlatformUnsupported(platform, version)
}
}