forked from cozy/cozy-stack
-
Notifications
You must be signed in to change notification settings - Fork 0
/
delete.go
42 lines (38 loc) · 996 Bytes
/
delete.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
41
42
package note
import (
"github.com/cozy/cozy-stack/model/instance"
"github.com/cozy/cozy-stack/model/vfs"
"github.com/cozy/cozy-stack/pkg/consts"
"github.com/cozy/cozy-stack/pkg/couchdb"
"github.com/cozy/cozy-stack/pkg/prefixer"
)
func init() {
vfs.DeleteNote = deleteNote
}
func deleteNote(db prefixer.Prefixer, noteID string) {
go func() {
images, err := getImages(db, noteID)
if err == nil {
formats := []string{
consts.NoteImageOriginalFormat,
consts.NoteImageThumbFormat,
}
for _, img := range images {
inst := &instance.Instance{
Domain: db.DomainName(),
Prefix: db.DBPrefix(),
}
_ = inst.ThumbsFS().RemoveNoteThumb(img.ID(), formats)
_ = couchdb.DeleteDoc(db, img)
}
}
steps, err := getSteps(db, noteID, 0)
if err == nil && len(steps) > 0 {
docs := make([]couchdb.Doc, 0, len(steps))
for i := range steps {
docs = append(docs, &steps[i])
}
_ = couchdb.BulkDeleteDocs(db, consts.NotesSteps, docs)
}
}()
}