mirror of
https://github.com/zoriya/flood.git
synced 2026-06-02 11:06:35 +00:00
server: migrate getDirectoryList to TypeScript
This commit is contained in:
@@ -1,45 +0,0 @@
|
||||
import fs from 'fs';
|
||||
import os from 'os';
|
||||
import path from 'path';
|
||||
|
||||
import fileUtil from '../util/fileUtil';
|
||||
|
||||
const getDirectoryList = (options, callback) => {
|
||||
const sourcePath = (options.path || '/').replace(/^~/, os.homedir());
|
||||
|
||||
const resolvedPath = fileUtil.sanitizePath(sourcePath);
|
||||
if (!fileUtil.isAllowedPath(resolvedPath)) {
|
||||
callback(null, fileUtil.accessDeniedError());
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const directories = [];
|
||||
const files = [];
|
||||
|
||||
fs.readdirSync(resolvedPath).forEach((item) => {
|
||||
const joinedPath = path.join(resolvedPath, item);
|
||||
if (fs.existsSync(joinedPath)) {
|
||||
if (fs.statSync(joinedPath).isDirectory()) {
|
||||
directories.push(item);
|
||||
} else {
|
||||
files.push(item);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
const hasParent = /^.{0,}:?(\/|\\){1,1}\S{1,}/.test(resolvedPath);
|
||||
|
||||
callback({
|
||||
directories,
|
||||
files,
|
||||
hasParent,
|
||||
path: resolvedPath,
|
||||
separator: path.sep,
|
||||
});
|
||||
} catch (error) {
|
||||
callback(null, error);
|
||||
}
|
||||
};
|
||||
|
||||
export default {getDirectoryList};
|
||||
@@ -4,10 +4,10 @@ import sanitize from 'sanitize-filename';
|
||||
import {series} from 'async';
|
||||
import tar from 'tar-stream';
|
||||
|
||||
import {accessDeniedError, createDirectory, isAllowedPath, sanitizePath} from '../util/fileUtil';
|
||||
import ClientRequest from './ClientRequest';
|
||||
import clientResponseUtil from '../util/clientResponseUtil';
|
||||
import {clientSettingsBiMap} from '../../shared/constants/clientSettingsMap';
|
||||
import fileUtil from '../util/fileUtil';
|
||||
import settings from './settings';
|
||||
import torrentFilePropsMap from '../../shared/constants/torrentFilePropsMap';
|
||||
import torrentPeerPropsMap from '../../shared/constants/torrentPeerPropsMap';
|
||||
@@ -18,13 +18,13 @@ const client = {
|
||||
addFiles(user, services, options, callback) {
|
||||
const {destination: destinationPath, files, isBasePath, start, tags} = options;
|
||||
|
||||
const resolvedPath = fileUtil.sanitizePath(destinationPath);
|
||||
if (!fileUtil.isAllowedPath(resolvedPath)) {
|
||||
callback(null, fileUtil.accessDeniedError());
|
||||
const resolvedPath = sanitizePath(destinationPath);
|
||||
if (!isAllowedPath(resolvedPath)) {
|
||||
callback(null, accessDeniedError());
|
||||
return;
|
||||
}
|
||||
|
||||
fileUtil.createDirectory({path: resolvedPath});
|
||||
createDirectory({path: resolvedPath});
|
||||
|
||||
// Each torrent is sent individually because rTorrent accepts a total
|
||||
// filesize of 524 kilobytes or less. This allows the user to send many
|
||||
@@ -56,12 +56,12 @@ const client = {
|
||||
addUrls(user, services, data, callback) {
|
||||
const {urls, destination, isBasePath, start, tags} = data;
|
||||
const request = new ClientRequest(user, services);
|
||||
const resolvedPath = fileUtil.sanitizePath(destination);
|
||||
if (!fileUtil.isAllowedPath(resolvedPath)) {
|
||||
callback(null, fileUtil.accessDeniedError());
|
||||
const resolvedPath = sanitizePath(destination);
|
||||
if (!isAllowedPath(resolvedPath)) {
|
||||
callback(null, accessDeniedError());
|
||||
return;
|
||||
}
|
||||
fileUtil.createDirectory({path: resolvedPath});
|
||||
createDirectory({path: resolvedPath});
|
||||
request.addURLs({
|
||||
urls,
|
||||
path: resolvedPath,
|
||||
|
||||
Reference in New Issue
Block a user