Based on QuantumNous/new-api v1.0.0-rc.36 (shallow history squashed). - CNY quota display mode: RMB-denominated top-up and crediting across Epay/Waffo channels - New CheckinButton in both authenticated and public headers (Turnstile supported) - New /subscribe page with public plan snapshot, Alipay/balance payment, auto group upgrade/reset - New /docs 12-section beginner guide with anchor navigation - New home PromoBanner linking to /docs; i18n synced (en/zh/zh-TW/fr/ja/ru/vi) - README: document custom features, live demo https://ai.88531.cn
38 lines
769 B
Go
38 lines
769 B
Go
//go:build !windows
|
|
|
|
package common
|
|
|
|
import (
|
|
"os"
|
|
|
|
"golang.org/x/sys/unix"
|
|
)
|
|
|
|
// GetDiskSpaceInfo 获取缓存目录所在磁盘的空间信息 (Unix/Linux/macOS)
|
|
func GetDiskSpaceInfo() DiskSpaceInfo {
|
|
cachePath := GetDiskCachePath()
|
|
if cachePath == "" {
|
|
cachePath = os.TempDir()
|
|
}
|
|
|
|
info := DiskSpaceInfo{}
|
|
|
|
var stat unix.Statfs_t
|
|
err := unix.Statfs(cachePath, &stat)
|
|
if err != nil {
|
|
return info
|
|
}
|
|
|
|
// 计算磁盘空间 (显式转换以兼容 FreeBSD,其字段类型为 int64)
|
|
bsize := uint64(stat.Bsize)
|
|
info.Total = uint64(stat.Blocks) * bsize
|
|
info.Free = uint64(stat.Bavail) * bsize
|
|
info.Used = info.Total - uint64(stat.Bfree)*bsize
|
|
|
|
if info.Total > 0 {
|
|
info.UsedPercent = float64(info.Used) / float64(info.Total) * 100
|
|
}
|
|
|
|
return info
|
|
}
|