up
This commit is contained in:
parent
08b05bd7da
commit
16a484a142
@ -664,18 +664,24 @@ func DetailHandler(w http.ResponseWriter, r *http.Request) {
|
||||
base := "/app/uploads"
|
||||
rel := r.URL.Query().Get("path")
|
||||
|
||||
// Nettoyage : retirer un éventuel slash au début
|
||||
// On sécurise : supprime les éventuels chemins relatifs
|
||||
rel = filepath.Clean("/" + rel) // ça supprime .. etc.
|
||||
rel = strings.TrimPrefix(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
|
||||
}
|
||||
|
||||
entry := Entry{
|
||||
Name: info.Name(),
|
||||
Path: rel,
|
||||
@ -683,7 +689,7 @@ func DetailHandler(w http.ResponseWriter, r *http.Request) {
|
||||
ModTime: info.ModTime(),
|
||||
Size: info.Size(),
|
||||
}
|
||||
// Toujours partial HTMX
|
||||
|
||||
renderPartial(w, "_file_detail", map[string]interface{}{
|
||||
"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{}) {
|
||||
// Exécute directement le define `<templ>.pages.tmpl`
|
||||
if err := templates.ExecuteTemplate(w, templ+".pages.tmpl", data); err != nil {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user