diff --git a/src/config.ts b/src/config.ts index 56c9d29..64b16df 100644 --- a/src/config.ts +++ b/src/config.ts @@ -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, @@ -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'); diff --git a/src/index.ts b/src/index.ts index c6fd882..e231b93 100644 --- a/src/index.ts +++ b/src/index.ts @@ -5,6 +5,7 @@ import { Bot, GrammyError, HttpError } from 'grammy'; import { botToken, cookiesFilePath, + qbtSavePath, qbtWebuiHost, qbtWebuiPassword, qbtWebuiPort, @@ -33,6 +34,7 @@ const qBittorrent = new QBittorrentClient({ url: `http://${qbtWebuiHost}:${qbtWebuiPort}`, username: qbtWebuiUsername, password: qbtWebuiPassword, + savePath: qbtSavePath }); const torrents = new Torrents({ bot, diff --git a/src/qBittorrent/QBittorrentClient.ts b/src/qBittorrent/QBittorrentClient.ts index 95aec9a..afdc368 100644 --- a/src/qBittorrent/QBittorrentClient.ts +++ b/src/qBittorrent/QBittorrentClient.ts @@ -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`; } @@ -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);