mirror of
https://github.com/lrnselfreliance/wrolpi.git
synced 2026-11-29 11:26:25 -05:00
Downloader can be specified by the user.
This commit is contained in:
parent
4a169ba43c
commit
047b507119
12 changed files with 171 additions and 53 deletions
|
|
@ -339,8 +339,8 @@ export async function fetchDomains() {
|
|||
}
|
||||
}
|
||||
|
||||
export async function postDownload(urls) {
|
||||
let body = {'urls': urls};
|
||||
export async function postDownload(urls, downloader) {
|
||||
let body = {urls: urls, downloader: downloader};
|
||||
let response = await apiPost(`${API_URI}/download`, body);
|
||||
return response;
|
||||
}
|
||||
|
|
@ -350,3 +350,8 @@ export async function killDownload(download_id) {
|
|||
let response = await apiPost(`${API_URI}/download/${download_id}/kill`);
|
||||
return response;
|
||||
}
|
||||
|
||||
export async function getDownloaders() {
|
||||
let response = await apiGet(`${API_URI}/downloaders`);
|
||||
return await response.json();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -219,7 +219,8 @@ class StoppableRow extends React.Component {
|
|||
|
||||
handleStart = async (e) => {
|
||||
e.preventDefault();
|
||||
await postDownload(`${this.props.url}`);
|
||||
let downloader = this.props.downloader || null;
|
||||
await postDownload(`${this.props.url}`, downloader);
|
||||
this.closeStart();
|
||||
await this.props.fetchDownloads();
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import React from "react";
|
||||
import {Button, Form, Header, Segment, TextArea} from "semantic-ui-react";
|
||||
import {postDownload} from "../api";
|
||||
import {Button, Dropdown, Form, Header, Segment, TextArea} from "semantic-ui-react";
|
||||
import {getDownloaders, postDownload} from "../api";
|
||||
|
||||
const validUrl = /^(http|https):\/\/[^ "]+$/;
|
||||
|
||||
|
|
@ -11,14 +11,29 @@ class Downloader extends React.Component {
|
|||
urls: '',
|
||||
valid: true,
|
||||
pending: false,
|
||||
downloaders: [],
|
||||
downloader: null,
|
||||
};
|
||||
}
|
||||
|
||||
async componentDidMount() {
|
||||
await this.fetchDownloaders();
|
||||
}
|
||||
|
||||
fetchDownloaders = async () => {
|
||||
let {downloaders} = await getDownloaders();
|
||||
downloaders = downloaders.map((i) => {
|
||||
return {key: i.name, text: i.pretty_name || i.name, value: i.name}
|
||||
})
|
||||
this.setState({downloaders});
|
||||
}
|
||||
|
||||
submitDownload = async () => {
|
||||
if (this.state.urls) {
|
||||
let {urls, downloader} = this.state;
|
||||
if (urls) {
|
||||
this.setState({pending: true});
|
||||
try {
|
||||
let response = await postDownload(this.state.urls);
|
||||
let response = await postDownload(urls, downloader);
|
||||
if (response.status === 204) {
|
||||
this.setState({urls: '', pending: false});
|
||||
}
|
||||
|
|
@ -52,14 +67,25 @@ class Downloader extends React.Component {
|
|||
|
||||
return (
|
||||
<Form onSubmit={this.submitDownload}>
|
||||
<Header as='h4'>Enter the URLs you wish to bring offline.</Header>
|
||||
<TextArea
|
||||
placeholder={textareaPlaceholder}
|
||||
name='urls'
|
||||
onChange={this.handleInputChange}
|
||||
value={this.state.urls}
|
||||
error={!this.state.valid}
|
||||
/>
|
||||
<Header as='h4'>Enter the URLs you wish to save offline.</Header>
|
||||
<Form.Field>
|
||||
<TextArea
|
||||
placeholder={textareaPlaceholder}
|
||||
name='urls'
|
||||
onChange={this.handleInputChange}
|
||||
value={this.state.urls}
|
||||
error={!this.state.valid}
|
||||
/>
|
||||
</Form.Field>
|
||||
<Form.Field>
|
||||
<Dropdown
|
||||
selection
|
||||
name='downloader'
|
||||
options={this.state.downloaders}
|
||||
placeholder='Automatic'
|
||||
onChange={this.handleInputChange}
|
||||
/>
|
||||
</Form.Field>
|
||||
<Button primary style={{marginTop: '1em'}} disabled={disabled}>Download</Button>
|
||||
</Form>
|
||||
)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue