Add partial mimetype detection for library file listings
This commit is contained in:
5
go.mod
5
go.mod
@@ -2,4 +2,7 @@ module opal
|
|||||||
|
|
||||||
go 1.25.3
|
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
|
||||||
|
)
|
||||||
|
|||||||
2
go.sum
2
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 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
|
||||||
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
||||||
|
|||||||
@@ -7,6 +7,8 @@ import (
|
|||||||
"opal/internal/config"
|
"opal/internal/config"
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/gabriel-vasile/mimetype"
|
||||||
)
|
)
|
||||||
|
|
||||||
func RegisterLibraryEndpoints() {
|
func RegisterLibraryEndpoints() {
|
||||||
@@ -96,12 +98,29 @@ func EndpointLibraryList(w http.ResponseWriter, r *http.Request) {
|
|||||||
for _, directoryEntry := range directoryListing {
|
for _, directoryEntry := range directoryListing {
|
||||||
var entry LibraryListEntry
|
var entry LibraryListEntry
|
||||||
|
|
||||||
fmt.Println(directoryEntry.Name())
|
|
||||||
if directoryEntry.IsDir() {
|
if directoryEntry.IsDir() {
|
||||||
entry.Name = directoryEntry.Name()
|
entry.Name = directoryEntry.Name()
|
||||||
entry.Type = "directory"
|
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)
|
ret.Listing = append(ret.Listing, entry)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
2
todo.txt
2
todo.txt
@@ -1,5 +1,7 @@
|
|||||||
TODO: LITERALLY HALF THE API ISNT EVEN AWARE ABOUT AUTHENTICATION, FIX BEFORE RELEASE
|
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
|
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
|
list available files, movies, videos, shows, and folders, for future release, currently just glorified file server
|
||||||
|
|||||||
Reference in New Issue
Block a user