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