diff --git a/src/main.go b/src/main.go index 9ee2e54..29689a7 100644 --- a/src/main.go +++ b/src/main.go @@ -2,9 +2,11 @@ package main import ( "fmt" + "html/template" "log" "os" "path/filepath" + "strconv" "github.com/gin-gonic/gin" "golang.org/x/crypto/bcrypt" @@ -31,6 +33,10 @@ func main() { router := gin.Default() router.MaxMultipartMemory = 10 << 30 + router.SetFuncMap(template.FuncMap{ + "add": func(a, b int) int { return a + b }, + "sub": func(a, b int) int { return a - b }, + }) router.LoadHTMLGlob("templates/*") var staticPath = gin.Dir("./static", false) fmt.Printf("Static path: %v\n", staticPath) @@ -49,8 +55,29 @@ func main() { admin.GET("/", func(c *gin.Context) { var files []FileRecord - db.Order("created_at desc").Find(&files) - c.HTML(200, "admin.html", gin.H{"Files": files}) + + // Pagination parameters + perPage := 20 + page := 1 + if p := c.Query("page"); p != "" { + if v, err := strconv.Atoi(p); err == nil && v > 0 { + page = v + } + } + + var total int64 + db.Model(&FileRecord{}).Count(&total) + + totalPages := int((total + int64(perPage) - 1) / int64(perPage)) // ceiling division + + offset := (page - 1) * perPage + db.Order("created_at desc").Limit(perPage).Offset(offset).Find(&files) + + c.HTML(200, "admin.html", gin.H{ + "Files": files, + "Page": page, + "TotalPages": totalPages, + }) }) admin.POST("/delete/:id", func(c *gin.Context) { diff --git a/templates/admin.html b/templates/admin.html index b67467c..441b9ce 100644 --- a/templates/admin.html +++ b/templates/admin.html @@ -17,9 +17,10 @@ .status-deleted { background: #ffcccc; text-decoration: line-through; } .status-no{ background: #ffcccc; } .status-active { background: #ccffcc; } - button { border: 1px solid #000; background: #eee; padding: 2px 8px; cursor: pointer; font-size: 11px; font-weight: bold; } - button:hover { background: #000; color: #fff; } + button, .button { border: 1px solid #000; background: #eee; padding: 2px 8px; cursor: pointer; font-size: 11px; font-weight: bold; text-decoration: none; } + button:hover, .button:hover { background: #000; color: #fff; } .nav-link { font-weight: bold; text-decoration: underline; margin-bottom: 20px; display: inline-block; } + .pagination a { margin: 0 2px; } @@ -27,8 +28,10 @@

System Console

- ← BACK TO UPLOADER - LOGOUT +
+ ← BACK TO UPLOADER + LOGOUT +
@@ -52,14 +55,12 @@ {{.CreatedAt.Format "Jan 02, 2006 15:04"}} {{.ExpiresAt.Format "Jan 02, 2006 15:04"}} + {{.DownloadCount}} - {{.DownloadCount}} - - {{if .DeleteAfterDownload}} - YES + YES {{else}} - NO + NO {{end}} @@ -82,8 +83,19 @@
+
+
+ {{if gt .Page 1}} + ← Prev + {{end}} + {{if lt .Page .TotalPages}} + Next → + {{end}} +
+
+
diff --git a/templates/index.html b/templates/index.html index 2170436..485a86a 100644 --- a/templates/index.html +++ b/templates/index.html @@ -128,7 +128,7 @@ - +