64 lines
1.5 KiB
Go
64 lines
1.5 KiB
Go
package server
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
|
|
"warpbox/lib/boxstore"
|
|
"warpbox/lib/helpers"
|
|
"warpbox/lib/metastore"
|
|
)
|
|
|
|
type adminBoxRow struct {
|
|
ID string
|
|
FileCount int
|
|
TotalSizeLabel string
|
|
CreatedAt string
|
|
ExpiresAt string
|
|
Expired bool
|
|
OneTimeDownload bool
|
|
PasswordProtected bool
|
|
}
|
|
|
|
func (app *App) handleAdminBoxes(ctx *gin.Context) {
|
|
if !app.requireAdminFlag(ctx, func(perms metastore.EffectivePermissions) bool { return perms.AdminBoxesView }) {
|
|
return
|
|
}
|
|
|
|
summaries, err := boxstore.ListBoxSummaries()
|
|
if err != nil {
|
|
ctx.String(http.StatusInternalServerError, "Could not list boxes")
|
|
return
|
|
}
|
|
|
|
rows := make([]adminBoxRow, 0, len(summaries))
|
|
totalSize := int64(0)
|
|
expiredCount := 0
|
|
for _, summary := range summaries {
|
|
totalSize += summary.TotalSize
|
|
if summary.Expired {
|
|
expiredCount++
|
|
}
|
|
rows = append(rows, adminBoxRow{
|
|
ID: summary.ID,
|
|
FileCount: summary.FileCount,
|
|
TotalSizeLabel: summary.TotalSizeLabel,
|
|
CreatedAt: formatAdminTime(summary.CreatedAt),
|
|
ExpiresAt: formatAdminTime(summary.ExpiresAt),
|
|
Expired: summary.Expired,
|
|
OneTimeDownload: summary.OneTimeDownload,
|
|
PasswordProtected: summary.PasswordProtected,
|
|
})
|
|
}
|
|
|
|
ctx.HTML(http.StatusOK, "admin_boxes.html", gin.H{
|
|
"AdminSection": "boxes",
|
|
"CurrentUser": app.currentAdminUsername(ctx),
|
|
"Boxes": rows,
|
|
"TotalBoxes": len(rows),
|
|
"TotalStorage": helpers.FormatBytes(totalSize),
|
|
"ExpiredBoxes": expiredCount,
|
|
})
|
|
}
|