From daca4e63938a9f9d066a3c083902dc897e3d5929 Mon Sep 17 00:00:00 2001 From: Rishi Ghan Date: Thu, 7 Mar 2024 05:51:13 -0600 Subject: [PATCH] =?UTF-8?q?=F0=9F=A7=B2=20Added=20a=20torrent=20detail=20e?= =?UTF-8?q?ndpoint?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- services/qbittorrent.service.ts | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/services/qbittorrent.service.ts b/services/qbittorrent.service.ts index 3790f2c..9f23875 100644 --- a/services/qbittorrent.service.ts +++ b/services/qbittorrent.service.ts @@ -1,15 +1,12 @@ -"use strict"; -import { Context, Service, ServiceBroker, ServiceSchema, Errors } from "moleculer"; -import { qBittorrentClient } from "@robertklep/qbittorrent"; -import parseTorrent from "parse-torrent"; import { readFileSync, writeFileSync } from "fs"; +import { qBittorrentClient } from "@robertklep/qbittorrent"; +import type { Context, ServiceBroker, ServiceSchema } from "moleculer"; +import { Errors, Service } from "moleculer"; +import parseTorrent from "parse-torrent"; export default class QBittorrentService extends Service { // @ts-ignore - public constructor( - public broker: ServiceBroker, - schema: ServiceSchema<{}> = { name: "qbittorrent" }, - ) { + constructor(public broker: ServiceBroker, schema: ServiceSchema<{}> = { name: "qbittorrent" }) { super(broker); this.parseServiceSchema({ name: "qbittorrent", @@ -93,8 +90,16 @@ export default class QBittorrentService extends Service { }, getTorrents: { rest: "POST /getTorrents", - handler: async (ctx: Context<{}>) => { - return await this.meta.torrents.info(); + handler: async (ctx: Context<{}>) => await this.meta.torrents.info(), + }, + getTorrentDetails: { + rest: "POST /getTorrentDetails", + handler: async (ctx: Context<{ infoHashes: [string] }>) => { + const infoHashes = Object.values(ctx.params); + const torrentDetails = infoHashes.map(async (infoHash) => { + return await this.meta.torrents.properties(infoHash); + }); + return Promise.all(torrentDetails); }, }, },