mirror of
https://github.com/keven1024/015.git
synced 2026-05-26 07:08:02 +00:00
feat(backend): implement GetStat function to retrieve file statistics and storage limits
This commit is contained in:
50
backend/internal/controllers/stat.go
Normal file
50
backend/internal/controllers/stat.go
Normal file
@@ -0,0 +1,50 @@
|
||||
package controllers
|
||||
|
||||
import (
|
||||
"backend/internal/models"
|
||||
"backend/internal/utils"
|
||||
"strings"
|
||||
|
||||
"github.com/labstack/echo/v4"
|
||||
"github.com/spf13/cast"
|
||||
)
|
||||
|
||||
func GetStat(c echo.Context) error {
|
||||
keys, err := models.GetRedisFileKeysAll()
|
||||
if err != nil {
|
||||
return utils.HTTPErrorHandler(c, err)
|
||||
}
|
||||
var filesSize int64
|
||||
for _, key := range keys {
|
||||
list := strings.Split(key, "_")
|
||||
if len(list) > 1 {
|
||||
filesSize += cast.ToInt64(list[1])
|
||||
}
|
||||
}
|
||||
queueInspector := utils.GetQueueInspector()
|
||||
queues, err := queueInspector.History("default", 30)
|
||||
if err != nil {
|
||||
return utils.HTTPErrorHandler(c, err)
|
||||
}
|
||||
|
||||
maxStorageSize, err := utils.GetFileSize(utils.GetEnv("MAX_LOCALSTORAGE_SIZE"))
|
||||
if err != nil {
|
||||
return utils.HTTPErrorHandler(c, err)
|
||||
}
|
||||
|
||||
return utils.HTTPSuccessHandler(c, map[string]any{
|
||||
"version": "0.1.0",
|
||||
"total": map[string]any{
|
||||
"file_size": filesSize,
|
||||
"file_num": len(keys),
|
||||
},
|
||||
"limit": map[string]any{
|
||||
"file_size": maxStorageSize,
|
||||
},
|
||||
"admin": map[string]any{
|
||||
"user_name": utils.GetEnv("ADMIN_NAME"),
|
||||
"email": utils.GetEnv("ADMIN_EMAIL"),
|
||||
},
|
||||
"queue": queues,
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user