Files
Marco Piovanello 143cc28a97 Server v4 (#370)
* refactoring-1

introduced pipelines and abstracted download process.go in Downloader interface

* migrated to boltdb from sqlite + session files

* refactoring: config struct & pipelines

* added js runtime for yt-dlp

* updated dockerfile

* added external js runtime, metadata scraping refactor

* updated Dockerfile

* fixed env propagation in docker

* updated package name to v4

* updated readme and cd
2026-06-29 19:01:53 +02:00

61 lines
1.4 KiB
Go

package sys
import (
"os"
"path/filepath"
"github.com/marcopiovanello/yt-dlp-web-ui/v4/server/config"
"github.com/marcopiovanello/yt-dlp-web-ui/v4/server/internal"
"golang.org/x/sys/unix"
)
// package containing fs related operation (unix only)
// FreeSpace gets the available Bytes writable to download directory
func FreeSpace() (uint64, error) {
var stat unix.Statfs_t
unix.Statfs(config.Instance().Paths.DownloadPath, &stat)
return (stat.Bavail * uint64(stat.Bsize)), nil
}
// Build a directory tree started from the specified path using DFS.
// Then return the flattened tree represented as a list.
func DirectoryTree() (*[]string, error) {
type Node struct {
path string
children []Node
}
var (
rootPath = config.Instance().Paths.DownloadPath
stack = internal.NewStack[Node]()
flattened = make([]string, 0)
)
stack.Push(Node{path: rootPath})
flattened = append(flattened, rootPath)
for stack.IsNotEmpty() {
current := stack.Pop().Value
children, err := os.ReadDir(current.path)
if err != nil {
return nil, err
}
for _, entry := range children {
var (
childPath = filepath.Join(current.path, entry.Name())
childNode = Node{path: childPath}
)
if entry.IsDir() {
current.children = append(current.children, childNode)
stack.Push(childNode)
flattened = append(flattened, childNode.path)
}
}
}
return &flattened, nil
}