Admin page: show actual file presence dot per row
This commit is contained in:
@@ -2,6 +2,7 @@ package web
|
||||
|
||||
import (
|
||||
"ResendIt/internal/file"
|
||||
"os"
|
||||
"strconv"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
@@ -70,10 +71,35 @@ func (h *Handler) AdminPage(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
// Only check files on the current page.
|
||||
// Status meanings:
|
||||
// - green: file exists on disk
|
||||
// - red: file missing
|
||||
// - rainbow: stat error (something unexpected)
|
||||
type AdminFileView struct {
|
||||
file.FileRecord
|
||||
ActualStatus string
|
||||
}
|
||||
|
||||
adminFiles := make([]AdminFileView, 0, len(files))
|
||||
for _, f := range files {
|
||||
status := "red"
|
||||
if f.Path != "" {
|
||||
if _, err := os.Stat(f.Path); err == nil {
|
||||
status = "green"
|
||||
} else if os.IsNotExist(err) {
|
||||
status = "red"
|
||||
} else {
|
||||
status = "rainbow"
|
||||
}
|
||||
}
|
||||
adminFiles = append(adminFiles, AdminFileView{FileRecord: f, ActualStatus: status})
|
||||
}
|
||||
|
||||
totalPages := (totalCount + limit - 1) / limit
|
||||
|
||||
c.HTML(200, "admin.html", gin.H{
|
||||
"Files": files,
|
||||
"Files": adminFiles,
|
||||
"Page": page,
|
||||
"TotalPages": totalPages,
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user