Add set throttle ability

This commit is contained in:
John Furrow
2016-01-03 20:58:34 -05:00
parent bdc5e147ef
commit f0ab3a347b
12 changed files with 170 additions and 37 deletions
@@ -25,6 +25,32 @@ const ClientActions = {
}
});
});
},
setThrottle: function(direction, throttle) {
return axios.put('/client/settings/speed-limits', {
direction,
throttle
})
.then((json = {}) => {
return json.data;
})
.then((transferData) => {
AppDispatcher.dispatchServerAction({
type: ActionTypes.CLIENT_SET_THROTTLE_SUCCESS,
data: {
transferData
}
});
})
.catch((error) => {
AppDispatcher.dispatchServerAction({
type: ActionTypes.CLIENT_SET_THROTTLE_ERROR,
data: {
error
}
});
});
}
};
@@ -30,6 +30,7 @@ export default class ActionBar extends React.Component {
}
componentDidMount() {
console.log(TorrentFilterStore.getTorrentsSort());
TorrentFilterStore.listen(EventTypes.UI_TORRENTS_SORT_CHANGE, this.onSortChange);
}
@@ -7,6 +7,8 @@ const ActionTypes = {
CLIENT_FETCH_TORRENTS_SUCCESS: 'CLIENT_FETCH_TORRENTS_SUCCESS',
CLIENT_FETCH_TRANSFER_DATA_ERROR: 'CLIENT_FETCH_TRANSFER_DATA_ERROR',
CLIENT_FETCH_TRANSFER_DATA_SUCCESS: 'CLIENT_FETCH_TRANSFER_DATA_SUCCESS',
CLIENT_SET_THROTTLE_ERROR: 'CLIENT_SET_THROTTLE_ERROR',
CLIENT_SET_THROTTLE_SUCCESS: 'CLIENT_SET_THROTTLE_SUCCESS',
CLIENT_START_TORRENT_ERROR: 'CLIENT_START_TORRENT_ERROR',
CLIENT_START_TORRENT_SUCCESS: 'CLIENT_START_TORRENT_SUCCESS',
CLIENT_STOP_TORRENT_ERROR: 'CLIENT_STOP_TORRENT_ERROR',
@@ -1,4 +1,6 @@
const EventTypes = {
CLIENT_SET_THROTTLE_ERROR: 'CLIENT_SET_THROTTLE_ERROR',
CLIENT_SET_THROTTLE_SUCCESS: 'CLIENT_SET_THROTTLE_SUCCESS',
CLIENT_TORRENTS_REQUEST_ERROR: 'CLIENT_TORRENTS_REQUEST_ERROR',
CLIENT_TORRENTS_REQUEST_SUCCESS: 'CLIENT_TORRENTS_REQUEST_SUCCESS',
CLIENT_TORRENT_DETAILS_CHANGE: 'CLIENT_TORRENT_DETAILS_CHANGE',
@@ -12,6 +12,7 @@ class ClientDataStoreClass extends BaseStore {
this.pollTransferDataID = null;
this.transferRates = {download: [], upload: []};
this.transferTotals = {download: null, upload: null};
this.throttles = {download: null, upload: null};
}
fetchTransferData() {
@@ -22,6 +23,10 @@ class ClientDataStoreClass extends BaseStore {
}
}
getThrottles() {
return this.throttles;
}
getTransferTotals() {
return this.transferTotals;
}
@@ -34,6 +39,15 @@ class ClientDataStoreClass extends BaseStore {
return this.transferRates;
}
handleSetThrottleSuccess(data) {
this.fetchTransferData();
this.emit(EventTypes.CLIENT_SET_THROTTLE_SUCCESS);
}
handleSetThrottleError(error) {
this.emit(EventTypes.CLIENT_SET_THROTTLE_ERROR);
}
handleTransferDataSuccess(transferData) {
this.transferTotals = {
download: transferData.downloadTotal,
@@ -45,20 +59,34 @@ class ClientDataStoreClass extends BaseStore {
upload: transferData.uploadRate
};
// this.throttles = {
// download: transferData.downloadThrottle,
// upload: transferData.uploadThrottle
// };
// add the latest download & upload rates to the end of the array and remove
// the first element in the array. if the arrays are empty, fill in zeros
// for the first n entries.
let index = 0;
let downloadRateHistory = Object.assign([], this.transferRates.download);
let downloadRateThrottleHistory = Object.assign([], this.throttles.download);
let uploadRateHistory = Object.assign([], this.transferRates.upload);
let uploadRateThrottleHistory = Object.assign([], this.throttles.upload);
if (uploadRateHistory.length === config.maxHistoryStates) {
downloadRateHistory.shift();
downloadRateThrottleHistory.shift();
uploadRateHistory.shift();
uploadRateThrottleHistory.shift();
downloadRateHistory.push(parseInt(transferData.downloadRate));
downloadRateThrottleHistory.push(parseInt(transferData.downloadThrottle));
uploadRateHistory.push(parseInt(transferData.uploadRate));
uploadRateThrottleHistory.push(parseInt(transferData.uploadThrottle));
} else {
while (index < config.maxHistoryStates) {
// if we don't have historical values, we assume zero for the transfer
// rate history.
if (index < config.maxHistoryStates - 1) {
uploadRateHistory[index] = 0;
downloadRateHistory[index] = 0;
@@ -66,6 +94,11 @@ class ClientDataStoreClass extends BaseStore {
downloadRateHistory[index] = parseInt(transferData.downloadRate);
uploadRateHistory[index] = parseInt(transferData.uploadRate);
}
// we assume the throttle history has been the same for all previous
// history states.
uploadRateThrottleHistory[index] = parseInt(transferData.uploadThrottle);
downloadRateThrottleHistory[index] = parseInt(transferData.downloadThrottle);
index++;
}
}
@@ -75,6 +108,11 @@ class ClientDataStoreClass extends BaseStore {
upload: uploadRateHistory
};
this.throttles = {
download: downloadRateThrottleHistory,
upload: uploadRateThrottleHistory
};
this.emit(EventTypes.CLIENT_TRANSFER_DATA_REQUEST_SUCCESS);
}
@@ -112,6 +150,12 @@ AppDispatcher.register((payload) => {
case ActionTypes.CLIENT_FETCH_TRANSFER_DATA_ERROR:
ClientDataStore.handleTransferDataError(action.data.error);
break;
case ActionTypes.CLIENT_SET_THROTTLE_SUCCESS:
ClientDataStore.handleSetThrottleSuccess(action.data.transferData);
break;
case ActionTypes.CLIENT_SET_THROTTLE_ERROR:
ClientDataStore.handleSetThrottleError(action.data.error);
break;
}
});
@@ -13,7 +13,8 @@ class TorrentFilterStoreClass extends BaseStore {
this.sortTorrentsBy = {
direction: 'desc',
displayName: 'Date Added',
property: 'added'
property: 'sortBy',
value: 'added'
};
}
+11 -11
View File
File diff suppressed because one or more lines are too long
+30 -9
View File
@@ -778,9 +778,8 @@ body {
border: none;
color: #53718a;
display: block;
margin: 15px 0 0 0;
outline: none;
padding: 2px 0 2px 25px;
padding: 10px 15px;
font-size: 0.85em;
text-align: left;
-webkit-transition: color 0.25s;
@@ -816,9 +815,13 @@ body {
.client-stat .graph svg {
height: 100%;
width: 100%; }
.client-stat .graph--line {
fill: none;
stroke-width: 2px; }
.client-stat .graph__line {
fill: none; }
.client-stat .graph__line--limit {
stroke-dasharray: 4px;
stroke-width: 1px; }
.client-stat .graph__line--rate {
stroke-width: 2px; }
.client-stat--download .icon {
fill: rgba(43, 174, 108, 0.75); }
.client-stat--download .client-stat__data--primary {
@@ -829,9 +832,11 @@ body {
stop-color: rgba(43, 174, 108, 0.2); }
.client-stat--download .graph .graph--download--gradient--bottom {
stop-color: rgba(43, 174, 108, 0); }
.client-stat--download .graph--area {
.client-stat--download .graph__area {
fill: url("#graph--download--gradient"); }
.client-stat--download .graph--line {
.client-stat--download .graph__line--limit {
stroke: rgba(102, 217, 159, 0.2); }
.client-stat--download .graph__line--rate {
stroke: rgba(43, 174, 108, 0.4); }
.client-stat--upload .icon {
fill: rgba(35, 135, 217, 0.75); }
@@ -843,9 +848,11 @@ body {
stop-color: rgba(35, 135, 217, 0.2); }
.client-stat--upload .graph .graph--upload--gradient--bottom {
stop-color: rgba(35, 135, 217, 0); }
.client-stat--upload .graph--area {
.client-stat--upload .graph__area {
fill: url("#graph--upload--gradient"); }
.client-stat--upload .graph--line {
.client-stat--upload .graph__line--limit {
stroke: rgba(121, 183, 233, 0.2); }
.client-stat--upload .graph__line--rate {
stroke: rgba(35, 135, 217, 0.4); }
.content {
@@ -909,7 +916,16 @@ body {
position: absolute;
width: 90%; }
.dropdown__items {
display: -webkit-box;
display: -webkit-flex;
display: -ms-flexbox;
display: flex;
padding: 10px 0; }
.dropdown__list {
-webkit-box-flex: 1;
-webkit-flex: 1;
-ms-flex: 1;
flex: 1; }
.dropdown__item {
cursor: pointer;
display: block;
@@ -1069,6 +1085,11 @@ body {
color: #2cad6d; }
.sidebar__item--search.is-in-use .textbox::placeholder {
color: #2cad6d; }
.sidebar__item--speed-limit {
padding-left: 5px;
padding-top: 5px; }
.sidebar__item--speed-limit .dropdown__content {
min-width: 180px; }
.modal {
background: rgba(26, 47, 61, 0.5);
File diff suppressed because one or more lines are too long
+30 -2
View File
@@ -175,6 +175,33 @@ var client = {
});
},
setSpeedLimits: function(data, callback) {
var methodName = 'throttle.global_down.max_rate.set';
if (data.direction === 'upload') {
methodName = 'throttle.global_up.max_rate.set';
}
var multicall = [
[
{
methodName: methodName,
params: [
'',
data.throttle
]
}
]
];
rTorrent.get('system.multicall', multicall)
.then(function(data) {
callback(null, data);
}, function(error) {
callback(error, null);
});
},
stopTorrent: function(hash, callback) {
if (!util.isArray(hash)) {
hash = [hash];
@@ -224,8 +251,9 @@ var client = {
rTorrent.get('system.multicall', request)
.then(function(data) {
callback(null, clientUtil.mapClientProps(
clientUtil.defaults.clientProperties, data)
);
clientUtil.defaults.clientProperties,
data
));
}, function(error) {
callback(error, null);
});
+7 -3
View File
@@ -115,16 +115,20 @@ var clientUtil = {
clientProperties: [
'uploadRate',
'uploadTotal',
'uploadThrottle',
'downloadRate',
'downloadTotal'
'downloadTotal',
'downloadThrottle'
],
clientPropertyMethods: [
'get_up_rate',
'get_up_total',
'throttle.global_up.max_rate',
'get_down_rate',
'get_down_total'
'get_down_total',
'throttle.global_down.max_rate'
],
peerProperties: [
'address',
@@ -185,7 +189,7 @@ var clientUtil = {
}
for (i = 0, len = methodCalls.length; i < len; i++) {
var param = [];
var param = [''];
if (params[i]) {
param = [params[i]];
}
+14 -10
View File
@@ -17,9 +17,9 @@ router.get('/', function(req, res, next) {
});
router.get('/add', function(req, res, next) {
client.add('get', handleClientResponse(res));
});
// router.get('/add', function(req, res, next) {
// client.add('get', handleClientResponse(res));
// });
router.post('/add', function(req, res, next) {
client.add(req.body, handleClientResponse(res));
@@ -29,9 +29,8 @@ router.get('/list', function(req, res, next) {
client.getTorrentList(handleClientResponse(res));
});
router.post('/stop', function(req, res, next) {
var hashes = req.body.hashes;
client.stopTorrent(hashes, handleClientResponse(res));
router.put('/settings/speed-limits', function(req, res, next) {
client.setSpeedLimits(req.body, handleClientResponse(res));
});
router.post('/start', function(req, res, next) {
@@ -39,15 +38,20 @@ router.post('/start', function(req, res, next) {
client.startTorrent(hashes, handleClientResponse(res));
});
router.get('/stats', function(req, res, next) {
client.getTransferStats(handleClientResponse(res));
});
router.post('/stop', function(req, res, next) {
var hashes = req.body.hashes;
client.stopTorrent(hashes, handleClientResponse(res));
});
router.post('/torrent-details', function(req, res, next) {
var hash = req.body.hash;
client.getTorrentDetails(hash, handleClientResponse(res));
});
router.get('/stats', function(req, res, next) {
client.getTransferStats(handleClientResponse(res));
});
router.get('/methods.json', function(req, res, next) {
var type = req.query.type;
var args = req.query.args;