attachmentArgsByPath indexes the attached files by absolute path, ready for attachmentArgForDestination to look one up. An argument with no URL is indexed too, so validation can run before anything has uploaded.
(attachmentArgs []attachmentArg)
| 324 | // attachmentArgForDestination to look one up. An argument with no URL is |
| 325 | // indexed too, so validation can run before anything has uploaded. |
| 326 | func attachmentArgsByPath(attachmentArgs []attachmentArg) (map[string]int, error) { |
| 327 | byPath := make(map[string]int, len(attachmentArgs)) |
| 328 | for i, a := range attachmentArgs { |
| 329 | if a.Path == "" { |
| 330 | continue |
| 331 | } |
| 332 | abs, err := filepath.Abs(a.Path) |
| 333 | if err != nil { |
| 334 | return nil, err |
| 335 | } |
| 336 | if _, dup := byPath[abs]; dup { |
| 337 | continue |
| 338 | } |
| 339 | byPath[abs] = i |
| 340 | } |
| 341 | return byPath, nil |
| 342 | } |
| 343 | |
| 344 | // attachmentArgForDestination is where the two halves of this package meet: it |
| 345 | // takes a markdown destination and answers which attached file, if any, it |