Refactoring
This commit is contained in:
@@ -31,7 +31,7 @@ import { RootState, store } from './stores/store';
|
|||||||
import { formatGiB, getWebSocketEndpoint } from "./utils";
|
import { formatGiB, getWebSocketEndpoint } from "./utils";
|
||||||
|
|
||||||
function AppContent() {
|
function AppContent() {
|
||||||
const [open, setOpen] = useState(false);
|
const [open, setOpen] = useState(false)
|
||||||
|
|
||||||
const settings = useSelector((state: RootState) => state.settings)
|
const settings = useSelector((state: RootState) => state.settings)
|
||||||
const status = useSelector((state: RootState) => state.status)
|
const status = useSelector((state: RootState) => state.status)
|
||||||
@@ -39,7 +39,6 @@ function AppContent() {
|
|||||||
const socket = useMemo(() => new WebSocket(getWebSocketEndpoint()), [])
|
const socket = useMemo(() => new WebSocket(getWebSocketEndpoint()), [])
|
||||||
|
|
||||||
const mode = settings.theme
|
const mode = settings.theme
|
||||||
|
|
||||||
const theme = useMemo(() =>
|
const theme = useMemo(() =>
|
||||||
createTheme({
|
createTheme({
|
||||||
palette: {
|
palette: {
|
||||||
@@ -49,11 +48,11 @@ function AppContent() {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
}), [settings.theme]
|
}), [settings.theme]
|
||||||
);
|
)
|
||||||
|
|
||||||
const toggleDrawer = () => {
|
const toggleDrawer = () => {
|
||||||
setOpen(!open);
|
setOpen(!open)
|
||||||
};
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<ThemeProvider theme={theme}>
|
<ThemeProvider theme={theme}>
|
||||||
@@ -61,11 +60,7 @@ function AppContent() {
|
|||||||
<Box sx={{ display: 'flex' }}>
|
<Box sx={{ display: 'flex' }}>
|
||||||
<CssBaseline />
|
<CssBaseline />
|
||||||
<AppBar position="absolute" open={open}>
|
<AppBar position="absolute" open={open}>
|
||||||
<Toolbar
|
<Toolbar sx={{ pr: '24px' }}>
|
||||||
sx={{
|
|
||||||
pr: '24px', // keep right padding when drawer closed
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<IconButton
|
<IconButton
|
||||||
edge="start"
|
edge="start"
|
||||||
color="inherit"
|
color="inherit"
|
||||||
@@ -175,7 +170,7 @@ function AppContent() {
|
|||||||
export function App() {
|
export function App() {
|
||||||
return (
|
return (
|
||||||
<Provider store={store}>
|
<Provider store={store}>
|
||||||
<AppContent></AppContent>
|
<AppContent />
|
||||||
</Provider>
|
</Provider>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -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
|
export default statusSlice.reducer
|
||||||
@@ -167,6 +167,10 @@ func (p *Process) Complete() {
|
|||||||
|
|
||||||
// Kill a process and remove it from the memory
|
// Kill a process and remove it from the memory
|
||||||
func (p *Process) Kill() error {
|
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)
|
pgid, err := syscall.Getpgid(p.proc.Pid)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -177,6 +181,7 @@ func (p *Process) Kill() error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Returns the available format for this URL
|
||||||
func (p *Process) GetFormatsSync() (DownloadFormats, error) {
|
func (p *Process) GetFormatsSync() (DownloadFormats, error) {
|
||||||
cmd := exec.Command(cfg.GetConfig().DownloaderPath, p.url, "-J")
|
cmd := exec.Command(cfg.GetConfig().DownloaderPath, p.url, "-J")
|
||||||
stdout, err := cmd.Output()
|
stdout, err := cmd.Output()
|
||||||
|
|||||||
@@ -31,11 +31,12 @@ func RunBlocking(ctx context.Context) {
|
|||||||
app := fiber.New()
|
app := fiber.New()
|
||||||
|
|
||||||
app.Use(cors.New())
|
app.Use(cors.New())
|
||||||
|
|
||||||
app.Use("/", filesystem.New(filesystem.Config{
|
app.Use("/", filesystem.New(filesystem.Config{
|
||||||
Root: http.FS(fe),
|
Root: http.FS(fe),
|
||||||
}))
|
}))
|
||||||
|
|
||||||
|
// RPC handlers
|
||||||
|
// websocket
|
||||||
app.Get("/ws-rpc", websocket.New(func(c *websocket.Conn) {
|
app.Get("/ws-rpc", websocket.New(func(c *websocket.Conn) {
|
||||||
for {
|
for {
|
||||||
mtype, reader, err := c.NextReader()
|
mtype, reader, err := c.NextReader()
|
||||||
@@ -51,7 +52,7 @@ func RunBlocking(ctx context.Context) {
|
|||||||
io.Copy(writer, res)
|
io.Copy(writer, res)
|
||||||
}
|
}
|
||||||
}))
|
}))
|
||||||
|
// http-post
|
||||||
app.Post("/http-rpc", func(c *fiber.Ctx) error {
|
app.Post("/http-rpc", func(c *fiber.Ctx) error {
|
||||||
reader := c.Context().RequestBodyStream()
|
reader := c.Context().RequestBodyStream()
|
||||||
writer := c.Response().BodyWriter()
|
writer := c.Response().BodyWriter()
|
||||||
|
|||||||
@@ -97,12 +97,14 @@ func (t *Service) FreeSpace(args NoArgs, free *uint64) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Return a flattned tree of the download directory
|
||||||
func (t *Service) DirectoryTree(args NoArgs, tree *[]string) error {
|
func (t *Service) DirectoryTree(args NoArgs, tree *[]string) error {
|
||||||
dfsTree, err := sys.DirectoryTree()
|
dfsTree, err := sys.DirectoryTree()
|
||||||
*tree = *dfsTree
|
*tree = *dfsTree
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Updates the yt-dlp binary using its builtin function
|
||||||
func (t *Service) UpdateExecutable(args NoArgs, updated *bool) error {
|
func (t *Service) UpdateExecutable(args NoArgs, updated *bool) error {
|
||||||
log.Println("Updating yt-dlp executable to the latest release")
|
log.Println("Updating yt-dlp executable to the latest release")
|
||||||
err := updater.UpdateExecutable()
|
err := updater.UpdateExecutable()
|
||||||
|
|||||||
@@ -1,11 +1,13 @@
|
|||||||
package server
|
package server
|
||||||
|
|
||||||
|
// Progress for the Running call
|
||||||
type DownloadProgress struct {
|
type DownloadProgress struct {
|
||||||
Percentage string `json:"percentage"`
|
Percentage string `json:"percentage"`
|
||||||
Speed float32 `json:"speed"`
|
Speed float32 `json:"speed"`
|
||||||
ETA int `json:"eta"`
|
ETA int `json:"eta"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Used to deser the yt-dlp -J output
|
||||||
type DownloadInfo struct {
|
type DownloadInfo struct {
|
||||||
URL string `json:"url"`
|
URL string `json:"url"`
|
||||||
Title string `json:"title"`
|
Title string `json:"title"`
|
||||||
@@ -17,6 +19,7 @@ type DownloadInfo struct {
|
|||||||
Extension string `json:"ext"`
|
Extension string `json:"ext"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Used to deser the formats in the -J output
|
||||||
type DownloadFormats struct {
|
type DownloadFormats struct {
|
||||||
Formats []Format `json:"formats"`
|
Formats []Format `json:"formats"`
|
||||||
Best Format `json:"best"`
|
Best Format `json:"best"`
|
||||||
@@ -25,6 +28,7 @@ type DownloadFormats struct {
|
|||||||
URL string `json:"url"`
|
URL string `json:"url"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// A skimmed yt-dlp format node
|
||||||
type Format struct {
|
type Format struct {
|
||||||
Format_id string `json:"format_id"`
|
Format_id string `json:"format_id"`
|
||||||
Format_note string `json:"format_note"`
|
Format_note string `json:"format_note"`
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import (
|
|||||||
|
|
||||||
var path = config.Instance().GetConfig().DownloaderPath
|
var path = config.Instance().GetConfig().DownloaderPath
|
||||||
|
|
||||||
|
// Update using the builtin function of yt-dlp
|
||||||
func UpdateExecutable() error {
|
func UpdateExecutable() error {
|
||||||
cmd := exec.Command(path, "-U")
|
cmd := exec.Command(path, "-U")
|
||||||
cmd.Start()
|
cmd.Start()
|
||||||
|
|||||||
Reference in New Issue
Block a user