diff options
author | Christian Pointner <equinox@helsinki.at> | 2017-01-27 23:28:29 (GMT) |
---|---|---|
committer | Christian Pointner <equinox@helsinki.at> | 2017-01-27 23:28:29 (GMT) |
commit | 001a2fdead2ffb499e78dece93d7bbd027c3765c (patch) | |
tree | b603835af452d28600f1613c03a914c3b62d8913 /src/file-hasher | |
parent | b79d589aad52792560eb8d42946cb96872973da2 (diff) |
make valid extensions configurable as well
Diffstat (limited to 'src/file-hasher')
-rw-r--r-- | src/file-hasher/main.go | 7 | ||||
-rw-r--r-- | src/file-hasher/walker.go | 24 |
2 files changed, 17 insertions, 14 deletions
diff --git a/src/file-hasher/main.go b/src/file-hasher/main.go index c7718ee..7100496 100644 --- a/src/file-hasher/main.go +++ b/src/file-hasher/main.go @@ -26,6 +26,7 @@ import ( "log" "os" "os/signal" + "strings" "syscall" "time" ) @@ -37,6 +38,7 @@ type Request struct { Directories []string `json:"dir"` M3UPlaylists []string `json:"m3u"` } `json:"src"` + ValidExtensions []string `json:"valid-ext"` } func main() { @@ -47,6 +49,11 @@ func main() { stdlog.Fatalf("Error decoding request: %v", err) } + validExtensions = req.ValidExtensions + for i, ext := range validExtensions { + validExtensions[i] = strings.ToLower(ext) + } + C := make(chan os.Signal, 1) signal.Notify(C, os.Interrupt, syscall.SIGHUP, syscall.SIGQUIT, syscall.SIGTERM) diff --git a/src/file-hasher/walker.go b/src/file-hasher/walker.go index cc543a2..602f974 100644 --- a/src/file-hasher/walker.go +++ b/src/file-hasher/walker.go @@ -26,23 +26,19 @@ import ( "strings" ) +var validExtensions []string + func checkFileExt(path string) bool { - switch strings.ToLower(filepath.Ext(path)) { - case ".flac": - return true - case ".ogg": - return true - case ".wav": - return true - case ".mp3": - return true - case ".aac": - return true - case ".mp4": - return true - case ".m4a": + if len(validExtensions) == 0 { return true } + + ext := strings.ToLower(filepath.Ext(path)) + for _, e := range validExtensions { + if ext == "."+e { + return true + } + } return false } |