{{.Content}}
diff --git a/file_display.go b/file_display.go index 99d5421..8886bfd 100644 --- a/file_display.go +++ b/file_display.go @@ -47,8 +47,10 @@ func DisplayFile(app *Application, file string, w http.ResponseWriter) { tmpl = template.Must(template.ParseFS(filesTemplate, "templates/files.html")) } - fileStat, _ := os.Stat("." + file) - fileContent, _ := os.ReadFile("." + file) + realPath := filepath.Join(app.filesDir, filepath.Base(file)) + + fileStat, _ := os.Stat("./" + realPath) + fileContent, _ := os.ReadFile("./" + realPath) fileInfo := FileInfo{ Name: file, diff --git a/handlers.go b/handlers.go index 9aa7358..4ff3f17 100644 --- a/handlers.go +++ b/handlers.go @@ -81,15 +81,16 @@ func (app *Application) fileListingHandler(w http.ResponseWriter, r *http.Reques } func (app *Application) fileHandler(w http.ResponseWriter, r *http.Request) { - path := fmt.Sprintf(".%s", filepath.Clean(r.URL.Path)) + path := fmt.Sprintf("%s", filepath.Base(r.URL.Path)) + realPath := filepath.Join(app.filesDir, path) - if !filepath.IsLocal(path) { + if !filepath.IsLocal(realPath) { http.Error(w, "Wrong url", http.StatusBadRequest) return } - if fileInfo, err := os.Stat(path); err == nil && !fileInfo.IsDir() { - http.ServeFile(w, r, path) + if fileInfo, err := os.Stat(realPath); err == nil && !fileInfo.IsDir() { + http.ServeFile(w, r, realPath) return } } @@ -106,16 +107,16 @@ func (app *Application) indexHandler(w http.ResponseWriter, r *http.Request) { return } - name := filepath.Clean(r.URL.Path) - path := filepath.Join(app.filesDir, name) + name := filepath.Base(r.URL.Path) + realPath := filepath.Join(app.filesDir, name) - if !filepath.IsLocal(path) { + if !filepath.IsLocal(realPath) { http.Error(w, "Wrong url", http.StatusBadRequest) return } - if fileInfo, err := os.Stat(path); err == nil && !fileInfo.IsDir() { - DisplayFile(app, "/"+path, w) + if fileInfo, err := os.Stat(realPath); err == nil && !fileInfo.IsDir() { + DisplayFile(app, filepath.Join("/raw", name), w) return } diff --git a/templates/files.html b/templates/files.html index 0ef66a0..50f4dbf 100644 --- a/templates/files.html +++ b/templates/files.html @@ -133,6 +133,10 @@ padding: 10px; } + header { + display: flex; + } + .content { flex-grow: 1; display: flex; @@ -193,14 +197,31 @@ } a { - color: #0288d1; + color: #d4d4d4; text-decoration: none; + filter: brightness(0.7); + transition: filter 0.2s; + } + + a:hover { + filter: brightness(1) + } + + .path { + position: relative; + margin: 0 auto; + left: -1.85%; }
-{{.Content}}