feat: add registry config, image upload/download, and OCI format support
Backend: - Add registry_address configuration API (GET/POST) - Add tar image upload with OCI and Docker format support - Add image download with streaming optimization - Fix blob download using c.Send (Fiber v3 SendStream bug) - Add registry_address prefix stripping for all OCI v2 endpoints - Add AGENTS.md for project documentation Frontend: - Add settings store with Snackbar notifications - Add image upload dialog with progress bar - Add download state tracking with multi-stage feedback - Replace alert() with MUI Snackbar messages - Display image names without registry_address prefix 🤖 Generated with [Qoder](https://qoder.com)
This commit is contained in:
76
pkg/tool/human.go
Normal file
76
pkg/tool/human.go
Normal file
@@ -0,0 +1,76 @@
|
||||
package tool
|
||||
|
||||
import "fmt"
|
||||
|
||||
const (
|
||||
_ = iota
|
||||
KB = 1 << (10 * iota) // 1 KB = 1024 bytes
|
||||
MB // 1 MB = 1024 KB
|
||||
GB // 1 GB = 1024 MB
|
||||
TB // 1 TB = 1024 GB
|
||||
PB // 1 PB = 1024 TB
|
||||
)
|
||||
|
||||
func HumanDuration(nano int64) string {
|
||||
duration := float64(nano)
|
||||
unit := "ns"
|
||||
if duration >= 1000 {
|
||||
duration /= 1000
|
||||
unit = "us"
|
||||
}
|
||||
|
||||
if duration >= 1000 {
|
||||
duration /= 1000
|
||||
unit = "ms"
|
||||
}
|
||||
|
||||
if duration >= 1000 {
|
||||
duration /= 1000
|
||||
unit = " s"
|
||||
}
|
||||
|
||||
return fmt.Sprintf("%6.2f%s", duration, unit)
|
||||
}
|
||||
|
||||
func HumanSize(size int64) string {
|
||||
|
||||
switch {
|
||||
case size >= PB:
|
||||
return fmt.Sprintf("%.2f PB", float64(size)/PB)
|
||||
case size >= TB:
|
||||
return fmt.Sprintf("%.2f TB", float64(size)/TB)
|
||||
case size >= GB:
|
||||
return fmt.Sprintf("%.2f GB", float64(size)/GB)
|
||||
case size >= MB:
|
||||
return fmt.Sprintf("%.2f MB", float64(size)/MB)
|
||||
case size >= KB:
|
||||
return fmt.Sprintf("%.2f KB", float64(size)/KB)
|
||||
default:
|
||||
return fmt.Sprintf("%d bytes", size)
|
||||
}
|
||||
}
|
||||
|
||||
// BytesToUnit 将字节转换为指定单位
|
||||
func BytesToUnit(bytes int64, unit float64) float64 {
|
||||
return float64(bytes) / unit
|
||||
}
|
||||
|
||||
// BytesToKB 转换为 KB
|
||||
func BytesToKB(bytes int64) float64 {
|
||||
return BytesToUnit(bytes, KB)
|
||||
}
|
||||
|
||||
// BytesToMB 转换为 MB
|
||||
func BytesToMB(bytes int64) float64 {
|
||||
return BytesToUnit(bytes, MB)
|
||||
}
|
||||
|
||||
// BytesToGB 转换为 GB
|
||||
func BytesToGB(bytes int64) float64 {
|
||||
return BytesToUnit(bytes, GB)
|
||||
}
|
||||
|
||||
// BytesToTB 转换为 TB
|
||||
func BytesToTB(bytes int64) float64 {
|
||||
return BytesToUnit(bytes, TB)
|
||||
}
|
||||
Reference in New Issue
Block a user