|
@ -1,9 +1,11 @@ |
|
|
package main |
|
|
package main |
|
|
|
|
|
|
|
|
import ( |
|
|
import ( |
|
|
|
|
|
"embed" |
|
|
_ "embed" |
|
|
_ "embed" |
|
|
"flag" |
|
|
"flag" |
|
|
"fmt" |
|
|
"fmt" |
|
|
|
|
|
"io/fs" |
|
|
"net/http" |
|
|
"net/http" |
|
|
"os" |
|
|
"os" |
|
|
"strconv" |
|
|
"strconv" |
|
@ -13,6 +15,9 @@ import ( |
|
|
"ytdlp-viewer/PageHandlers" |
|
|
"ytdlp-viewer/PageHandlers" |
|
|
) |
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
//go:embed PageHandlers/static
|
|
|
|
|
|
var staticEmbedFS embed.FS |
|
|
|
|
|
|
|
|
func main() { |
|
|
func main() { |
|
|
var path string |
|
|
var path string |
|
|
flag.StringVar(&path, "path", "./", "the full path to the ytdlp archive") |
|
|
flag.StringVar(&path, "path", "./", "the full path to the ytdlp archive") |
|
@ -64,13 +69,17 @@ func main() { |
|
|
fmt.Println(time.Now().String(),request.URL) |
|
|
fmt.Println(time.Now().String(),request.URL) |
|
|
PageHandlers.View(writer, request, &FL, path) |
|
|
PageHandlers.View(writer, request, &FL, path) |
|
|
}) |
|
|
}) |
|
|
http.HandleFunc("/static", func(writer http.ResponseWriter, request *http.Request) { |
|
|
|
|
|
fmt.Println(time.Now().String(),request.URL) |
|
|
subFS, err := fs.Sub(staticEmbedFS, "PageHandlers/static") |
|
|
PageHandlers.Static(writer, request) |
|
|
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)))) |
|
|
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 { |
|
|
if err != nil { |
|
|
fmt.Println(err) |
|
|
fmt.Println(err) |
|
|
os.Exit(1) |
|
|
os.Exit(1) |
|
|