1
0

Working Index handler.

This commit is contained in:
Alexander Andreev 2022-06-27 23:37:12 +04:00
parent 5f2b69ee3c
commit ef920126c3
Signed by: Arav
GPG Key ID: 0388CC8FAA51063F

View File

@ -2,8 +2,13 @@ package handlers
import ( import (
"dwelling-files/pkg/files" "dwelling-files/pkg/files"
"dwelling-files/pkg/server"
"dwelling-files/pkg/utils"
"dwelling-files/web" "dwelling-files/web"
"log"
"net/http" "net/http"
"github.com/julienschmidt/httprouter"
) )
type IndexData struct { type IndexData struct {
@ -34,10 +39,15 @@ func (FilesHandlers) Robots(w http.ResponseWriter, r *http.Request) {
} }
func (h *FilesHandlers) Index(w http.ResponseWriter, r *http.Request) { func (h *FilesHandlers) Index(w http.ResponseWriter, r *http.Request) {
currentPath := "" path := httprouter.CleanPath(server.GetURLParam(r, "filepath"))
var totalFiles int64 = 0
var totalFilesSize int64 = 0
var totalDirectories int64 = 0
web.Index(r.Host, currentPath, totalFiles, totalFilesSize, totalDirectories, nil, r, w) currentPath := files.CurrentPath(path)
entries, stats, err := files.ScanDirectory(h.directoryPath+path, path)
if err != nil {
log.Println(err)
return
}
web.Index(utils.MainSite(r.Host), currentPath, &stats, &entries, r, w)
} }