-
-
Notifications
You must be signed in to change notification settings - Fork 11
/
ordering.go
65 lines (57 loc) · 1.31 KB
/
ordering.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
package utils
import (
"os"
"path/filepath"
"sync"
)
type locationUtil interface {
GetLocation(path string) (*Location, error)
}
type SortOptions struct {
ByLocation bool
ByCamera bool
}
func GetOrder(sortoptions SortOptions, GetLocation locationUtil, osPathname, out, mediaDate, deviceName string) string {
order := orderFromConfig()
dayFolder := out
var wg sync.WaitGroup
for _, item := range order {
switch item {
case "date":
dayFolder = filepath.Join(dayFolder, mediaDate)
case "camera":
if sortoptions.ByCamera {
dayFolder = filepath.Join(dayFolder, deviceName)
}
case "location":
if GetLocation == nil {
continue
}
wg.Add(1)
go func() {
defer wg.Done()
location := fallbackFromConfig()
locationFromFile, locerr := GetLocation.GetLocation(osPathname)
if locerr == nil {
reverseLocation, reverseerr := ReverseLocation(*locationFromFile)
if reverseerr == nil {
location = reverseLocation
if location == "" || location == " " {
location = fallbackFromConfig()
}
}
}
if sortoptions.ByLocation {
dayFolder = filepath.Join(dayFolder, location)
}
}()
default:
// Not supported
}
}
wg.Wait()
if _, err := os.Stat(dayFolder); os.IsNotExist(err) {
_ = os.MkdirAll(dayFolder, 0o755)
}
return dayFolder
}