mirror of
https://github.com/zoriya/flood.git
synced 2026-06-03 19:21:48 +00:00
api: torrents: simplify contents API by returning an Array of TorrentContent
This commit is contained in:
@@ -2,8 +2,6 @@ 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 = () => {
|
||||
@@ -50,24 +48,6 @@ 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();
|
||||
|
||||
Reference in New Issue
Block a user