Skip to content

Commit 3a14a89

Browse files
committed
fix: Do not upload files that start with /tmp/, fix test
1 parent 382b6b3 commit 3a14a89

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

Diff for: src/index.ts

+11-4
Original file line numberDiff line numberDiff line change
@@ -253,12 +253,19 @@ export class Deluge implements TorrentClient {
253253
torrent: string | Buffer,
254254
config: Partial<AddTorrentOptions> = {},
255255
): Promise<AddTorrentResponse> {
256-
const upload = await this.upload(torrent);
257-
if (!upload.success || !upload.files.length) {
258-
throw new Error('Failed to upload');
256+
let path: string;
257+
if (Buffer.isBuffer(torrent) || !torrent.startsWith('/tmp/')) {
258+
const upload = await this.upload(torrent);
259+
if (!upload.success || !upload.files.length) {
260+
throw new Error('Failed to upload');
261+
}
262+
263+
path = upload.files[0];
264+
} else {
265+
/** Assume paths starting with /tmp/ are from {@link Deluge.addTorrent} */
266+
path = torrent;
259267
}
260268

261-
const path = upload.files[0];
262269
const options: AddTorrentOptions = {
263270
file_priorities: [],
264271
add_paused: false,

Diff for: test/index.spec.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ describe('Deluge', () => {
314314
'https://releases.ubuntu.com/20.10/ubuntu-20.10-desktop-amd64.iso.torrent',
315315
);
316316
expect(result).toContain('/tmp/');
317-
await client.addTorrent(torrentFile, { add_paused: true });
317+
await client.addTorrent(result, { add_paused: true });
318318
await pWaitFor(
319319
async () => {
320320
const r = await client.listTorrents();

0 commit comments

Comments
 (0)