Add disk space to status
This commit is contained in:
@@ -56,8 +56,8 @@ Build and push this container to ghcr
|
|||||||
- [x] Environment variable to control whether "Secure" flag set on cookie
|
- [x] Environment variable to control whether "Secure" flag set on cookie
|
||||||
- [x] Allow custom FPS for video transcode
|
- [x] Allow custom FPS for video transcode
|
||||||
- [ ] Provide an about page
|
- [ ] Provide an about page
|
||||||
- `ffmpeg` version
|
- [x] `ffmpeg` version
|
||||||
- `yt-dlp` version
|
- [x] `yt-dlp` version
|
||||||
- disk space
|
- disk space
|
||||||
- [ ] skip buttons for audio player
|
- [ ] skip buttons for audio player
|
||||||
- [ ] Track progress via video URL rather than ID
|
- [ ] Track progress via video URL rather than ID
|
||||||
|
@@ -1,14 +1,50 @@
|
|||||||
package handlers
|
package handlers
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
|
||||||
"github.com/labstack/echo/v4"
|
"github.com/labstack/echo/v4"
|
||||||
|
"golang.org/x/sys/unix"
|
||||||
|
|
||||||
|
"ytdlp-site/config"
|
||||||
"ytdlp-site/ffmpeg"
|
"ytdlp-site/ffmpeg"
|
||||||
"ytdlp-site/ytdlp"
|
"ytdlp-site/ytdlp"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// GetFreeSpace returns the free space in bytes for the filesystem containing the given directory
|
||||||
|
func getFreeSpace(dir string) (uint64, error) {
|
||||||
|
var stat unix.Statfs_t
|
||||||
|
err := unix.Statfs(dir, &stat)
|
||||||
|
if err != nil {
|
||||||
|
return 0, fmt.Errorf("error getting filesystem stats: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Calculate free space
|
||||||
|
freeSpace := stat.Bavail * uint64(stat.Bsize)
|
||||||
|
return freeSpace, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetDirectorySize calculates the total size of a directory in bytes
|
||||||
|
func getDirectorySize(dir string) (int64, error) {
|
||||||
|
var size int64
|
||||||
|
err := filepath.Walk(dir, func(_ string, info os.FileInfo, err error) error {
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if !info.IsDir() {
|
||||||
|
size += info.Size()
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return 0, fmt.Errorf("error walking directory: %v", err)
|
||||||
|
}
|
||||||
|
return size, nil
|
||||||
|
}
|
||||||
|
|
||||||
func StatusGet(c echo.Context) error {
|
func StatusGet(c echo.Context) error {
|
||||||
|
|
||||||
ytdlpStdout, _, err := ytdlp.Run("--version")
|
ytdlpStdout, _, err := ytdlp.Run("--version")
|
||||||
@@ -20,9 +56,23 @@ func StatusGet(c echo.Context) error {
|
|||||||
log.Errorln(err)
|
log.Errorln(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
free, err := getFreeSpace(config.GetDataDir())
|
||||||
|
if err != nil {
|
||||||
|
log.Errorln(err)
|
||||||
|
}
|
||||||
|
used, err := getDirectorySize(config.GetDataDir())
|
||||||
|
if err != nil {
|
||||||
|
log.Errorln(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
freeMiB := float64(free) / 1024 / 1024
|
||||||
|
usedMiB := float64(used) / 1024 / 1024
|
||||||
|
|
||||||
return c.Render(http.StatusOK, "status.html", map[string]interface{}{
|
return c.Render(http.StatusOK, "status.html", map[string]interface{}{
|
||||||
"ytdlp": string(ytdlpStdout),
|
"ytdlp": string(ytdlpStdout),
|
||||||
"ffmpeg": string(ffmpegStdout),
|
"ffmpeg": string(ffmpegStdout),
|
||||||
|
"free": fmt.Sprintf("%.2f", freeMiB),
|
||||||
|
"used": fmt.Sprintf("%.2f", usedMiB),
|
||||||
"Footer": MakeFooter(),
|
"Footer": MakeFooter(),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@@ -28,6 +28,10 @@
|
|||||||
{{.ffmpeg}}
|
{{.ffmpeg}}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="disk-space card">
|
||||||
|
<h2>Disk</h2>
|
||||||
|
{{.used}} MiB ({{.free}} MiB remaning)
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{{template "footer" .}}
|
{{template "footer" .}}
|
||||||
</body>
|
</body>
|
||||||
|
Reference in New Issue
Block a user