change route vlc
This commit is contained in:
parent
111669084a
commit
93361d5469
@ -14,6 +14,7 @@ import (
|
||||
"github.com/gorilla/mux"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type spaHandler struct {
|
||||
staticPath string
|
||||
indexPath string
|
||||
@ -35,14 +36,38 @@ func RoutesPublic(r *mux.Router, bd *gorm.DB) {
|
||||
r.HandleFunc("/api/login", login.LoginHandler(bd)).Methods("POST")
|
||||
r.HandleFunc("/api/scan/{id}", library.ScanFolder(bd)).Methods("GET")
|
||||
r.HandleFunc("/api/download/stream", renders.HandleJobsStream(bd))
|
||||
r.HandleFunc("/playlist.m3u", func(w http.ResponseWriter, r *http.Request) {
|
||||
uploadDir := "/app/upload"
|
||||
|
||||
w.Header().Set("Content-Type", "audio/x-mpegurl")
|
||||
fmt.Fprintln(w, "#EXTM3U")
|
||||
|
||||
err := filepath.Walk(uploadDir, func(path string, info os.FileInfo, err error) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if info.IsDir() {
|
||||
return nil
|
||||
}
|
||||
// On construit l'URL HTTP complète
|
||||
relPath, _ := filepath.Rel(uploadDir, path)
|
||||
// Important : remplacer \ par / pour Windows
|
||||
relPath = filepath.ToSlash(relPath)
|
||||
fileURL := fmt.Sprintf("http://%s:4000/upload/%s", getLocalIP(), relPath)
|
||||
fmt.Fprintln(w, fileURL)
|
||||
return nil
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
http.Error(w, "Erreur lors de la génération de la playlist", http.StatusInternalServerError)
|
||||
}
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
// Routes protégées
|
||||
func RoutesProtected(r *mux.Router, bd *gorm.DB) {
|
||||
|
||||
|
||||
|
||||
// Ici on place les vues et API qui doivent être protégées
|
||||
r.HandleFunc("/stream", StreamHandler)
|
||||
r.HandleFunc("/dashboard", renders.Dashboard(bd))
|
||||
@ -65,7 +90,6 @@ func RoutesProtected(r *mux.Router, bd *gorm.DB) {
|
||||
r.HandleFunc("/api/download/delete/{id}", renders.HandleDeleteJob(bd)).Methods("DELETE")
|
||||
r.HandleFunc("/api/download/delete-multiple", renders.HandleDeleteMultipleJobs(bd)).Methods("POST")
|
||||
|
||||
|
||||
// API user
|
||||
r.HandleFunc("/api/user/create", users.CreateUser(bd)).Methods("POST")
|
||||
r.HandleFunc("/api/user/update/{id}", users.UpdateUser(bd)).Methods("PUT")
|
||||
@ -84,7 +108,6 @@ func RoutesProtected(r *mux.Router, bd *gorm.DB) {
|
||||
|
||||
//API Scan folder
|
||||
|
||||
|
||||
}
|
||||
func StreamHandler(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Set("Content-Type", "text/event-stream")
|
||||
|
||||
4
main.go
4
main.go
@ -33,8 +33,8 @@ func main() {
|
||||
route.RoutesProtected(protected, bd)
|
||||
//setupPortMappingWithFallback(4000, 4000)
|
||||
// 6.5. Exposer le dossier upload
|
||||
fs := http.StripPrefix("/upload/", http.FileServer(http.Dir("/app/upload")))
|
||||
r.PathPrefix("/upload/").Handler(fs)
|
||||
// fs := http.StripPrefix("/upload/", http.FileServer(http.Dir("/app/upload")))
|
||||
// r.PathPrefix("/upload/").Handler(fs)
|
||||
|
||||
// 7. Lancer le serveur sur le port 4000
|
||||
log.Fatal(http.ListenAndServe(":4000", r))
|
||||
|
||||
Loading…
Reference in New Issue
Block a user