97 custom arguments broken (#99)

* golang debug

* handle template in playlist download

* code refactoring, dropped goccy go json
This commit is contained in:
Marco
2023-10-22 15:54:08 +02:00
committed by GitHub
parent 8eb2831bc6
commit ba23485b33
13 changed files with 60 additions and 48 deletions

View File

@@ -6,4 +6,12 @@ export const downloadTemplateState = atom({
effects: [
({ onSet }) => onSet(e => localStorage.setItem('lastDownloadTemplate', e))
]
})
export const filenameTemplateState = atom({
key: 'filenameTemplateState',
default: localStorage.getItem('lastFilenameTemplate') ?? '',
effects: [
({ onSet }) => onSet(e => localStorage.setItem('lastFilenameTemplate', e))
]
})

View File

@@ -30,7 +30,7 @@ import {
useTransition
} from 'react'
import { useRecoilState, useRecoilValue } from 'recoil'
import { downloadTemplateState } from '../atoms/downloadTemplate'
import { downloadTemplateState, filenameTemplateState } from '../atoms/downloadTemplate'
import { settingsState } from '../atoms/settings'
import { availableDownloadPathsState, connectedState } from '../atoms/status'
import FormatsGrid from '../components/FormatsGrid'
@@ -74,7 +74,9 @@ export default function DownloadDialog({
const [customArgs, setCustomArgs] = useRecoilState(downloadTemplateState)
const [downloadPath, setDownloadPath] = useState(0)
const [fileNameOverride, setFilenameOverride] = useState('')
const [filenameTemplate, setFilenameTemplate] = useRecoilState(
filenameTemplateState
)
const [url, setUrl] = useState('')
const [workingUrl, setWorkingUrl] = useState('')
@@ -110,7 +112,7 @@ export default function DownloadDialog({
immediate || url || workingUrl,
`${cliArgs.toString()} ${toFormatArgs(codes)} ${customArgs}`,
availableDownloadPaths[downloadPath] ?? '',
fileNameOverride,
filenameTemplate,
isPlaylist,
)
@@ -141,27 +143,15 @@ export default function DownloadDialog({
})
}
/**
* Update the url state whenever the input value changes
* @param e Input change event
*/
const handleUrlChange = (e: React.ChangeEvent<HTMLInputElement>) => {
setUrl(e.target.value)
}
/**
* Update the filename override state whenever the input value changes
* @param e Input change event
*/
const handleFilenameOverrideChange = (e: React.ChangeEvent<HTMLInputElement>) => {
setFilenameOverride(e.target.value)
const handleFilenameTemplateChange = (e: React.ChangeEvent<HTMLInputElement>) => {
setFilenameTemplate(e.target.value)
localStorage.setItem('last-filename-override', e.target.value)
}
/**
* Update the custom args state whenever the input value changes
* @param e Input change event
*/
const handleCustomArgsChange = (e: React.ChangeEvent<HTMLInputElement>) => {
setCustomArgs(e.target.value)
localStorage.setItem("last-input-args", e.target.value)
@@ -285,8 +275,8 @@ export default function DownloadDialog({
fullWidth
label={i18n.t('customFilename')}
variant="outlined"
value={fileNameOverride}
onChange={handleFilenameOverrideChange}
value={filenameTemplate}
onChange={handleFilenameTemplateChange}
disabled={
!isConnected ||
(settings.formatSelection && downloadFormats != null)

View File

@@ -1,4 +1,4 @@
import { Observable, share } from 'rxjs'
import { Observable } from 'rxjs'
import type { DLMetadata, RPCRequest, RPCResponse, RPCResult } from '../types'
import { WebSocketSubject, webSocket } from 'rxjs/webSocket'
@@ -29,6 +29,12 @@ export class RPCClient {
})
}
private argsSanitizer(args: string) {
return args
.split(' ')
.map(a => a.trim().replaceAll("'", '').replaceAll('"', ''))
}
private async sendHTTP<T>(req: RPCRequest) {
const res = await fetch(this.httpEndpoint, {
method: 'POST',
@@ -57,16 +63,17 @@ export class RPCClient {
method: 'Service.ExecPlaylist',
params: [{
URL: url,
Params: args.split(" ").map(a => a.trim()),
Params: this.argsSanitizer(args),
Path: pathOverride,
Rename: renameTo,
}]
})
}
this.sendHTTP({
method: 'Service.Exec',
params: [{
URL: url.split("?list").at(0)!,
Params: args.split(" ").map(a => a.trim()),
URL: url.split('?list').at(0)!,
Params: this.argsSanitizer(args),
Path: pathOverride,
Rename: renameTo,
}]
@@ -78,7 +85,7 @@ export class RPCClient {
return this.sendHTTP<DLMetadata>({
method: 'Service.Formats',
params: [{
URL: url.split("?list").at(0)!,
URL: url.split('?list').at(0)!,
}]
})
}