Skip to content

Commit

Permalink
feat: allow to set save path
Browse files Browse the repository at this point in the history
  • Loading branch information
strayiker committed Sep 27, 2024
1 parent 9ce67bf commit 07349c4
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export const botToken = config.get('BOT_TOKEN', {
required: true,
});
export const cookiesFilePath = config.get('COOKIES_FILE_PATH', {
default: './data/cookies.json',
default: '/data/cookies.json',
});
export const rutrackerUsername = config.get('RUTRACKER_USERNAME', {
required: true,
Expand All @@ -37,3 +37,4 @@ export const qbtWebuiUsername = config.get('QBT_WEBUI_USERNAME', {
export const qbtWebuiPassword = config.get('QBT_WEBUI_PASSWORD', {
required: true,
});
export const qbtSavePath = config.get('QBT_SAVE_PATH');
2 changes: 2 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { Bot, GrammyError, HttpError } from 'grammy';
import {
botToken,
cookiesFilePath,
qbtSavePath,
qbtWebuiHost,
qbtWebuiPassword,
qbtWebuiPort,
Expand Down Expand Up @@ -33,6 +34,7 @@ const qBittorrent = new QBittorrentClient({
url: `http://${qbtWebuiHost}:${qbtWebuiPort}`,
username: qbtWebuiUsername,
password: qbtWebuiPassword,
savePath: qbtSavePath
});
const torrents = new Torrents({
bot,
Expand Down
8 changes: 8 additions & 0 deletions src/qBittorrent/QBittorrentClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,20 @@ interface QBClientOptions {
url: string;
username: string;
password: string;
savePath?: string;
}

export class QBittorrentClient {
private username: string;
private password: string;
private savePath?: string;
private cookieJar: CookieJar = new CookieJar();
private apiBase: string;

constructor(options: QBClientOptions) {
this.username = options.username;
this.password = options.password;
this.savePath = options.savePath;
this.apiBase = `${options.url}/api/v2`;
}

Expand Down Expand Up @@ -90,11 +93,16 @@ export class QBittorrentClient {
async addTorrents({
torrents = [],
tags,
savepath = this.savePath,
...rest
}: QBClientAddTorrentsOptions) {
const data = new FormData();
const hashes: string[] = [];

if (savepath) {
data.append('savepath', savepath);
}

for (const torrent of torrents) {
const buffer = Buffer.from(torrent, 'base64');
const { infoHash } = await parseTorrent(buffer);
Expand Down

0 comments on commit 07349c4

Please sign in to comment.