comments and code refactoring

This commit is contained in:
2024-04-24 11:52:14 +02:00
parent 01c327d308
commit 00bacf5c41
7 changed files with 39 additions and 20 deletions

View File

@@ -2,6 +2,7 @@ package internal
import "time"
// Used to unmarshall yt-dlp progress
type ProgressTemplate struct {
Percentage string `json:"percentage"`
Speed float32 `json:"speed"`
@@ -9,6 +10,7 @@ type ProgressTemplate struct {
Eta float32 `json:"eta"`
}
// Defines where and how the download needs to be saved
type DownloadOutput struct {
Path string
Filename string
@@ -92,6 +94,7 @@ type SetCookiesRequest struct {
Cookies string `json:"cookies"`
}
// represents a user defined collection of yt-dlp arguments
type CustomTemplate struct {
Id string `json:"id"`
Name string `json:"name"`

View File

@@ -168,7 +168,7 @@ func (p *Process) Start() {
p.Logger.Info("progress",
slog.String("id", p.getShortId()),
slog.String("url", p.Url),
slog.String("percentege", progress.Percentage),
slog.String("percentage", progress.Percentage),
)
})
}()

View File

@@ -8,6 +8,15 @@ import (
"time"
)
/*
File base logger with log-rotate capabilities.
The rotate process must be initiated from an external goroutine.
After rotation the previous logs file are compressed with gzip algorithm.
The rotated log follows this naming: [filename].UTC time.gz
*/
// implements io.Writer interface
type LogRotateWriter struct {
mu sync.Mutex

View File

@@ -6,6 +6,17 @@ import (
"github.com/reactivex/rxgo/v2"
)
/*
Logger implementation using the observable pattern.
Implements io.Writer interface.
The observable is an event source which drops everythigng unless there's
a subscriber connected.
The observer implementatios are a http ServerSentEvents handler and a
websocket one in handler.go
*/
var (
logsChan = make(chan rxgo.Item, 100)
logsObservable = rxgo.

View File

@@ -26,10 +26,12 @@ func DirectoryTree() (*[]string, error) {
children []Node
}
rootPath := config.Instance().DownloadPath
var (
rootPath = config.Instance().DownloadPath
stack := internal.NewStack[Node]()
flattened := make([]string, 0)
stack = internal.NewStack[Node]()
flattened = make([]string, 0)
)
stack.Push(Node{path: rootPath})
@@ -37,14 +39,16 @@ func DirectoryTree() (*[]string, error) {
for stack.IsNotEmpty() {
current := stack.Pop().Value
children, err := os.ReadDir(current.path)
if err != nil {
return nil, err
}
for _, entry := range children {
childPath := filepath.Join(current.path, entry.Name())
childNode := Node{path: childPath}
var (
childPath = filepath.Join(current.path, entry.Name())
childNode = Node{path: childPath}
)
if entry.IsDir() {
current.children = append(current.children, childNode)
stack.Push(childNode)