readMessageBody fetches an objectified agent-message body (content-addressed on disk) and returns its text.
(db *sql.DB, hash string)
| 150 | // readMessageBody fetches an objectified agent-message body (content-addressed on |
| 151 | // disk) and returns its text. |
| 152 | func readMessageBody(db *sql.DB, hash string) string { |
| 153 | var path string |
| 154 | if err := db.QueryRow(`SELECT path FROM provenance_objects WHERE hash = ?`, hash).Scan(&path); err != nil { |
| 155 | return "" |
| 156 | } |
| 157 | raw, err := os.ReadFile(path) |
| 158 | if err != nil { |
| 159 | return "" |
| 160 | } |
| 161 | var obj struct { |
| 162 | Payload struct { |
| 163 | Body string `json:"body"` |
| 164 | Content string `json:"content"` |
| 165 | } `json:"payload"` |
| 166 | } |
| 167 | if err := json.Unmarshal(raw, &obj); err != nil { |
| 168 | return "" |
| 169 | } |
| 170 | if obj.Payload.Body != "" { |
| 171 | return obj.Payload.Body |
| 172 | } |
| 173 | return obj.Payload.Content |
| 174 | } |
no test coverage detected