server: fileUtil: properly use async createDirectory

This commit is contained in:
Jesse Chan
2020-10-19 19:50:09 +08:00
parent f0daebbf41
commit 63860705ef
2 changed files with 17 additions and 10 deletions

View File

@@ -61,7 +61,7 @@ class RTorrentClientGatewayService extends ClientGatewayService {
throw accessDeniedError(); throw accessDeniedError();
} }
createDirectory(destinationPath); await createDirectory(destinationPath);
// Each torrent is sent individually because rTorrent might have small // Each torrent is sent individually because rTorrent might have small
// XMLRPC request size limit. This allows the user to send files reliably. // XMLRPC request size limit. This allows the user to send files reliably.
@@ -99,7 +99,7 @@ class RTorrentClientGatewayService extends ClientGatewayService {
throw accessDeniedError(); throw accessDeniedError();
} }
createDirectory(destinationPath); await createDirectory(destinationPath);
const methodCalls: MultiMethodCalls = urls.map((url) => { const methodCalls: MultiMethodCalls = urls.map((url) => {
const additionalCalls: Array<string> = []; const additionalCalls: Array<string> = [];

View File

@@ -38,14 +38,21 @@ export const sanitizePath = (input: string) => {
return path.resolve(input).replace(controlRe, ''); return path.resolve(input).replace(controlRe, '');
}; };
export const createDirectory = (directoryPath: string) => { export const createDirectory = (directoryPath: string): Promise<void> => {
return new Promise<void>((resolve, reject) => {
if (directoryPath) { if (directoryPath) {
fs.mkdir(directoryPath, {recursive: true}, (error) => { fs.mkdir(directoryPath, {recursive: true}, (error) => {
if (error) { if (error) {
console.trace('Error creating directory.', error); console.trace('Error creating directory.', error);
reject();
return;
}
resolve();
});
} else {
reject();
} }
}); });
}
}; };
export const getDirectoryList = async (inputPath: string) => { export const getDirectoryList = async (inputPath: string) => {