diff --git a/src/app/app.js b/src/app/app.js index 3dfa04a..e958dd8 100644 --- a/src/app/app.js +++ b/src/app/app.js @@ -214,7 +214,7 @@ class App extends Component { reader.readAsArrayBuffer(file); }) })); - torrentSocket.emit('dropTorrents', files); + torrentSocket.emit('dropTorrents', {pathTorrents: files}); } document.addEventListener('dragover', (event) => { diff --git a/src/app/config-page.js b/src/app/config-page.js index 42f05b3..4ba6349 100644 --- a/src/app/config-page.js +++ b/src/app/config-page.js @@ -30,7 +30,7 @@ export default class ConfigPage extends Page { })); } saveSettings() { - window.torrentSocket.emit('setConfig', this.options) + window.torrentSocket.emit('setConfig', {options: this.options}) this.settingsSavedMessage = true this.forceUpdate() setTimeout(() => { diff --git a/src/app/download-torrent-menu.js b/src/app/download-torrent-menu.js index b773ed8..931f32d 100644 --- a/src/app/download-torrent-menu.js +++ b/src/app/download-torrent-menu.js @@ -12,7 +12,7 @@ export default (props) => { e.stopPropagation(); }} menu={[ {name: __('Download'), click: () => { - window.torrentSocket.emit('download', props.torrent, null, (added) => { + window.torrentSocket.emit('download', {torrent: props.torrent, savePath: null}, (added) => { if(props.onAdded) props.onAdded(added) }) @@ -65,7 +65,7 @@ export default (props) => { { path = testPath; } - window.torrentSocket.emit('download', props.torrent, path[0], (added) => { + window.torrentSocket.emit('download', {torrent: props.torrent, savePath: path[0]}, (added) => { if(props.onAdded) props.onAdded(added) }) diff --git a/src/app/feed.js b/src/app/feed.js index bc7deff..f7a3961 100644 --- a/src/app/feed.js +++ b/src/app/feed.js @@ -28,7 +28,7 @@ export default class RecentTorrents extends AutoScrollable { this.loadMoreFeed(); } loadMoreFeed() { - window.torrentSocket.emit('feed', this.torrents.length, window.customLoader((data) => { + window.torrentSocket.emit('feed', {index: this.torrents.length}, window.customLoader((data) => { if(data) { this.torrents = this.torrents.concat(data); this.forceUpdate(); diff --git a/src/app/filters-page.js b/src/app/filters-page.js index 41e0296..7523325 100644 --- a/src/app/filters-page.js +++ b/src/app/filters-page.js @@ -73,7 +73,7 @@ export default class ConfigPage extends Page { else this.options.filters.contentType = this.contentType - window.torrentSocket.emit('setConfig', this.options) + window.torrentSocket.emit('setConfig', {options: this.options}) this.settingsSavedMessage = true this.forceUpdate() setTimeout(() => { @@ -266,7 +266,7 @@ export default class ConfigPage extends Page { { this.toRemoveProbably = null this.toRemove = null - window.torrentSocket.emit('removeTorrents', true, window.customLoader((toRemove) => { + window.torrentSocket.emit('removeTorrents', {checkOnly: true}, window.customLoader((toRemove) => { this.toRemoveProbably = toRemove this.forceUpdate() })); @@ -274,7 +274,7 @@ export default class ConfigPage extends Page { { this.toRemoveProbably = null this.toRemove = null - window.torrentSocket.emit('removeTorrents', false, window.customLoader((toRemove) => { + window.torrentSocket.emit('removeTorrents', {checkOnly: false}, window.customLoader((toRemove) => { this.toRemove = toRemove this.forceUpdate() })); diff --git a/src/app/header.js b/src/app/header.js index adf9643..23ca1c8 100644 --- a/src/app/header.js +++ b/src/app/header.js @@ -71,7 +71,7 @@ class Header extends React.Component { if(savePath) { fs.writeFileSync(savePath, torrent) console.log('saved', torrent.length, 'to', savePath) - torrentSocket.emit('dropTorrents', [{path: savePath}]); + torrentSocket.emit('dropTorrents', {pathTorrents: [{path: savePath}]}); } } }) diff --git a/src/app/search.js b/src/app/search.js index 6dc6b69..125272d 100644 --- a/src/app/search.js +++ b/src/app/search.js @@ -60,7 +60,7 @@ class Search extends Component { if(this.state.advancedSearch && this.advanced) searchTorrentsParams = Object.assign(searchTorrentsParams, this.advanced); - this.searchTorrentId = window.torrentSocket.emit('searchTorrent', oldSearch ? this.currentSearch : this.searchValue, searchTorrentsParams, window.customLoader((torrents) => { + this.searchTorrentId = window.torrentSocket.emit('searchTorrent', {text: oldSearch ? this.currentSearch : this.searchValue, navigation: searchTorrentsParams}, window.customLoader((torrents) => { if(torrents) { this.searchTorrents = torrents; if(torrents.length != this.searchLimit) @@ -86,7 +86,7 @@ class Search extends Component { if(this.state.advancedSearch && this.advanced) searchFilesParams = Object.assign(searchFilesParams, this.advanced); - this.searchFilesId = window.torrentSocket.emit('searchFiles', oldSearch ? this.currentSearch : this.searchValue, searchFilesParams, window.customLoader((torrents) => { + this.searchFilesId = window.torrentSocket.emit('searchFiles', {text: oldSearch ? this.currentSearch : this.searchValue, navigation: searchFilesParams}, window.customLoader((torrents) => { if(torrents) { this.searchFiles = torrents; let files = 0; @@ -113,13 +113,13 @@ class Search extends Component { this.setState({moreTorrentsIndicator: true}); this.onSearchUpdate('indicator') - this.searchTorrentId = window.torrentSocket.emit('searchTorrent', this.currentSearch, { + this.searchTorrentId = window.torrentSocket.emit('searchTorrent', {text: this.currentSearch, navigation: { index: this.searchTorrents.length, limit: this.searchLimit, safeSearch: !this.notSafeSearch, orderBy: this.state.orderBy, orderDesc: this.state.orderDesc, - }, window.customLoader((torrents) => { + }}, window.customLoader((torrents) => { if(torrents) { this.searchTorrents = this.searchTorrents.concat(torrents); if(torrents.length != this.searchLimit) @@ -149,13 +149,13 @@ class Search extends Component { this.setState({moreFilesIndicator: true}); this.onSearchUpdate('indicator') - this.searchFilesId = window.torrentSocket.emit('searchFiles', this.currentSearch, { + this.searchFilesId = window.torrentSocket.emit('searchFiles', {text: this.currentSearch, navigation: { index: index, limit: this.searchLimit, safeSearch: !this.notSafeSearch, orderBy: this.state.orderBy, orderDesc: this.state.orderDesc, - }, window.customLoader((torrents) => { + }}, window.customLoader((torrents) => { if(torrents) { this.searchFiles = this.searchFiles.concat(torrents); diff --git a/src/app/top-page.js b/src/app/top-page.js index e4bfee9..fac9245 100644 --- a/src/app/top-page.js +++ b/src/app/top-page.js @@ -39,9 +39,10 @@ export default class TopPage extends Page { this.firstUpdate = false time = time ? time : this.state.time const page = (this.topTorrents[type] && this.topTorrents[type][time] && this.topTorrents[type][time].page) || 0 - window.torrentSocket.emit('topTorrents', - type == 'main' ? null : type, - {index: page * 20, limit: 20, time}, + window.torrentSocket.emit('topTorrents', { + type: (type == 'main' ? null : type), + navigation: {index: page * 20, limit: 20, time} + }, window.customLoader((torrents) => { this.mergeTorrents(torrents, type, time) this.topTorrents[type][time].page = page + 1 diff --git a/src/app/torrent-page.js b/src/app/torrent-page.js index 0ed3237..5df680b 100644 --- a/src/app/torrent-page.js +++ b/src/app/torrent-page.js @@ -114,7 +114,7 @@ const treeToTorrentFiles = (tree, torrent, toggles) => { e.stopPropagation() let toggleValues = {} newToggles.forEach(({downloadIndex}) => toggleValues[downloadIndex] = checked) - window.torrentSocket.emit('downloadSelectFiles', torrent, toggleValues) + window.torrentSocket.emit('downloadSelectFiles', {hash: torrent.hash, files: toggleValues}) }} /> : @@ -258,7 +258,7 @@ export default class TorrentPage extends Page { }); }; getTorrentInfo() { - window.torrentSocket.emit('torrent', this.props.hash, {files: true, peer: this.props.peer}, window.customLoader((data) => { + window.torrentSocket.emit('torrent', {hash: this.props.hash, options: {files: true, peer: this.props.peer}}, window.customLoader((data) => { if(data) { this.torrent = data this.setTitle(this.torrent.name + ' - Rats On The Boat'); @@ -270,7 +270,7 @@ export default class TorrentPage extends Page { // Получаем более новую статистику пира if((Date.now() / 1000) - this.torrent.trackersChecked > 10 * 60) { - window.torrentSocket.emit('checkTrackers', this.torrent.hash); + window.torrentSocket.emit('checkTrackers', {hash: this.torrent.hash}); } } }, () => { @@ -391,7 +391,7 @@ export default class TorrentPage extends Page { this.setState({ voting: true }); - window.torrentSocket.emit('vote', this.torrent.hash, !!good, window.customLoader((success) => { + window.torrentSocket.emit('vote', {hash: this.torrent.hash, isGood: !!good}, window.customLoader((success) => { this.setState({ voted: true, voting: false @@ -531,7 +531,7 @@ export default class TorrentPage extends Page { /> { - window.torrentSocket.emit('downloadCancel', this.torrent.hash) + window.torrentSocket.emit('downloadCancel', {hash: this.torrent.hash}) }} label={__('Cancel download')} secondary={true} diff --git a/src/app/torrent.js b/src/app/torrent.js index 7cc0dfe..ab793aa 100644 --- a/src/app/torrent.js +++ b/src/app/torrent.js @@ -416,7 +416,7 @@ export default class Torrent extends Component { }} onClick={(e) => { e.preventDefault(); e.stopPropagation(); - window.torrentSocket.emit('downloadUpdate', torrent.hash, {pause: 'switch'}) + window.torrentSocket.emit('downloadUpdate', {hash: torrent.hash, options: {pause: 'switch'}}) }} viewBox="0 0 438.536 438.536"> { e.preventDefault(); e.stopPropagation(); - window.torrentSocket.emit('downloadCancel', torrent.hash) + window.torrentSocket.emit('downloadCancel', {hash: torrent.hash}) }}>
@@ -541,7 +541,7 @@ export default class Torrent extends Component { e.preventDefault(); e.stopPropagation(); - window.torrentSocket.emit('downloadCancel', torrent.hash) + window.torrentSocket.emit('downloadCancel', {hash: torrent.hash}) }} viewBox="0 0 18 18"> @@ -558,7 +558,7 @@ export default class Torrent extends Component { e.preventDefault(); e.stopPropagation(); - window.torrentSocket.emit('downloadCancel', torrent.hash) + window.torrentSocket.emit('downloadCancel', {hash: torrent.hash}) }} viewBox="0 0 18 18"> diff --git a/src/background/api.js b/src/background/api.js index 6e52711..f9b1703 100644 --- a/src/background/api.js +++ b/src/background/api.js @@ -125,7 +125,7 @@ module.exports = async ({ }) }); - const onTorrent = (hash, options, callback) => { + const onTorrent = ({hash, options}, callback) => { if(hash.length != 40) return; @@ -381,7 +381,7 @@ module.exports = async ({ }); } - recive('searchTorrent', mergeTorrentsWithDownloadsFn((text, navigation, callback, id) => { + recive('searchTorrent', mergeTorrentsWithDownloadsFn(({text, navigation}, callback, id) => { searchTorrentCall(text, navigation, callback) p2p.emit('searchTorrent', {text, navigation}, (remote, socketObject) => { logT('search', 'remote search results', remote && remote.length) @@ -473,7 +473,7 @@ module.exports = async ({ }); } - recive('searchFiles', mergeTorrentsWithDownloadsFn((text, navigation, callback, id) => { + recive('searchFiles', mergeTorrentsWithDownloadsFn(({text, navigation}, callback, id) => { searchFilesCall(text, navigation, callback) p2p.emit('searchFiles', {text, navigation}, (remote, socketObject) => { logT('search', 'remote search files results', remote && remote.length) @@ -494,7 +494,7 @@ module.exports = async ({ searchFilesCall(text, navigation, (data) => callback(data)) }) - recive('checkTrackers', function(hash) + recive('checkTrackers', function({hash}) { if(hash.length != 40) return; @@ -550,7 +550,7 @@ module.exports = async ({ }); } - recive('topTorrents', mergeTorrentsWithDownloadsFn((type, navigation, callback) => + recive('topTorrents', mergeTorrentsWithDownloadsFn(({type, navigation}, callback) => { topTorrentsCall(type, navigation, callback) p2p.emit('topTorrents', {type, navigation}, (remote, socketObject) => { @@ -596,7 +596,7 @@ module.exports = async ({ callback(config) }); - recive('setConfig', (options, callback) => + recive('setConfig', ({options}, callback) => { if(typeof options !== 'object') return; @@ -815,9 +815,9 @@ module.exports = async ({ return torrent } - recive('download', torrentClient._add); + recive('download', ({torrent, savePath}, callback) => torrentClient._add(torrent, savePath, callback)); - recive('downloadUpdate', (hash, options) => + recive('downloadUpdate', ({hash, options}) => { const id = torrentClientHashMap[hash] if(!id) @@ -852,7 +852,7 @@ module.exports = async ({ }) }) - recive('downloadCancel', (hash, callback) => + recive('downloadCancel', ({hash}, callback) => { const id = torrentClientHashMap[hash] if(!id) @@ -880,7 +880,7 @@ module.exports = async ({ }) }) - recive('downloadSelectFiles', ({hash}, files, callback) => + recive('downloadSelectFiles', ({hash, files}, callback) => { logT('downloader', 'call update selection', hash, files.length) const id = torrentClientHashMap[hash] @@ -920,7 +920,7 @@ module.exports = async ({ }) let removeProtect = false - recive('removeTorrents', (checkOnly = true, callback) => + recive('removeTorrents', ({checkOnly}, callback) => { if(removeProtect) return @@ -981,7 +981,7 @@ module.exports = async ({ return {good, bad, selfVote} } - recive('vote', async (hash, isGood, callback) => + recive('vote', async ({hash, isGood}, callback) => { if(hash.length != 40) return; @@ -1060,7 +1060,7 @@ module.exports = async ({ }); }) - const feedCall = (index, callback) => + const feedCall = ({index}, callback) => { callback(feed.feed.slice(index || 0, (index || 0) + 20)); } diff --git a/src/background/config.js b/src/background/config.js index 20d7056..2fe93f4 100644 --- a/src/background/config.js +++ b/src/background/config.js @@ -13,6 +13,7 @@ let config = { peerId: undefined, language: 'en', trackers: true, + restApi: false, p2p: true, p2pConnections: 10, diff --git a/src/background/spider.js b/src/background/spider.js index bbf4a6e..4a59b15 100644 --- a/src/background/spider.js +++ b/src/background/spider.js @@ -803,7 +803,7 @@ module.exports = function (send, recive, dataDirectory, version, env, {version: client._download(peer, infoHash) } - recive('dropTorrents', (pathTorrents) => { + recive('dropTorrents', ({pathTorrents}) => { logT('drop', 'drop torrents and replicate from original torrent files') const addTorrents = (torrents) => { torrents.map(({data, path}) => {