diff --git a/main.go b/main.go index 56cc239..08a1cd8 100644 --- a/main.go +++ b/main.go @@ -1,9 +1,11 @@ package main import ( + "embed" _ "embed" "flag" "fmt" + "io/fs" "net/http" "os" "strconv" @@ -13,6 +15,9 @@ import ( "ytdlp-viewer/PageHandlers" ) +//go:embed PageHandlers/static +var staticEmbedFS embed.FS + func main() { var path string flag.StringVar(&path, "path", "./", "the full path to the ytdlp archive") @@ -64,13 +69,17 @@ func main() { fmt.Println(time.Now().String(),request.URL) PageHandlers.View(writer, request, &FL, path) }) - http.HandleFunc("/static", func(writer http.ResponseWriter, request *http.Request) { - fmt.Println(time.Now().String(),request.URL) - PageHandlers.Static(writer, request) - }) + + subFS, err := fs.Sub(staticEmbedFS, "PageHandlers/static") + if err != nil { + fmt.Println(err) + os.Exit(1) + } + http.Handle("/static/", http.StripPrefix("/static/", http.FileServer(http.FS(subFS)))) + http.Handle("/videos/", http.StripPrefix("/videos/", http.FileServer(http.Dir(path)))) - err := http.ListenAndServe(":" + strconv.Itoa(port), nil) + err = http.ListenAndServe(":" + strconv.Itoa(port), nil) if err != nil { fmt.Println(err) os.Exit(1)