import { IpcClientService } from "@autoplex/ipc"; import { Microservice } from "@autoplex/microservice"; import { SOCKET_PATH } from "./constants"; import { ISerializedTorrent, ITorrent } from "./schema"; export abstract class IpcClient extends IpcClientService { /** * The path to the socket file */ protected SOCKET_PATH = SOCKET_PATH; /** * Add a torrent to the client * @param torrent Magnet URI or file buffer */ public async add(torrent: string | Buffer, downloadPath?: string) { let response = await this.request("add", { torrent, downloadPath }); if (response.error) { throw new Error("Failed to add torrent"); } return response.data; } /** * Remove a torrent from the client * @param torrent Torrent info hash */ public async remove(torrent: string) { let response = await this.request("remove", torrent); if (response.error) { throw new Error("Failed to remove torrent"); } } /** * Get a list of all torrents in the client */ public async list() { let response = await this.request("list"); if (response.error) { console.error(response.error); throw new Error("Failed to obtain torrent list"); } return response.data; } /** * Get full details of each of the provided torrents * @param torrentIds Array of torrent info hashes */ public async details(...torrentIds: string[]) { let response = await this.request("details", torrentIds); if (response.error) { console.error(response.error); throw new Error("Failed to retrieve torrent details"); } return response.data; } }