diff --git a/frontend/src/App.tsx b/frontend/src/App.tsx index 709a816..8bb10e8 100755 --- a/frontend/src/App.tsx +++ b/frontend/src/App.tsx @@ -31,7 +31,7 @@ import { RootState, store } from './stores/store'; import { formatGiB, getWebSocketEndpoint } from "./utils"; function AppContent() { - const [open, setOpen] = useState(false); + const [open, setOpen] = useState(false) const settings = useSelector((state: RootState) => state.settings) const status = useSelector((state: RootState) => state.status) @@ -39,7 +39,6 @@ function AppContent() { const socket = useMemo(() => new WebSocket(getWebSocketEndpoint()), []) const mode = settings.theme - const theme = useMemo(() => createTheme({ palette: { @@ -49,11 +48,11 @@ function AppContent() { }, }, }), [settings.theme] - ); + ) const toggleDrawer = () => { - setOpen(!open); - }; + setOpen(!open) + } return ( @@ -61,11 +60,7 @@ function AppContent() { - + - + ); } \ No newline at end of file diff --git a/frontend/src/features/status/statusSlice.ts b/frontend/src/features/status/statusSlice.ts index a0d55af..209bc53 100644 --- a/frontend/src/features/status/statusSlice.ts +++ b/frontend/src/features/status/statusSlice.ts @@ -42,6 +42,14 @@ export const statusSlice = createSlice({ } }) -export const { connected, disconnected, updated, alreadyUpdated, downloading, finished, setFreeSpace } = statusSlice.actions +export const { + connected, + disconnected, + updated, + alreadyUpdated, + downloading, + finished, + setFreeSpace +} = statusSlice.actions export default statusSlice.reducer \ No newline at end of file diff --git a/server/process.go b/server/process.go index f7cff0b..4ce0ac3 100644 --- a/server/process.go +++ b/server/process.go @@ -167,6 +167,10 @@ func (p *Process) Complete() { // Kill a process and remove it from the memory func (p *Process) Kill() error { + // yt-dlp uses multiple child process the parent process + // has been spawned with setPgid = true. To properly kill + // all subprocesses a SIGTERM need to be sent to the correct + // process group pgid, err := syscall.Getpgid(p.proc.Pid) if err != nil { return err @@ -177,6 +181,7 @@ func (p *Process) Kill() error { return err } +// Returns the available format for this URL func (p *Process) GetFormatsSync() (DownloadFormats, error) { cmd := exec.Command(cfg.GetConfig().DownloaderPath, p.url, "-J") stdout, err := cmd.Output() diff --git a/server/server.go b/server/server.go index ba0bb4c..7a9f548 100644 --- a/server/server.go +++ b/server/server.go @@ -31,11 +31,12 @@ func RunBlocking(ctx context.Context) { app := fiber.New() app.Use(cors.New()) - app.Use("/", filesystem.New(filesystem.Config{ Root: http.FS(fe), })) + // RPC handlers + // websocket app.Get("/ws-rpc", websocket.New(func(c *websocket.Conn) { for { mtype, reader, err := c.NextReader() @@ -51,7 +52,7 @@ func RunBlocking(ctx context.Context) { io.Copy(writer, res) } })) - + // http-post app.Post("/http-rpc", func(c *fiber.Ctx) error { reader := c.Context().RequestBodyStream() writer := c.Response().BodyWriter() diff --git a/server/service.go b/server/service.go index 62bb73c..4a3cdb8 100644 --- a/server/service.go +++ b/server/service.go @@ -97,12 +97,14 @@ func (t *Service) FreeSpace(args NoArgs, free *uint64) error { return err } +// Return a flattned tree of the download directory func (t *Service) DirectoryTree(args NoArgs, tree *[]string) error { dfsTree, err := sys.DirectoryTree() *tree = *dfsTree return err } +// Updates the yt-dlp binary using its builtin function func (t *Service) UpdateExecutable(args NoArgs, updated *bool) error { log.Println("Updating yt-dlp executable to the latest release") err := updater.UpdateExecutable() diff --git a/server/types.go b/server/types.go index 54e4964..8257aa1 100644 --- a/server/types.go +++ b/server/types.go @@ -1,11 +1,13 @@ package server +// Progress for the Running call type DownloadProgress struct { Percentage string `json:"percentage"` Speed float32 `json:"speed"` ETA int `json:"eta"` } +// Used to deser the yt-dlp -J output type DownloadInfo struct { URL string `json:"url"` Title string `json:"title"` @@ -17,6 +19,7 @@ type DownloadInfo struct { Extension string `json:"ext"` } +// Used to deser the formats in the -J output type DownloadFormats struct { Formats []Format `json:"formats"` Best Format `json:"best"` @@ -25,6 +28,7 @@ type DownloadFormats struct { URL string `json:"url"` } +// A skimmed yt-dlp format node type Format struct { Format_id string `json:"format_id"` Format_note string `json:"format_note"` diff --git a/server/updater/update.go b/server/updater/update.go index 8bf8b37..994e2ac 100644 --- a/server/updater/update.go +++ b/server/updater/update.go @@ -8,6 +8,7 @@ import ( var path = config.Instance().GetConfig().DownloaderPath +// Update using the builtin function of yt-dlp func UpdateExecutable() error { cmd := exec.Command(path, "-U") cmd.Start()