-
Notifications
You must be signed in to change notification settings - Fork 1
/
attachments.go
40 lines (37 loc) · 1.01 KB
/
attachments.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package model
import (
"context"
fb "github.com/FlashbackSRS/flashback-model"
)
// FetchAttachment fetches the requested attachment associated with the specified
// card.
func (r *Repo) FetchAttachment(ctx context.Context, cardID, filename string) (*fb.Attachment, error) {
defer profile("FetchAttachment %s %s", cardID, filename)()
udb, err := r.userDB(ctx)
if err != nil {
return nil, err
}
card := &fb.Card{}
if e := getDoc(ctx, udb, cardID, &card); e != nil {
return nil, e
}
bdb, err := r.newDB(ctx, card.BundleID())
if err != nil {
return nil, err
}
fbCard := &Card{Card: card}
if err := fbCard.fetch(ctx, r.local); err != nil {
return nil, err
}
for _, attName := range fbCard.note.Note.Attachments.FileList() {
if filename == attName {
return getAttachment(ctx, bdb, fbCard.note.Note.ID, filename)
}
}
for _, attName := range fbCard.model.Theme.Attachments.FileList() {
if filename == attName {
return getAttachment(ctx, bdb, fbCard.model.Theme.ID, filename)
}
}
return nil, nil
}