diff --git a/frontend/src/components/DownloadDialog.tsx b/frontend/src/components/DownloadDialog.tsx index 888a38d..106f37a 100644 --- a/frontend/src/components/DownloadDialog.tsx +++ b/frontend/src/components/DownloadDialog.tsx @@ -40,7 +40,7 @@ import { useI18n } from '../hooks/useI18n' import { useRPC } from '../hooks/useRPC' import { CliArguments } from '../lib/argsParser' import type { DLMetadata } from '../types' -import { isValidURL, toFormatArgs } from '../utils' +import { toFormatArgs } from '../utils' import ExtraDownloadOptions from './ExtraDownloadOptions' const Transition = forwardRef(function Transition( @@ -166,7 +166,6 @@ const DownloadDialog: FC = ({ open, onClose, onDownloadStart }) => { file .split('\n') - .filter(u => isValidURL(u)) .forEach(u => sendUrl(u)) } diff --git a/frontend/src/utils.ts b/frontend/src/utils.ts index 2afc0df..dff658d 100644 --- a/frontend/src/utils.ts +++ b/frontend/src/utils.ts @@ -20,17 +20,10 @@ export function validateDomain(url: string): boolean { return urlRegex.test(url) || name === 'localhost' && slugRegex.test(slug) } -export function isValidURL(url: string): boolean { - let urlRegex = /https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()!@:%_\+.~#?&\/\/=]*)/ - return urlRegex.test(url) -} - -export function ellipsis(str: string, lim: number): string { - if (str) { - return str.length > lim ? `${str.substring(0, lim)}...` : str - } - return '' -} +export const ellipsis = (str: string, lim: number) => + str.length > lim + ? `${str.substring(0, lim)}...` + : str export function toFormatArgs(codes: string[]): string { if (codes.length > 1) { diff --git a/server/internal/common.go b/server/internal/common.go index 2d0b91e..e019efe 100644 --- a/server/internal/common.go +++ b/server/internal/common.go @@ -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"` diff --git a/server/internal/process.go b/server/internal/process.go index 1abbc7a..54b65db 100644 --- a/server/internal/process.go +++ b/server/internal/process.go @@ -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), ) }) }() diff --git a/server/logging/file_logger.go b/server/logging/file_logger.go index b99174e..e83a717 100644 --- a/server/logging/file_logger.go +++ b/server/logging/file_logger.go @@ -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 diff --git a/server/logging/observable_logger.go b/server/logging/observable_logger.go index 95fd794..4b02d03 100644 --- a/server/logging/observable_logger.go +++ b/server/logging/observable_logger.go @@ -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. diff --git a/server/sys/fs.go b/server/sys/fs.go index 88fda33..98ed048 100644 --- a/server/sys/fs.go +++ b/server/sys/fs.go @@ -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)