Add partial mimetype detection for library file listings

This commit is contained in:
the-m-monk
2025-12-29 22:47:53 +10:00
parent c25bff7203
commit 32da27c404
4 changed files with 28 additions and 2 deletions

View File

@@ -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)
}