mirror of
https://github.com/zoriya/flood.git
synced 2026-06-02 19:11:14 +00:00
Merge pull request #105 from jfurrow/feature/set-tags-when-adding-urls
Allow setting tags when adding a torrent via URL
This commit is contained in:
@@ -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) {
|
||||
|
||||
@@ -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();
|
||||
},
|
||||
|
||||
@@ -1,188 +0,0 @@
|
||||
/**
|
||||
* @class DateFormatter
|
||||
* The DateFormatter supports decoding from and encoding to
|
||||
* ISO8601 formatted strings. Accepts formats with and without
|
||||
* hyphen/colon separators and correctly parses zoning info.
|
||||
*/
|
||||
var DateFormatter = (opts) => {
|
||||
this.opts = {}
|
||||
this.setOpts(opts)
|
||||
}
|
||||
|
||||
/**
|
||||
* Default options for DateFormatter
|
||||
* @static
|
||||
* @see DateFormatter#setOpts
|
||||
*/
|
||||
DateFormatter.DEFAULT_OPTIONS = {
|
||||
colons: true
|
||||
, hyphens: false
|
||||
, local: true
|
||||
, ms: false
|
||||
, offset: false
|
||||
}
|
||||
|
||||
/**
|
||||
* Regular Expression that disects ISO 8601 formatted strings into
|
||||
* an array of parts.
|
||||
* @static
|
||||
*/
|
||||
DateFormatter.ISO8601 = new RegExp(
|
||||
'([0-9]{4})([-]?([0-9]{2}))([-]?([0-9]{2}))'
|
||||
+ '(T([0-9]{2})(((:?([0-9]{2}))?((:?([0-9]{2}))?(\.([0-9]+))?))?)'
|
||||
+ '(Z|([+-]([0-9]{2}(:?([0-9]{2}))?)))?)?'
|
||||
)
|
||||
|
||||
/**
|
||||
* Sets options for encoding Date objects to ISO8601 strings.
|
||||
* Omitting the 'opts' argument will reset all options to the default.
|
||||
*
|
||||
* @param {Object} opts - Options (optional)
|
||||
* @param {Boolean} opts.colons - Enable/disable formatting the time portion
|
||||
* with a colon as separator (default: true)
|
||||
* @param {Boolean} opts.hyphens - Enable/disable formatting the date portion
|
||||
* with a hyphen as separator (default: false)
|
||||
* @param {Boolean} opts.local - Encode as local time instead of UTC
|
||||
* (default: true)
|
||||
* @param {Boolean} opts.ms - Enable/Disable output of milliseconds
|
||||
* (default: false)
|
||||
* @param {Boolean} opts.offset - Enable/Disable output of UTC offset
|
||||
* (default: false)
|
||||
*/
|
||||
DateFormatter.prototype.setOpts = (opts) => {
|
||||
if (!opts) opts = DateFormatter.DEFAULT_OPTIONS
|
||||
|
||||
var ctx = this;
|
||||
Object.keys(DateFormatter.DEFAULT_OPTIONS).forEach((k) => {
|
||||
ctx.opts[k] = opts.hasOwnProperty(k) ?
|
||||
opts[k] : DateFormatter.DEFAULT_OPTIONS[k]
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a date time stamp following the ISO8601 format to a JavaScript Date
|
||||
* object.
|
||||
*
|
||||
* @param {String} time - String representation of timestamp.
|
||||
* @return {Date} - Date object from timestamp.
|
||||
*/
|
||||
DateFormatter.prototype.decodeIso8601 = (time) => {
|
||||
var dateParts = time.toString().match(DateFormatter.ISO8601)
|
||||
if (!dateParts) {
|
||||
throw new Error('Expected a ISO8601 datetime but got \'' + time + '\'')
|
||||
}
|
||||
|
||||
var date = [
|
||||
[dateParts[1], dateParts[3] || '01', dateParts[5] || '01'].join('-')
|
||||
, 'T'
|
||||
, [
|
||||
dateParts[7] || '00'
|
||||
, dateParts[11] || '00'
|
||||
, dateParts[14] || '00'
|
||||
].join(':')
|
||||
, '.'
|
||||
, dateParts[16] || '000'
|
||||
].join('')
|
||||
|
||||
date += (dateParts[17] !== undefined) ?
|
||||
dateParts[17] +
|
||||
((dateParts[19] && dateParts[20] === undefined) ? '00' : '') :
|
||||
DateFormatter.formatCurrentOffset(new Date(date))
|
||||
|
||||
return new Date(date)
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a JavaScript Date object to an ISO8601 timestamp.
|
||||
*
|
||||
* @param {Date} date - Date object.
|
||||
* @return {String} - String representation of timestamp.
|
||||
*/
|
||||
DateFormatter.prototype.encodeIso8601 = (date) => {
|
||||
var parts = this.opts.local ?
|
||||
DateFormatter.getLocalDateParts(date) :
|
||||
DateFormatter.getUTCDateParts(date)
|
||||
|
||||
return [
|
||||
[parts[0],parts[1],parts[2]].join(this.opts.hyphens ? '-' : '')
|
||||
, 'T'
|
||||
, [parts[3],parts[4],parts[5]].join(this.opts.colons ? ':' : '')
|
||||
, (this.opts.ms) ? '.' + parts[6] : ''
|
||||
, (this.opts.local) ? ((this.opts.offset) ?
|
||||
DateFormatter.formatCurrentOffset(date) : '') : 'Z'
|
||||
].join('')
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper function to get an array of zero-padded date parts,
|
||||
* in UTC
|
||||
*
|
||||
* @param {Date} date - Date Object
|
||||
* @return {String[]}
|
||||
*/
|
||||
DateFormatter.getUTCDateParts = (date) => {
|
||||
return [
|
||||
date.getUTCFullYear()
|
||||
, DateFormatter.zeroPad(date.getUTCMonth()+1,2)
|
||||
, DateFormatter.zeroPad(date.getUTCDate(),2)
|
||||
, DateFormatter.zeroPad(date.getUTCHours(), 2)
|
||||
, DateFormatter.zeroPad(date.getUTCMinutes(), 2)
|
||||
, DateFormatter.zeroPad(date.getUTCSeconds(), 2)
|
||||
, DateFormatter.zeroPad(date.getUTCMilliseconds(), 3)]
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Helper function to get an array of zero-padded date parts,
|
||||
* in the local time zone
|
||||
*
|
||||
* @param {Date} date - Date Object
|
||||
* @return {String[]}
|
||||
*/
|
||||
DateFormatter.getLocalDateParts = (date) => {
|
||||
return [
|
||||
date.getFullYear()
|
||||
, DateFormatter.zeroPad(date.getMonth()+1,2)
|
||||
, DateFormatter.zeroPad(date.getDate(),2)
|
||||
, DateFormatter.zeroPad(date.getHours(), 2)
|
||||
, DateFormatter.zeroPad(date.getMinutes(), 2)
|
||||
, DateFormatter.zeroPad(date.getSeconds(), 2)
|
||||
, DateFormatter.zeroPad(date.getMilliseconds(), 3)]
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper function to pad the digits with 0s to meet date formatting
|
||||
* requirements.
|
||||
*
|
||||
* @param {Number} digit - The number to pad.
|
||||
* @param {Number} length - Length of digit string, prefix with 0s if not
|
||||
* already length.
|
||||
* @return {String} - String with the padded digit
|
||||
*/
|
||||
DateFormatter.zeroPad = (digit, length) => {
|
||||
var padded = '' + digit
|
||||
while (padded.length < length) {
|
||||
padded = '0' + padded
|
||||
}
|
||||
|
||||
return padded
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper function to get the current timezone to default decoding to
|
||||
* rather than UTC. (for backward compatibility)
|
||||
*
|
||||
* @return {String} - in the format /Z|[+-]\d{2}:\d{2}/
|
||||
*/
|
||||
DateFormatter.formatCurrentOffset = (d) => {
|
||||
var offset = (d || new Date()).getTimezoneOffset()
|
||||
return (offset === 0) ? 'Z' : [
|
||||
(offset < 0) ? '+' : '-'
|
||||
, DateFormatter.zeroPad(Math.abs(Math.floor(offset/60)),2)
|
||||
, ':'
|
||||
, DateFormatter.zeroPad(Math.abs(offset%60),2)
|
||||
].join('')
|
||||
}
|
||||
|
||||
// export an instance of DateFormatter only.
|
||||
module.exports = new DateFormatter()
|
||||
@@ -1,12 +1,9 @@
|
||||
var util = require('util');
|
||||
'use strict';
|
||||
let moment = require('moment');
|
||||
|
||||
var FormatUtil = {
|
||||
percentComplete: (numerator, denominator) => {
|
||||
|
||||
},
|
||||
|
||||
eta: (rate, completed, total) => {
|
||||
|
||||
minToHumanReadable: min => {
|
||||
return moment.duration(min * 60 * 1000).humanize();
|
||||
},
|
||||
|
||||
parsePeers: (string) => {
|
||||
Reference in New Issue
Block a user