up
This commit is contained in:
parent
08b05bd7da
commit
16a484a142
@ -661,21 +661,27 @@ func StreamHandler(w http.ResponseWriter, r *http.Request) {
|
|||||||
renderTemplate(w, "folders", data)
|
renderTemplate(w, "folders", data)
|
||||||
}
|
}
|
||||||
func DetailHandler(w http.ResponseWriter, r *http.Request) {
|
func DetailHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
base := "/app/uploads"
|
base := "/app/uploads"
|
||||||
rel := r.URL.Query().Get("path")
|
rel := r.URL.Query().Get("path")
|
||||||
|
|
||||||
// Nettoyage : retirer un éventuel slash au début
|
// On sécurise : supprime les éventuels chemins relatifs
|
||||||
rel = strings.TrimPrefix(rel, "/")
|
rel = filepath.Clean("/" + rel) // ça supprime .. etc.
|
||||||
|
rel = strings.TrimPrefix(rel, "/")
|
||||||
|
|
||||||
absPath := filepath.Join(base, rel)
|
absPath := filepath.Join(base, rel)
|
||||||
fmt.Println("PATH demandé:", rel)
|
|
||||||
fmt.Println("Chemin complet:", filepath.Join(base, rel))
|
info, err := os.Stat(absPath)
|
||||||
|
if err != nil {
|
||||||
|
http.NotFound(w, r)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Protection : vérifier qu'on reste bien dans base
|
||||||
|
if !strings.HasPrefix(absPath, base) {
|
||||||
|
http.NotFound(w, r)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
info, err := os.Stat(absPath)
|
|
||||||
if err != nil {
|
|
||||||
http.NotFound(w, r)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
entry := Entry{
|
entry := Entry{
|
||||||
Name: info.Name(),
|
Name: info.Name(),
|
||||||
Path: rel,
|
Path: rel,
|
||||||
@ -683,7 +689,7 @@ func DetailHandler(w http.ResponseWriter, r *http.Request) {
|
|||||||
ModTime: info.ModTime(),
|
ModTime: info.ModTime(),
|
||||||
Size: info.Size(),
|
Size: info.Size(),
|
||||||
}
|
}
|
||||||
// Toujours partial HTMX
|
|
||||||
renderPartial(w, "_file_detail", map[string]interface{}{
|
renderPartial(w, "_file_detail", map[string]interface{}{
|
||||||
"Entry": entry,
|
"Entry": entry,
|
||||||
})
|
})
|
||||||
@ -694,6 +700,7 @@ func DetailHandler(w http.ResponseWriter, r *http.Request) {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
func renderPartial(w http.ResponseWriter, templ string, data map[string]interface{}) {
|
func renderPartial(w http.ResponseWriter, templ string, data map[string]interface{}) {
|
||||||
// Exécute directement le define `<templ>.pages.tmpl`
|
// Exécute directement le define `<templ>.pages.tmpl`
|
||||||
if err := templates.ExecuteTemplate(w, templ+".pages.tmpl", data); err != nil {
|
if err := templates.ExecuteTemplate(w, templ+".pages.tmpl", data); err != nil {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user