2026-05-25 15:36:49 +03:00
|
|
|
package handlers
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"net/http"
|
|
|
|
|
|
2026-05-30 15:42:35 +03:00
|
|
|
"warpbox.dev/backend/libs/services"
|
2026-05-25 15:36:49 +03:00
|
|
|
"warpbox.dev/backend/libs/web"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
type homeData struct {
|
|
|
|
|
MaxUploadSize string
|
2026-05-30 15:42:35 +03:00
|
|
|
Collections []collectionView
|
|
|
|
|
IsAdmin bool
|
2026-05-25 15:36:49 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (a *App) Home(w http.ResponseWriter, r *http.Request) {
|
2026-05-30 15:42:35 +03:00
|
|
|
currentUser := a.currentPublicUser(r)
|
|
|
|
|
var collections []collectionView
|
|
|
|
|
var isAdmin bool
|
|
|
|
|
if user, ok := a.currentUser(r); ok {
|
|
|
|
|
isAdmin = user.Role == services.UserRoleAdmin
|
|
|
|
|
userCollections, err := a.authService.ListCollections(user.ID)
|
|
|
|
|
if err == nil {
|
|
|
|
|
collections = make([]collectionView, 0, len(userCollections))
|
|
|
|
|
for _, collection := range userCollections {
|
|
|
|
|
collections = append(collections, collectionView{ID: collection.ID, Name: collection.Name})
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2026-05-25 16:52:57 +03:00
|
|
|
a.renderer.Render(w, http.StatusOK, "home.html", web.PageData{
|
2026-05-25 15:36:49 +03:00
|
|
|
Title: "Upload your files",
|
|
|
|
|
Description: "Upload and share files through a self-hosted Warpbox instance.",
|
2026-05-30 15:42:35 +03:00
|
|
|
CurrentUser: currentUser,
|
2026-05-25 15:36:49 +03:00
|
|
|
Data: homeData{
|
|
|
|
|
MaxUploadSize: a.uploadService.MaxUploadSizeLabel(),
|
2026-05-30 15:42:35 +03:00
|
|
|
Collections: collections,
|
|
|
|
|
IsAdmin: isAdmin,
|
2026-05-25 15:36:49 +03:00
|
|
|
},
|
|
|
|
|
})
|
|
|
|
|
}
|