/
index_result.go
67 lines (56 loc) Β· 1.78 KB
/
index_result.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
package photoprism
const (
IndexUpdated IndexStatus = "updated"
IndexAdded IndexStatus = "added"
IndexStacked IndexStatus = "stacked"
IndexSkipped IndexStatus = "skipped"
IndexDuplicate IndexStatus = "skipped duplicate"
IndexArchived IndexStatus = "skipped archived"
IndexFailed IndexStatus = "failed"
)
type IndexStatus string
// IndexResult represents a media file indexing result.
type IndexResult struct {
Status IndexStatus
Err error
FileID uint
FileUID string
PhotoID uint
PhotoUID string
}
// String returns the indexing result as string.
func (r IndexResult) String() string {
return string(r.Status)
}
// Success checks whether a media file was successfully indexed or skipped.
func (r IndexResult) Success() bool {
return !r.Failed() && (r.FileID > 0 || r.Stacked() || r.Skipped() || r.Archived())
}
// Failed checks if indexing has failed.
func (r IndexResult) Failed() bool {
return r.Err != nil && r.Status == IndexFailed
}
// Indexed checks whether a media file was successfully indexed.
func (r IndexResult) Indexed() bool {
return r.Status == IndexAdded || r.Status == IndexUpdated || r.Status == IndexStacked
}
// Stacked checks whether a media file was stacked while indexing.
func (r IndexResult) Stacked() bool {
return r.Status == IndexStacked
}
// Skipped checks whether a media file was skipped while indexing.
func (r IndexResult) Skipped() bool {
return r.Status == IndexSkipped
}
// Archived checks whether a media file was skipped because it is archived.
func (r IndexResult) Archived() bool {
return r.Status == IndexArchived
}
// FileError checks if there is a file error and returns it.
func (r IndexResult) FileError() (string, error) {
if r.Failed() && r.FileUID != "" {
return r.FileUID, r.Err
} else {
return "", nil
}
}