Refactoring

This commit is contained in:
2023-01-12 21:10:23 +01:00
parent d93fc37943
commit 658cb64a02
7 changed files with 30 additions and 14 deletions

View File

@@ -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 (
<ThemeProvider theme={theme}>
@@ -61,11 +60,7 @@ function AppContent() {
<Box sx={{ display: 'flex' }}>
<CssBaseline />
<AppBar position="absolute" open={open}>
<Toolbar
sx={{
pr: '24px', // keep right padding when drawer closed
}}
>
<Toolbar sx={{ pr: '24px' }}>
<IconButton
edge="start"
color="inherit"
@@ -175,7 +170,7 @@ function AppContent() {
export function App() {
return (
<Provider store={store}>
<AppContent></AppContent>
<AppContent />
</Provider>
);
}

View File

@@ -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

View File

@@ -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()

View File

@@ -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()

View File

@@ -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()

View File

@@ -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"`

View File

@@ -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()