server: rTorrent: ensure the temporary file is world-readable

This allows rTorrent to read the file when the Flood and rTorrent
are running in different users and when the system has a restrictive
default umask.

Bug: #86
This commit is contained in:
Jesse Chan
2020-11-14 01:30:01 +08:00
parent 006512c013
commit ac11f3190b
2 changed files with 8 additions and 4 deletions
@@ -63,7 +63,7 @@ class RTorrentClientGatewayService extends ClientGatewayService {
}: Required<AddTorrentByFileOptions>): Promise<void> {
const torrentPaths = await Promise.all(
files.map(async (file) => {
return saveBufferToTempFile(Buffer.from(file, 'base64'), 'torrent');
return saveBufferToTempFile(Buffer.from(file, 'base64'), 'torrent', {mode: 0o664});
}),
);
+7 -3
View File
@@ -1,6 +1,6 @@
import axios, {AxiosError, AxiosResponse} from 'axios';
import crypto from 'crypto';
import fs from 'fs';
import fs, {WriteFileOptions} from 'fs';
import {getTempPath} from '../models/TemporaryStorage';
@@ -33,10 +33,14 @@ const delayedDelete = (tempPath: string): void => {
* @param {string} extension - file extension of temp file
* @return {string} - path of saved temporary file. deleted after 5 minutes.
*/
export const saveBufferToTempFile = async (buffer: Buffer, extension?: string): Promise<string> => {
export const saveBufferToTempFile = async (
buffer: Buffer,
extension?: string,
options?: WriteFileOptions,
): Promise<string> => {
const tempPath = getTempFilePath(extension);
fs.writeFileSync(tempPath, buffer);
fs.writeFileSync(tempPath, buffer, options);
delayedDelete(tempPath);