feat(backend): add disk usage statistics endpoint and utility for converting human-readable file sizes

This commit is contained in:
keven1024
2025-06-01 18:34:40 +08:00
parent ed9d56c6d9
commit 3895234d96
4 changed files with 11 additions and 0 deletions

View File

@@ -6,6 +6,7 @@ require (
dario.cat/mergo v1.0.1 // indirect
github.com/cespare/xxhash/v2 v2.3.0 // indirect
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
github.com/docker/go-units v0.5.0 // indirect
github.com/fsnotify/fsnotify v1.8.0 // indirect
github.com/go-viper/mapstructure/v2 v2.2.1 // indirect
github.com/gofrs/uuid v4.0.0+incompatible // indirect

View File

@@ -8,6 +8,8 @@ github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSs
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f h1:lO4WD4F/rVNCu3HqELle0jiPLLBs70cWOduZpkS1E78=
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f/go.mod h1:cuUVRXasLTGF7a8hSLbxyZXjz+1KgoB3wDUb6vlszIc=
github.com/docker/go-units v0.5.0 h1:69rxXcBk27SvSaaxTtLh/8llcHD8vYHT7WSdRZ/jvr4=
github.com/docker/go-units v0.5.0/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDDbaIK4Dk=
github.com/fsnotify/fsnotify v1.8.0 h1:dAwr6QBTBZIkG8roQaJjGof0pp0EeF+tNV7YBP3F/8M=
github.com/fsnotify/fsnotify v1.8.0/go.mod h1:8jBTzvmWwFyi3Pb8djgCCO5IBqzKJ/Jwo8TRcHyHii0=
github.com/go-viper/mapstructure/v2 v2.2.1 h1:ZAaOCxANMuZx5RCeg0mBdEZk7DZasvvZIxtHqx8aGss=

View File

@@ -7,6 +7,8 @@ import (
"io"
"os"
"path/filepath"
goUnits "github.com/docker/go-units"
)
func GetFileId(fileHash string, fileSize int64) string {
@@ -45,3 +47,8 @@ func GetUploadDirPath() (string, error) {
}
return uploadPath, nil
}
func GetFileSize(size string) (int64, error) {
s, err := goUnits.FromHumanSize(size)
return s, err
}

View File

@@ -39,5 +39,6 @@ func main() {
e.POST("/image/compress", controllers.GenCompressImage)
e.GET("/image/compress/:id", controllers.GetCompressImage)
e.GET("/stat", controllers.GetStat)
e.Logger.Fatal(e.Start(":1323"))
}