🔧 Fixes to getList endpoint

This commit is contained in:
2023-09-05 21:53:42 -04:00
parent adab421e5b
commit 44f612c52f
2 changed files with 140 additions and 164 deletions

View File

@@ -1,6 +1,7 @@
"use strict";
import { Context, Service, ServiceBroker, ServiceSchema, Errors } from "moleculer";
import { qBittorrentClient} from "@robertklep/qbittorrent";
import { qBittorrentClient } from "@robertklep/qbittorrent";
const { MoleculerError } = require("moleculer").Errors;
export default class QBittorrentService extends Service {
// @ts-ignore
@@ -14,23 +15,25 @@ export default class QBittorrentService extends Service {
mixins: [],
hooks: {},
actions: {
connect: {
rest: "POST /connect",
handler: async (ctx: Context<{}>) => {
const torrentClient = new qBittorrentClient("http://192.168.1.183:8089", "admin", "adminadmin");
const info = await torrentClient.torrents.info();
return { foo: info };
},
},
getList : {
rest: "GET /getList",
getList: {
rest: "GET /getTorrents",
handler: async (ctx: Context<{}>) => {
return await this.torrentClient.torrents.info()
}
}
},
methods: {},
}, methods: {},
async started(): Promise<any> {
try {
this.torrentClient = new qBittorrentClient("http://192.168.1.183:8089", "admin", "adminadmin");
} catch (err) {
throw new MoleculerError(err, 500, "QBITTORRENT_CONNECTION_ERROR", {
data: err,
});
}
}
});
}
}