server: migrate setSpeedLimits and setTracker to clientGatewayService

This commit is contained in:
Jesse Chan
2020-10-13 17:05:23 +08:00
parent 3ea6a93904
commit c0ddc55810
28 changed files with 506 additions and 475 deletions
+20
View File
@@ -2,6 +2,8 @@ import fs from 'fs';
import {homedir} from 'os';
import path from 'path';
import {TorrentContent, TorrentContentTree} from '@shared/types/TorrentContent';
import config from '../../config';
export const accessDeniedError = () => {
@@ -48,6 +50,24 @@ export const createDirectory = (directoryPath: string) => {
}
};
export const findFilesByIndices = (indices: Array<number>, fileTree: TorrentContentTree): TorrentContent[] => {
const {directories, files = []} = fileTree;
let selectedFiles = files.filter((file) => indices.includes(file.index));
if (directories != null) {
selectedFiles = selectedFiles.concat(
Object.keys(directories).reduce(
(accumulator: TorrentContent[], directory) =>
accumulator.concat(findFilesByIndices(indices, directories[directory])),
[],
),
);
}
return selectedFiles;
};
export const getDirectoryList = async (inputPath: string) => {
if (typeof inputPath !== 'string') {
throw fileNotFoundError();