code refactoring, fixed playlist downloads sorting

This commit is contained in:
2023-10-19 11:29:56 +02:00
parent 2d75030cbc
commit da4aaeac84
3 changed files with 16 additions and 7 deletions

View File

@@ -31,7 +31,7 @@ import {
useState, useState,
useTransition useTransition
} from 'react' } from 'react'
import { useRecoilValue } from 'recoil' import { useRecoilState, useRecoilValue } from 'recoil'
import { settingsState } from '../atoms/settings' import { settingsState } from '../atoms/settings'
import { availableDownloadPathsState, connectedState } from '../atoms/status' import { availableDownloadPathsState, connectedState } from '../atoms/status'
import FormatsGrid from '../components/FormatsGrid' import FormatsGrid from '../components/FormatsGrid'
@@ -40,6 +40,7 @@ import { useRPC } from '../hooks/useRPC'
import { CliArguments } from '../lib/argsParser' import { CliArguments } from '../lib/argsParser'
import type { DLMetadata } from '../types' import type { DLMetadata } from '../types'
import { isValidURL, toFormatArgs } from '../utils' import { isValidURL, toFormatArgs } from '../utils'
import { downloadTemplateState } from '../atoms/downloadTemplate'
const Transition = forwardRef(function Transition( const Transition = forwardRef(function Transition(
props: TransitionProps & { props: TransitionProps & {
@@ -72,7 +73,7 @@ export default function DownloadDialog({
const [pickedAudioFormat, setPickedAudioFormat] = useState('') const [pickedAudioFormat, setPickedAudioFormat] = useState('')
const [pickedBestFormat, setPickedBestFormat] = useState('') const [pickedBestFormat, setPickedBestFormat] = useState('')
const [customArgs, setCustomArgs] = useState(localStorage.getItem("last-input-args")||'') const [customArgs, setCustomArgs] = useRecoilState(downloadTemplateState)
const [downloadPath, setDownloadPath] = useState(0) const [downloadPath, setDownloadPath] = useState(0)
const [fileNameOverride, setFilenameOverride] = useState('') const [fileNameOverride, setFilenameOverride] = useState('')

View File

@@ -24,9 +24,12 @@ func Login(w http.ResponseWriter, r *http.Request) {
return return
} }
cfg := config.Instance().GetConfig() var (
username = config.Instance().GetConfig().Username
password = config.Instance().GetConfig().Password
)
if cfg.Username != req.Username || cfg.Password != req.Password { if username != req.Username || password != req.Password {
http.Error(w, err.Error(), http.StatusBadRequest) http.Error(w, err.Error(), http.StatusBadRequest)
return return
} }

View File

@@ -18,7 +18,10 @@ type metadata struct {
} }
func PlaylistDetect(req DownloadRequest, mq *MessageQueue, db *MemoryDB) error { func PlaylistDetect(req DownloadRequest, mq *MessageQueue, db *MemoryDB) error {
cmd := exec.Command(config.Instance().GetConfig().DownloaderPath, req.URL, "-J") var (
downloader = config.Instance().GetConfig().DownloaderPath
cmd = exec.Command(downloader, req.URL, "-J")
)
stdout, err := cmd.StdoutPipe() stdout, err := cmd.StdoutPipe()
if err != nil { if err != nil {
@@ -51,7 +54,9 @@ func PlaylistDetect(req DownloadRequest, mq *MessageQueue, db *MemoryDB) error {
cli.BgGreen, "Playlist detected", cli.Reset, m.Count, "entries", cli.BgGreen, "Playlist detected", cli.Reset, m.Count, "entries",
) )
for _, meta := range m.Entries { for i, meta := range m.Entries {
delta := time.Second.Microseconds() * int64(i+1)
proc := &Process{ proc := &Process{
Url: meta.OriginalURL, Url: meta.OriginalURL,
Progress: DownloadProgress{}, Progress: DownloadProgress{},
@@ -61,7 +66,7 @@ func PlaylistDetect(req DownloadRequest, mq *MessageQueue, db *MemoryDB) error {
} }
proc.Info.URL = meta.OriginalURL proc.Info.URL = meta.OriginalURL
proc.Info.CreatedAt = time.Now().Add(time.Second) proc.Info.CreatedAt = time.Now().Add(time.Duration(delta))
db.Set(proc) db.Set(proc)
proc.SetPending() proc.SetPending()