🐯 Added a prowlarr api test endpoint
This commit is contained in:
39
services/prowlarr.service.ts
Normal file
39
services/prowlarr.service.ts
Normal file
@@ -0,0 +1,39 @@
|
||||
"use strict";
|
||||
import { Context, Service, ServiceBroker, ServiceSchema, Errors } from "moleculer";
|
||||
import { qBittorrentClient } from "@robertklep/qbittorrent";
|
||||
const { MoleculerError } = require("moleculer").Errors;
|
||||
|
||||
export default class QBittorrentService extends Service {
|
||||
// @ts-ignore
|
||||
public constructor(
|
||||
public broker: ServiceBroker,
|
||||
schema: ServiceSchema<{}> = { name: "qbittorrent" },
|
||||
) {
|
||||
super(broker);
|
||||
this.parseServiceSchema({
|
||||
name: "qbittorrent",
|
||||
mixins: [],
|
||||
hooks: {},
|
||||
actions: {
|
||||
|
||||
getList: {
|
||||
rest: "GET /getTorrents",
|
||||
handler: async (ctx: Context<{}>) => {
|
||||
return await this.torrentClient.torrents.info()
|
||||
}
|
||||
}
|
||||
}, 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,
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -1,37 +1,43 @@
|
||||
"use strict";
|
||||
import { Context, Service, ServiceBroker, ServiceSchema, Errors } from "moleculer";
|
||||
import { qBittorrentClient } from "@robertklep/qbittorrent";
|
||||
const { MoleculerError } = require("moleculer").Errors;
|
||||
import axios from "axios";
|
||||
|
||||
export default class QBittorrentService extends Service {
|
||||
export default class ProwlarrService extends Service {
|
||||
// @ts-ignore
|
||||
public constructor(
|
||||
public broker: ServiceBroker,
|
||||
schema: ServiceSchema<{}> = { name: "qbittorrent" },
|
||||
schema: ServiceSchema<{}> = { name: "prowlarr" },
|
||||
) {
|
||||
super(broker);
|
||||
this.parseServiceSchema({
|
||||
name: "qbittorrent",
|
||||
name: "prowlarr",
|
||||
mixins: [],
|
||||
hooks: {},
|
||||
actions: {
|
||||
|
||||
getList: {
|
||||
rest: "GET /getTorrents",
|
||||
testConnection: {
|
||||
rest: "GET /testConnection",
|
||||
handler: async (ctx: Context<{}>) => {
|
||||
return await this.torrentClient.torrents.info()
|
||||
try {
|
||||
const result = await axios.request({
|
||||
url: `http://192.168.1.183:9696/api/`,
|
||||
method: `GET`,
|
||||
headers: { Accept: "application/json" },
|
||||
params: {
|
||||
apiKey: "163ef9a683874f65b53c7be87354b38b",
|
||||
}
|
||||
});
|
||||
|
||||
return result.data;
|
||||
} catch(err) {
|
||||
console.log(err);
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
}, 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,
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user