Refactor file type functions
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"mime"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"golang.org/x/exp/slices"
|
||||
)
|
||||
|
||||
var excludeAudioType = []string{
|
||||
"audio/x-mpegurl",
|
||||
"audio/x-scpls",
|
||||
}
|
||||
|
||||
func IsAudioFile(filePath string) bool {
|
||||
extension := filepath.Ext(filePath)
|
||||
mimeType := mime.TypeByExtension(extension)
|
||||
return !slices.Contains(excludeAudioType, mimeType) && strings.HasPrefix(mimeType, "audio/")
|
||||
}
|
||||
|
||||
func IsImageFile(filePath string) bool {
|
||||
extension := filepath.Ext(filePath)
|
||||
return strings.HasPrefix(mime.TypeByExtension(extension), "image/")
|
||||
}
|
||||
|
||||
func IsValidPlaylist(filePath string) bool {
|
||||
extension := strings.ToLower(filepath.Ext(filePath))
|
||||
return extension == ".m3u" || extension == ".m3u8" || extension == ".nsp"
|
||||
}
|
||||
Reference in New Issue
Block a user