-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
/
related.go
71 lines (56 loc) Β· 1.33 KB
/
related.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package photoprism
import (
"strings"
"github.com/photoprism/photoprism/pkg/clean"
)
// RelatedFiles represents a list of related files to be indexed or imported.
type RelatedFiles struct {
Files MediaFiles
Main *MediaFile
}
// HasPreview checks if the list of files contains a PNG or JPEG image to render a preview in the UI.
func (m RelatedFiles) HasPreview() bool {
for _, f := range m.Files {
if f.IsPreviewImage() {
return true
}
}
if m.Main == nil {
return false
}
return m.Main.IsPreviewImage()
}
// String returns file names as string.
func (m RelatedFiles) String() string {
names := make([]string, len(m.Files))
for i, f := range m.Files {
names[i] = f.BaseName()
}
return strings.Join(names, ", ")
}
// Len returns the number of related files.
func (m RelatedFiles) Len() int {
return len(m.Files)
}
// Count returns the number of files without the main file.
func (m RelatedFiles) Count() int {
if l := m.Len(); l < 1 {
return l
} else {
return l - 1
}
}
// MainFileType returns the main file type as string.
func (m RelatedFiles) MainFileType() string {
if m.Main == nil {
return ""
}
return string(m.Main.FileType())
}
// MainLogName returns the main file name for logging.
func (m RelatedFiles) MainLogName() string {
if m.Main == nil {
return ""
}
return clean.Log(m.Main.RootRelName())
}