feat: create new file page with improved UI, combine upload and download functionality
This commit is contained in:
38
handler/file/file.go
Normal file
38
handler/file/file.go
Normal file
@ -0,0 +1,38 @@
|
||||
package fileHandler
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/fossyy/filekeeper/app"
|
||||
"github.com/fossyy/filekeeper/types"
|
||||
"github.com/fossyy/filekeeper/utils"
|
||||
fileView "github.com/fossyy/filekeeper/view/client/file"
|
||||
"net/http"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
func GET(w http.ResponseWriter, r *http.Request) {
|
||||
userSession := r.Context().Value("user").(types.User)
|
||||
files, err := app.Server.Database.GetFiles(userSession.UserID.String())
|
||||
if err != nil {
|
||||
fmt.Println(err.Error())
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
var filesData []types.FileData
|
||||
for i := 0; i < len(files); i++ {
|
||||
filesData = append(filesData, types.FileData{
|
||||
ID: files[i].ID.String(),
|
||||
Name: files[i].Name,
|
||||
Size: utils.ConvertFileSize(files[i].Size),
|
||||
Downloaded: strconv.FormatUint(files[i].Downloaded, 10),
|
||||
})
|
||||
}
|
||||
|
||||
component := fileView.Main("File Dashboard", filesData, userSession)
|
||||
err = component.Render(r.Context(), w)
|
||||
if err != nil {
|
||||
fmt.Println(err.Error())
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user