Skip to content

Commit

Permalink
fix: Do not upload files that start with /tmp/, fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
scttcper committed Apr 19, 2021
1 parent 382b6b3 commit 3a14a89
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
15 changes: 11 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -253,12 +253,19 @@ export class Deluge implements TorrentClient {
torrent: string | Buffer,
config: Partial<AddTorrentOptions> = {},
): Promise<AddTorrentResponse> {
const upload = await this.upload(torrent);
if (!upload.success || !upload.files.length) {
throw new Error('Failed to upload');
let path: string;
if (Buffer.isBuffer(torrent) || !torrent.startsWith('/tmp/')) {
const upload = await this.upload(torrent);
if (!upload.success || !upload.files.length) {
throw new Error('Failed to upload');
}

path = upload.files[0];
} else {
/** Assume paths starting with /tmp/ are from {@link Deluge.addTorrent} */
path = torrent;
}

const path = upload.files[0];
const options: AddTorrentOptions = {
file_priorities: [],
add_paused: false,
Expand Down
2 changes: 1 addition & 1 deletion test/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ describe('Deluge', () => {
'https://releases.ubuntu.com/20.10/ubuntu-20.10-desktop-amd64.iso.torrent',
);
expect(result).toContain('/tmp/');
await client.addTorrent(torrentFile, { add_paused: true });
await client.addTorrent(result, { add_paused: true });
await pWaitFor(
async () => {
const r = await client.listTorrents();
Expand Down

0 comments on commit 3a14a89

Please sign in to comment.