prepare for REST public API: one args format for recive()

This commit is contained in:
Alexey Kasyanchuk 2023-06-05 04:45:41 +03:00
parent 9d17fd28d1
commit 56746cb9d7
13 changed files with 44 additions and 42 deletions

View File

@ -214,7 +214,7 @@ class App extends Component {
reader.readAsArrayBuffer(file);
})
}));
torrentSocket.emit('dropTorrents', files);
torrentSocket.emit('dropTorrents', {pathTorrents: files});
}
document.addEventListener('dragover', (event) => {

View File

@ -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(() => {

View File

@ -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)
})

View File

@ -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();

View File

@ -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 {
<RaisedButton label={__('Check torrents')} primary={true} onClick={() => {
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 {
<RaisedButton label={__('Clean torrents')} secondary={true} onClick={() => {
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()
}));

View File

@ -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}]});
}
}
})

View File

@ -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);

View File

@ -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

View File

@ -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 {
/>
<FlatButton
onClick={() => {
window.torrentSocket.emit('downloadCancel', this.torrent.hash)
window.torrentSocket.emit('downloadCancel', {hash: this.torrent.hash})
}}
label={__('Cancel download')}
secondary={true}

View File

@ -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">
<g>
<path d="M164.453,0H18.276C13.324,0,9.041,1.807,5.425,5.424C1.808,9.04,0.001,13.322,0.001,18.271v401.991
@ -443,7 +443,7 @@ export default class Torrent extends Component {
}} onClick={(e) => {
e.preventDefault();
e.stopPropagation();
window.torrentSocket.emit('downloadUpdate', torrent.hash, {removeOnDone: 'switch'})
window.torrentSocket.emit('downloadUpdate', {hash: torrent.hash, options: {removeOnDone: 'switch'}})
}} viewBox="0 0 512 512">
<g>
<path d="M456.313,85.333h-55.527C386.809,36.16,341.594,0,288,0s-98.809,36.16-112.785,85.333h-69.441l-3.482-11.938
@ -515,7 +515,7 @@ export default class Torrent extends Component {
<div className="overlay-loader" onClick={(e) => {
e.preventDefault();
e.stopPropagation();
window.torrentSocket.emit('downloadCancel', torrent.hash)
window.torrentSocket.emit('downloadCancel', {hash: torrent.hash})
}}>
<div className="loader">
<div></div>
@ -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"><path d="M9 1C4.58 1 1 4.58 1 9s3.58 8 8 8 8-3.58 8-8-3.58-8-8-8zm4 10.87L11.87 13 9 10.13 6.13 13 5 11.87 7.87 9 5 6.13 6.13 5 9 7.87 11.87 5 13 6.13 10.13 9 13 11.87z"/></svg>
</a>
</ToolTip>
@ -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"><path d="M9 1C4.58 1 1 4.58 1 9s3.58 8 8 8 8-3.58 8-8-3.58-8-8-8zm4 10.87L11.87 13 9 10.13 6.13 13 5 11.87 7.87 9 5 6.13 6.13 5 9 7.87 11.87 5 13 6.13 10.13 9 13 11.87z"/></svg>
</a>
</ToolTip>

View File

@ -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));
}

View File

@ -13,6 +13,7 @@ let config = {
peerId: undefined,
language: 'en',
trackers: true,
restApi: false,
p2p: true,
p2pConnections: 10,

View File

@ -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}) => {