Allow setting tags when adding a torrent via URL

This commit is contained in:
John Furrow
2016-08-13 13:08:34 -07:00
parent c861d9052e
commit 849c8695a5
2 changed files with 24 additions and 6 deletions
+21 -4
View File
@@ -132,6 +132,7 @@ class ClientRequest {
addURLsMethodCall(options) {
let path = options.path;
let start = options.start;
let tagsArr = options.tags;
let urls = this.getEnsuredArray(options.urls);
urls.forEach((url) => {
@@ -139,10 +140,24 @@ class ClientRequest {
let parameters = ['', url];
let timeAdded = Math.floor(Date.now() / 1000);
if (path && path !== '') {
if (path) {
parameters.push(`d.directory.set="${path}"`);
}
if (tagsArr) {
let tags = tagsArr.reduce((memo, currentTag) => {
let tag = encodeURIComponent(currentTag.trim());
if (tag !== '' && memo.indexOf(tag) === -1) {
memo.push(tag);
}
return memo;
}, []).join(',');
parameters.push(`d.custom1.set="${tags}"`);
}
parameters.push(`d.custom.set=addtime,${timeAdded}`);
if (!start) {
@@ -162,9 +177,11 @@ class ClientRequest {
}
createDirectoryMethodCall(options) {
this.requests.push(
this.getMethodCall('execute2', ['mkdir', '-p', options.path])
);
if (options.path) {
this.requests.push(
this.getMethodCall('execute2', ['mkdir', '-p', options.path])
);
}
}
fetchSettingsMethodCall(options) {
+3 -2
View File
@@ -8,7 +8,7 @@ let clientSettingsMap = require('../../shared/constants/clientSettingsMap');
let ClientRequest = require('./ClientRequest');
let clientUtil = require('../util/clientUtil');
let propsMap = require('../../shared/constants/propsMap');
let formatUtil = require('../util/formatUtil');
let formatUtil = require('../../shared/util/formatUtil');
let scgi = require('../util/scgi');
let Torrent = require('./Torrent');
let TorrentCollection = require('./TorrentCollection');
@@ -48,10 +48,11 @@ var client = {
let urls = data.urls;
let path = data.destination;
let start = data.start;
let tags = data.tags;
let request = new ClientRequest();
request.add('createDirectory', {path});
request.add('addURLs', {urls, path, start});
request.add('addURLs', {urls, path, start, tags});
request.onComplete(callback);
request.send();
},