mirror of
https://github.com/zoriya/flood.git
synced 2025-12-19 13:45:15 +00:00
When moving files, remember start/stopped status
This commit is contained in:
@@ -12,7 +12,8 @@ let util = require('util');
|
||||
let clientSettingsMap = require('../../shared/constants/clientSettingsMap');
|
||||
let rTorrentPropMap = require('../util/rTorrentPropMap');
|
||||
let scgi = require('../util/scgi');
|
||||
let stringUtil = require('../../shared/util/stringUtil');
|
||||
const torrentService = require('../services/torrentService');
|
||||
const torrentStatusMap = require('../../shared/constants/torrentStatusMap');
|
||||
|
||||
class ClientRequest {
|
||||
constructor(options) {
|
||||
@@ -183,11 +184,16 @@ class ClientRequest {
|
||||
}
|
||||
|
||||
checkHash(options) {
|
||||
let hashes = this.getEnsuredArray(options.hashes);
|
||||
const hashes = this.getEnsuredArray(options.hashes);
|
||||
const hashesToStop = hashes.filter(hash => {
|
||||
return torrentService.getTorrent(hash).status.includes(torrentStatusMap.stopped);
|
||||
});
|
||||
|
||||
hashes.forEach((hash) => {
|
||||
hashes.forEach(hash => {
|
||||
this.requests.push(this.getMethodCall('d.check_hash', [hash]));
|
||||
});
|
||||
|
||||
this.stopTorrents({hashes: hashesToStop});
|
||||
}
|
||||
|
||||
createDirectory(options) {
|
||||
@@ -247,15 +253,14 @@ class ClientRequest {
|
||||
}
|
||||
|
||||
moveTorrents(options) {
|
||||
let hashes = this.getEnsuredArray(options.hashes);
|
||||
let destinationPath = options.destinationPath;
|
||||
let filenames = this.getEnsuredArray(options.filenames);
|
||||
let sourcePaths = this.getEnsuredArray(options.sourcePaths);
|
||||
const destinationPath = options.destinationPath;
|
||||
const filenames = this.getEnsuredArray(options.filenames);
|
||||
const sourcePaths = this.getEnsuredArray(options.sourcePaths);
|
||||
|
||||
sourcePaths.forEach((source, index) => {
|
||||
let callback = () => {};
|
||||
let destination = `${destinationPath}${path.sep}${filenames[index]}`;
|
||||
let isLastRequest = index + 1 === sourcePaths.length;
|
||||
const destination = `${destinationPath}${path.sep}${filenames[index]}`;
|
||||
const isLastRequest = index + 1 === sourcePaths.length;
|
||||
|
||||
if (isLastRequest) {
|
||||
callback = this.handleSuccess.bind(this);
|
||||
|
||||
@@ -11,6 +11,7 @@ const clientSettingsMap = require('../../shared/constants/clientSettingsMap');
|
||||
const settings = require('./settings');
|
||||
const torrentFilePropsMap = require('../../shared/constants/torrentFilePropsMap');
|
||||
const torrentPeerPropsMap = require('../../shared/constants/torrentPeerPropsMap');
|
||||
const torrentStatusMap = require('../../shared/constants/torrentStatusMap');
|
||||
const torrentService = require('../services/torrentService');
|
||||
const torrentTrackerPropsMap = require('../../shared/constants/torrentTrackerPropsMap');
|
||||
|
||||
@@ -18,7 +19,7 @@ var client = {
|
||||
addFiles (req, callback) {
|
||||
let files = req.files;
|
||||
let path = req.body.destination;
|
||||
let isBasePath = req.body.isBasePath === 'true';
|
||||
let isBasePath = req.body.isBasePath;
|
||||
let request = new ClientRequest();
|
||||
let start = req.body.start;
|
||||
let tags = req.body.tags;
|
||||
@@ -234,36 +235,45 @@ var client = {
|
||||
|
||||
moveTorrents (data, callback) {
|
||||
let destinationPath = data.destination;
|
||||
let isBasePath = data.isBasePath === 'true';
|
||||
let isBasePath = data.isBasePath;
|
||||
let hashes = data.hashes;
|
||||
let filenames = data.filenames;
|
||||
let moveFiles = data.moveFiles;
|
||||
let sourcePaths = data.sources;
|
||||
let mainRequest = new ClientRequest();
|
||||
|
||||
let startTorrents = () => {
|
||||
let startTorrentsRequest = new ClientRequest();
|
||||
startTorrentsRequest.startTorrents({hashes});
|
||||
const hashesToRestart = hashes.filter((hash) => {
|
||||
return !torrentService.getTorrent(hash).status.includes(torrentStatusMap.stopped);
|
||||
});
|
||||
|
||||
let afterCheckHash;
|
||||
|
||||
if (hashesToRestart.length) {
|
||||
afterCheckHash = () => {
|
||||
const startTorrentsRequest = new ClientRequest();
|
||||
startTorrentsRequest.startTorrents({hashes: hashesToRestart});
|
||||
startTorrentsRequest.onComplete(callback);
|
||||
startTorrentsRequest.send();
|
||||
};
|
||||
} else {
|
||||
afterCheckHash = callback;
|
||||
}
|
||||
|
||||
let checkHash = () => {
|
||||
let checkHashRequest = new ClientRequest();
|
||||
const checkHash = () => {
|
||||
const checkHashRequest = new ClientRequest();
|
||||
checkHashRequest.checkHash({hashes});
|
||||
checkHashRequest.onComplete(afterCheckHash);
|
||||
checkHashRequest.send();
|
||||
};
|
||||
|
||||
let moveTorrents = () => {
|
||||
let moveTorrentsRequest = new ClientRequest();
|
||||
const moveTorrents = () => {
|
||||
const moveTorrentsRequest = new ClientRequest();
|
||||
moveTorrentsRequest.onComplete(checkHash);
|
||||
moveTorrentsRequest.moveTorrents({
|
||||
filenames, sourcePaths, destinationPath
|
||||
});
|
||||
};
|
||||
|
||||
let afterCheckHash = startTorrents;
|
||||
let afterSetPath = checkHash;
|
||||
|
||||
if (moveFiles) {
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
'use strict';
|
||||
|
||||
let objectUtil = require('../util/objectUtil');
|
||||
const objectUtil = require('../util/objectUtil');
|
||||
|
||||
let torrentStatusMap = objectUtil.reflect({
|
||||
const torrentStatusMap = objectUtil.reflect({
|
||||
ch: 'checking',
|
||||
sd: 'seeding',
|
||||
p: 'paused',
|
||||
|
||||
Reference in New Issue
Block a user