Add a button to increase peer timeouts

This commit is contained in:
Igor Katson 2023-11-30 16:05:48 +00:00
parent dc50de31dc
commit a0feee27a6
No known key found for this signature in database
GPG key ID: B4EC22B66D61A3F5
6 changed files with 61 additions and 28 deletions

View file

@ -147,7 +147,7 @@ export const API = {
},
uploadTorrent: (data: string | File, opts?: {
listOnly?: boolean, selectedFiles?: Array<number>
listOnly?: boolean, selectedFiles?: Array<number>, unpopularTorrent?: boolean,
}): Promise<AddTorrentResponse> => {
opts = opts || {};
let url = '/torrents?&overwrite=true';
@ -157,6 +157,9 @@ export const API = {
if (opts.selectedFiles != null) {
url += `&only_files=${opts.selectedFiles.join(',')}`;
}
if (opts.unpopularTorrent) {
url += '&peer_connect_timeout=20&peer_read_write_timeout=60';
}
return makeRequest('POST', url, data)
},

View file

@ -438,7 +438,7 @@ const MagnetInput = () => {
};
return (
<UploadButton variant='primary' buttonText="Add Torrent from Magnet Link" onClick={onClick} data={magnet} resetData={() => setMagnet(null)} />
<UploadButton variant='primary' buttonText="Add Torrent from Magnet / URL" onClick={onClick} data={magnet} resetData={() => setMagnet(null)} />
);
};
@ -481,6 +481,7 @@ const FileSelectionModal = (props: {
const [selectedFiles, setSelectedFiles] = useState([]);
const [uploading, setUploading] = useState(false);
const [uploadError, setUploadError] = useState<Error>(null);
const [unpopularTorrent, setUnpopularTorrent] = useState(false);
const ctx = useContext(AppContext);
useEffect(() => {
@ -504,7 +505,7 @@ const FileSelectionModal = (props: {
const handleUpload = async () => {
setUploading(true);
API.uploadTorrent(data, { selectedFiles }).then(
API.uploadTorrent(data, { selectedFiles, unpopularTorrent }).then(
() => {
onHide();
ctx.refreshTorrents();
@ -518,24 +519,43 @@ const FileSelectionModal = (props: {
return (
<Modal show={show} onHide={clear} size='lg'>
<Modal.Header closeButton>
{!!fileListError || <Modal.Title>Select Files</Modal.Title>}
{!!fileListError || <Modal.Title>Add torrent</Modal.Title>}
</Modal.Header>
<Modal.Body>
{fileListLoading ? <Spinner />
: fileListError ? <ErrorComponent error={fileListError}></ErrorComponent> :
<Form>
{fileList.map((file, index) => (
<Form.Group key={index} controlId={`check-${index}`}>
<Form.Check
type="checkbox"
label={`${file.name} (${formatBytes(file.length)})`}
checked={selectedFiles.includes(index)}
onChange={() => handleToggleFile(index)}>
</Form.Check>
</Form.Group>
))}
</Form>
}
<Form>
<fieldset className='mb-5'>
<legend>Pick the files to download</legend>
{fileListLoading ? <Spinner />
: fileListError ? <ErrorComponent error={fileListError}></ErrorComponent> :
<>
{fileList.map((file, index) => (
<Form.Group key={index} controlId={`check-${index}`}>
<Form.Check
type="checkbox"
label={`${file.name} (${formatBytes(file.length)})`}
checked={selectedFiles.includes(index)}
onChange={() => handleToggleFile(index)}>
</Form.Check>
</Form.Group>
))}
</>
}
</fieldset>
<fieldset>
<legend>Other options</legend>
<Form.Group controlId='unpopular-torrent'>
<Form.Check
type="checkbox"
label="Increase timeouts"
checked={unpopularTorrent}
onChange={() => setUnpopularTorrent(!unpopularTorrent)}>
</Form.Check>
<small id="emailHelp" className="form-text text-muted">This might be useful for unpopular torrents with few peers.</small>
</Form.Group>
</fieldset>
</Form>
<ErrorComponent error={uploadError} />
</Modal.Body>
<Modal.Footer>