Add partial mimetype detection for library file listings
This commit is contained in:
@@ -7,6 +7,8 @@ import (
|
||||
"opal/internal/config"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"github.com/gabriel-vasile/mimetype"
|
||||
)
|
||||
|
||||
func RegisterLibraryEndpoints() {
|
||||
@@ -96,12 +98,29 @@ func EndpointLibraryList(w http.ResponseWriter, r *http.Request) {
|
||||
for _, directoryEntry := range directoryListing {
|
||||
var entry LibraryListEntry
|
||||
|
||||
fmt.Println(directoryEntry.Name())
|
||||
if directoryEntry.IsDir() {
|
||||
entry.Name = directoryEntry.Name()
|
||||
entry.Type = "directory"
|
||||
}
|
||||
|
||||
//TODO: update to use opal.cfg files to determine if movie or show
|
||||
if directoryEntry.Type().IsRegular() {
|
||||
//TODO: formatted string?
|
||||
filePath := ret.LibraryInfo.Path + "/" + path + "/" + directoryEntry.Name()
|
||||
mtype, err := mimetype.DetectFile(filePath)
|
||||
if err != nil {
|
||||
http.Error(w, "Internal server error", http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
entry.Name = directoryEntry.Name()
|
||||
if strings.HasPrefix(mtype.String(), "video/") {
|
||||
entry.Type = "video"
|
||||
} else {
|
||||
entry.Type = "file"
|
||||
}
|
||||
}
|
||||
|
||||
ret.Listing = append(ret.Listing, entry)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user