mirror of
https://github.com/zoriya/flood.git
synced 2026-06-01 18:47:44 +00:00
server: migrate torrent details functions to TypeScript
This commit is contained in:
@@ -4,7 +4,6 @@
|
||||
import util from 'util';
|
||||
|
||||
import {clientSettingsMap} from '../../shared/constants/clientSettingsMap';
|
||||
import rTorrentPropMap from '../util/rTorrentPropMap';
|
||||
|
||||
const getEnsuredArray = (item) => {
|
||||
if (!util.isArray(item)) {
|
||||
@@ -108,16 +107,6 @@ class ClientRequest {
|
||||
});
|
||||
}
|
||||
|
||||
getTorrentDetails(options) {
|
||||
const peerParams = [options.hash, ''].concat(options.peerProps);
|
||||
const fileParams = [options.hash, ''].concat(options.fileProps);
|
||||
const trackerParams = [options.hash, ''].concat(options.trackerProps);
|
||||
|
||||
this.requests.push(getMethodCall('p.multicall', peerParams));
|
||||
this.requests.push(getMethodCall('f.multicall', fileParams));
|
||||
this.requests.push(getMethodCall('t.multicall', trackerParams));
|
||||
}
|
||||
|
||||
setSettings(options) {
|
||||
const settings = getEnsuredArray(options.settings);
|
||||
|
||||
|
||||
+7
-25
@@ -5,30 +5,26 @@ import {series} from 'async';
|
||||
import tar from 'tar-stream';
|
||||
|
||||
import ClientRequest from './ClientRequest';
|
||||
import clientResponseUtil from '../util/clientResponseUtil';
|
||||
import {clientSettingsBiMap} from '../../shared/constants/clientSettingsMap';
|
||||
import torrentFilePropsMap from '../../shared/constants/torrentFilePropsMap';
|
||||
import torrentPeerPropsMap from '../../shared/constants/torrentPeerPropsMap';
|
||||
import torrentFileUtil from '../util/torrentFileUtil';
|
||||
import torrentTrackerPropsMap from '../../shared/constants/torrentTrackerPropsMap';
|
||||
|
||||
const client = {
|
||||
downloadFiles(user, services, hash, fileString, res) {
|
||||
downloadFiles(services, hash, fileString, res) {
|
||||
try {
|
||||
const selectedTorrent = services.torrentService.getTorrent(hash);
|
||||
if (!selectedTorrent) return res.status(404).json({error: 'Torrent not found.'});
|
||||
|
||||
this.getTorrentDetails(user, services, hash, (torrentDetails) => {
|
||||
if (!torrentDetails) return res.status(404).json({error: 'Torrent details not found'});
|
||||
services.clientGatewayService.getTorrentContents(hash).then((contents) => {
|
||||
if (!contents) return res.status(404).json({error: 'Torrent contents not found'});
|
||||
|
||||
let files;
|
||||
if (!fileString || fileString === 'all') {
|
||||
files = torrentDetails.fileTree.files.map((x, i) => `${i}`);
|
||||
files = contents.files.map((x, i) => `${i}`);
|
||||
} else {
|
||||
files = fileString.split(',');
|
||||
}
|
||||
|
||||
const filePathsToDownload = this.findFilesByIndicies(files, torrentDetails.fileTree).map((file) =>
|
||||
const filePathsToDownload = this.findFilesByIndices(files, contents).map((file) =>
|
||||
path.join(selectedTorrent.directory, file.path),
|
||||
);
|
||||
|
||||
@@ -76,7 +72,7 @@ const client = {
|
||||
}
|
||||
},
|
||||
|
||||
findFilesByIndicies(indices, fileTree = {}) {
|
||||
findFilesByIndices(indices, fileTree = {}) {
|
||||
const {directories, files = []} = fileTree;
|
||||
|
||||
let selectedFiles = files.filter((file) => indices.includes(`${file.index}`));
|
||||
@@ -84,7 +80,7 @@ const client = {
|
||||
if (directories != null) {
|
||||
selectedFiles = selectedFiles.concat(
|
||||
Object.keys(directories).reduce(
|
||||
(accumulator, directory) => accumulator.concat(this.findFilesByIndicies(indices, directories[directory])),
|
||||
(accumulator, directory) => accumulator.concat(this.findFilesByIndices(indices, directories[directory])),
|
||||
[],
|
||||
),
|
||||
);
|
||||
@@ -133,20 +129,6 @@ const client = {
|
||||
request.send();
|
||||
},
|
||||
|
||||
getTorrentDetails(user, services, hash, callback) {
|
||||
const request = new ClientRequest(user, services);
|
||||
|
||||
request.getTorrentDetails({
|
||||
hash,
|
||||
fileProps: torrentFilePropsMap.methods,
|
||||
peerProps: torrentPeerPropsMap.methods,
|
||||
trackerProps: torrentTrackerPropsMap.methods,
|
||||
});
|
||||
request.postProcess(clientResponseUtil.processTorrentDetails);
|
||||
request.onComplete(callback);
|
||||
request.send();
|
||||
},
|
||||
|
||||
setSettings(user, services, payloads, callback) {
|
||||
const request = new ClientRequest(user, services);
|
||||
if (payloads.length === 0) return callback({});
|
||||
|
||||
Reference in New Issue
Block a user