🧲 Added parse-torrent for metadata

This commit is contained in:
2024-02-29 08:37:24 -06:00
parent df07dff1db
commit 54974db2de
5 changed files with 366 additions and 88 deletions

View File

@@ -59,8 +59,8 @@ export default class ProwlarrService extends Service {
apiKey: string;
query: string;
type: string;
indexerIds: string;
categories: string;
indexerIds: [number];
categories: [number];
limit: number;
offset: number;
}>,
@@ -77,19 +77,14 @@ export default class ProwlarrService extends Service {
offset,
} = ctx.params;
const indexers = indexerIds.split(",").map((index) => parseInt(index, 10));
const searchCategories = categories
.split(",")
.map((category) => parseInt(category, 10));
const result = await axios({
url: `http://${host}:${port}/api/v1/search`,
method: "GET",
params: {
query,
type,
indexers,
searchCategories,
indexerIds,
categories,
limit,
offset,
},
@@ -98,7 +93,6 @@ export default class ProwlarrService extends Service {
"X-Api-Key": `${apiKey}`,
},
});
console.log(result);
return result.data;
},
},

View File

@@ -1,6 +1,8 @@
"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";
export default class QBittorrentService extends Service {
// @ts-ignore
@@ -32,6 +34,7 @@ export default class QBittorrentService extends Service {
`${username}`,
`${password}`,
);
console.log(this.meta);
},
},
getClientInfo: {
@@ -45,6 +48,46 @@ export default class QBittorrentService extends Service {
};
},
},
addTorrent: {
rest: "POST /addTorrent",
handler: async (
ctx: Context<{
torrentToDownload: any;
comicObjectId: string;
}>,
) => {
try {
const { torrentToDownload } = ctx.params;
console.log(torrentToDownload);
const response = await fetch(torrentToDownload, {
method: "GET",
});
const buffer = await response.arrayBuffer();
writeFileSync(`mithrandir.torrent`, Buffer.from(buffer));
const result = await this.meta.torrents.add({
torrents: {
buffer: readFileSync("mithrandir.torrent"),
},
// start this torrent in a paused state (see Torrent type for options)
paused: true,
});
return {
result,
metadata: parseTorrent(readFileSync("mithrandir.torrent")),
};
} catch (err) {
console.error(err);
}
},
},
getTorrents: {
rest: "POST /getTorrents",
handler: async (ctx: Context<{}>) => {
return await this.meta.torrents.info();
},
},
},
methods: {},
});