From 51395f9349c089555d57bf6cccb91e40a050cc91 Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Thu, 7 Sep 2017 16:56:47 +0900 Subject: [PATCH] Apply torrent options after creation Note this is broken due to https://github.com/Luminarys/synapse/issues/25 --- src/ui/add_torrent.js | 43 ++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 40 insertions(+), 3 deletions(-) diff --git a/src/ui/add_torrent.js b/src/ui/add_torrent.js index dcc3015..f525ad4 100644 --- a/src/ui/add_torrent.js +++ b/src/ui/add_torrent.js @@ -168,17 +168,54 @@ class AddTorrent extends Component { } } + applyOptions(id) { + const { + priority, + uploadThrottle, + downloadThrottle + } = this.state; + const { dispatch } = this.props; + const customize = // TODO: File options + priority !== 3 || + uploadThrottle !== -1 || + downloadThrottle !== -1; + if (!customize) { + dispatch(push(`/torrents/${id}`)); + return; + } + ws_send("UPDATE_RESOURCE", { + resource: { + id, + priority, + throttle_up: uploadThrottle, + throttle_down: downloadThrottle + } + }, async done => { + if (this.state.startImmediately) { + ws_send("RESUME_TORRENT", { id }); + } + dispatch(push(`/torrents/${id}`)); + }); + } + uploadFile() { this.setState({ loading: true }); - const { file } = this.state; + const { file, startImmediately } = this.state; const { dispatch } = this.props; - ws_send("UPLOAD_TORRENT", { size: file.size }, async offer => { + const customize = // TODO: File options + this.state.priority !== 3 || + this.state.uploadThrottle !== -1 || + this.state.downloadThrottle !== -1; + ws_send("UPLOAD_TORRENT", { + size: file.size, + start: startImmediately && !customize + }, async offer => { switch (offer.type) { case "TRANSFER_OFFER": return await this.handleTransferOffer(offer, file); case "RESOURCES_EXTANT": const [id] = offer.ids; - dispatch(push(`/torrents/${id}`)); + this.applyOptions.bind(this)(id); break; } });