From 32da27c40445979def974d6ccdcdf08b020f565e Mon Sep 17 00:00:00 2001 From: the-m-monk Date: Mon, 29 Dec 2025 22:47:53 +1000 Subject: [PATCH] Add partial mimetype detection for library file listings --- go.mod | 5 ++++- go.sum | 2 ++ internal/httpserver/api/libraries.go | 21 ++++++++++++++++++++- todo.txt | 2 ++ 4 files changed, 28 insertions(+), 2 deletions(-) diff --git a/go.mod b/go.mod index 57b30ae..5b1c431 100644 --- a/go.mod +++ b/go.mod @@ -2,4 +2,7 @@ module opal go 1.25.3 -require github.com/google/uuid v1.6.0 // indirect +require ( + github.com/gabriel-vasile/mimetype v1.4.12 // indirect + github.com/google/uuid v1.6.0 // indirect +) diff --git a/go.sum b/go.sum index 7790d7c..c592a68 100644 --- a/go.sum +++ b/go.sum @@ -1,2 +1,4 @@ +github.com/gabriel-vasile/mimetype v1.4.12 h1:e9hWvmLYvtp846tLHam2o++qitpguFiYCKbn0w9jyqw= +github.com/gabriel-vasile/mimetype v1.4.12/go.mod h1:d+9Oxyo1wTzWdyVUPMmXFvp4F9tea18J8ufA774AB3s= github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= diff --git a/internal/httpserver/api/libraries.go b/internal/httpserver/api/libraries.go index 2cbb50f..92e114c 100644 --- a/internal/httpserver/api/libraries.go +++ b/internal/httpserver/api/libraries.go @@ -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) } diff --git a/todo.txt b/todo.txt index b7830f6..3d8fff9 100644 --- a/todo.txt +++ b/todo.txt @@ -1,5 +1,7 @@ TODO: LITERALLY HALF THE API ISNT EVEN AWARE ABOUT AUTHENTICATION, FIX BEFORE RELEASE +add opal.cfg files to determine if movie or show + video player, use hls, add direct download at somepoint list available files, movies, videos, shows, and folders, for future release, currently just glorified file server