diff options
Diffstat (limited to 'format_rich_log.go')
| -rw-r--r-- | format_rich_log.go | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/format_rich_log.go b/format_rich_log.go index ddf75bf..09bea60 100644 --- a/format_rich_log.go +++ b/format_rich_log.go @@ -12,6 +12,41 @@ import ( const termWidth = 120 // The target width for the formatted output boxes. +func parseRichLog(filename string) *chatpb.Chats { + data, err := os.ReadFile(filename) + if err != nil { + log.Fatalf("Error reading file %s: %v", filename, err) + } + + logData, err := chatpb.UnmarshalChatsTEXT(data) + if err != nil { + log.Fatalf("Error unmarshaling log file %s: %v", filename, err) + } + + for _, chat := range logData.GetChats() { + // Handle content: prefer content_file, fallback to content. + var content string + if contentFile := chat.GetContentFile(); contentFile != "" { + // Construct the full path relative to the log file's directory. + logDir := filepath.Dir(filename) + contentPath := filepath.Join(logDir, contentFile) + + contentBytes, err := os.ReadFile(contentPath) + if err != nil { + content = fmt.Sprintf("--- ERROR: Could not read content file %s: %v ---", contentPath, err) + } else { + content = string(contentBytes) + } + } else { + // Fallback for older log formats. + content = chat.GetContent() + } + chat.Content = content + } + + return logData +} + func formatRichLog(filename string) *chatpb.Chats { data, err := os.ReadFile(filename) if err != nil { |
