From 0eb55935fe974ba916599e171a46f24c8530e61e Mon Sep 17 00:00:00 2001 From: Rishi Ghan Date: Sun, 24 Mar 2024 17:31:12 -0400 Subject: [PATCH] =?UTF-8?q?=F0=9F=A7=B2=20Added=20maindata=20realtime=20st?= =?UTF-8?q?ats?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- services/qbittorrent.service.ts | 53 ++++++++++++++++++++------------- 1 file changed, 32 insertions(+), 21 deletions(-) diff --git a/services/qbittorrent.service.ts b/services/qbittorrent.service.ts index 001aa19..d227b87 100644 --- a/services/qbittorrent.service.ts +++ b/services/qbittorrent.service.ts @@ -61,13 +61,17 @@ export default class QBittorrentService extends Service { host: { username, password, hostname, port, protocol }, }, } = result; - return await this.broker.call("qbittorrent.connect", { + + const connection = await this.broker.call("qbittorrent.connect", { username, password, hostname, port, protocol, }); + console.log("qbittorrent connection details:"); + console.log(JSON.stringify(connection, null, 4)); + return connection; } } catch (err) { return { @@ -142,32 +146,39 @@ export default class QBittorrentService extends Service { return await this.meta.torrents.info(); }, }, - getTorrentDetails: { - rest: "POST /getTorrentDetails", - handler: async (ctx: Context<{ infoHashes: [string] }>) => { - await this.broker.call("qbittorrent.loginWithStoredCredentials", {}); - const infoHashes = Object.values(ctx.params); - const torrentDetails = infoHashes.map(async (infoHash) => { - return await this.meta.torrents.properties(infoHash); - }); - return Promise.all(torrentDetails); + getTorrentProperties: { + rest: "POST /getTorrentProperties", + handler: async (ctx: Context<{ infoHashes: string[] }>) => { + try { + const { infoHashes } = ctx.params; + await this.broker.call("qbittorrent.loginWithStoredCredentials", {}); + return await this.meta.torrents.info({ + hashes: infoHashes, + }); + } catch (err) { + console.error("An error occurred:", err); + // Consider handling the error more gracefully here, possibly returning an error response + throw err; // or return a specific error object/message + } }, }, - checkForDeletedTorrents: { - rest: "GET /checkForDeletedTorrents", - handler: async (ctx: Context<{ infoHashes: [string] }>) => { + getTorrentRealTimeStats: { + rest: "POST /getTorrentRealTimeStats", + handler: async ( + ctx: Context<{ infoHashes: { _id: string; infoHashes: string[] }[] }>, + ) => { await this.broker.call("qbittorrent.loginWithStoredCredentials", {}); - const torrents: any = await this.broker.call("qbittorrent.getTorrents", {}); - const deletedTorrents = this.detectDeletedTorrents( - torrents.map((torrent: any) => torrent.hash), - ); - return deletedTorrents; + + try { + return await this.meta.sync.maindata(1); + } catch (err) { + this.logger.error(err); + throw err; + } }, }, }, - methods: { - detectDeletedTorrents(currentHashes) {}, - }, + methods: {}, async started() {}, }); }