Goes through a given attachments map, loads attachments (by their 'digest' properties) and adds 'data' properties containing the data. The data is added as raw []byte; the JSON marshaller will convert that to base64. If minRevpos is > 0, then only attachments that have been changed in a revision of
(attachments AttachmentsMeta, minRevpos int, docid string)
| 209 | // If minRevpos is > 0, then only attachments that have been changed in a revision of that |
| 210 | // generation or later are loaded. |
| 211 | func (c *DatabaseCollection) loadAttachmentsData(attachments AttachmentsMeta, minRevpos int, docid string) (newAttachments AttachmentsMeta, err error) { |
| 212 | newAttachments = attachments.ShallowCopy() |
| 213 | |
| 214 | for attachmentName, value := range newAttachments { |
| 215 | meta := value.(map[string]interface{}) |
| 216 | revpos, ok := base.ToInt64(meta["revpos"]) |
| 217 | if ok && revpos >= int64(minRevpos) { |
| 218 | digest, ok := meta["digest"] |
| 219 | if !ok { |
| 220 | return nil, base.RedactErrorf("Unable to load attachment for doc: %v with name: %v and revpos: %v due to missing digest field", base.UD(docid), base.UD(attachmentName), revpos) |
| 221 | } |
| 222 | digestStr, ok := digest.(string) |
| 223 | if !ok { |
| 224 | return nil, base.RedactErrorf("Unable to load attachment for doc: %v with name: %v and revpos: %v due to unexpected digest field: %v", base.UD(docid), base.UD(attachmentName), revpos, digest) |
| 225 | } |
| 226 | version, ok := GetAttachmentVersion(meta) |
| 227 | if !ok { |
| 228 | return nil, base.RedactErrorf("Unable to load attachment for doc: %v with name: %v, revpos: %v and digest: %v due to unexpected version value: %v", base.UD(docid), base.UD(attachmentName), revpos, digest, version) |
| 229 | } |
| 230 | attachmentKey := MakeAttachmentKey(version, docid, digestStr) |
| 231 | data, err := c.GetAttachment(attachmentKey) |
| 232 | if err != nil { |
| 233 | return nil, err |
| 234 | } |
| 235 | meta["data"] = data |
| 236 | delete(meta, "stub") |
| 237 | } |
| 238 | } |
| 239 | |
| 240 | return newAttachments, nil |
| 241 | } |
| 242 | |
| 243 | // DeleteAttachmentVersion removes attachment versions from the AttachmentsMeta map specified. |
| 244 | func DeleteAttachmentVersion(attachments AttachmentsMeta) { |
no test coverage detected