Qbittorrent endpoints #3
@@ -57,14 +57,15 @@ export default class QBittorrentService extends Service {
|
|||||||
}>,
|
}>,
|
||||||
) => {
|
) => {
|
||||||
try {
|
try {
|
||||||
const { torrentToDownload } = ctx.params;
|
const { torrentToDownload, comicObjectId } = ctx.params;
|
||||||
console.log(torrentToDownload);
|
console.log(torrentToDownload);
|
||||||
const response = await fetch(torrentToDownload, {
|
const response = await fetch(torrentToDownload, {
|
||||||
method: "GET",
|
method: "GET",
|
||||||
});
|
});
|
||||||
|
// Read the buffer to a file
|
||||||
const buffer = await response.arrayBuffer();
|
const buffer = await response.arrayBuffer();
|
||||||
writeFileSync(`mithrandir.torrent`, Buffer.from(buffer));
|
writeFileSync(`mithrandir.torrent`, Buffer.from(buffer));
|
||||||
|
// Add the torrent to qbittorrent's queue, paused.
|
||||||
const result = await this.meta.torrents.add({
|
const result = await this.meta.torrents.add({
|
||||||
torrents: {
|
torrents: {
|
||||||
buffer: readFileSync("mithrandir.torrent"),
|
buffer: readFileSync("mithrandir.torrent"),
|
||||||
@@ -72,10 +73,18 @@ export default class QBittorrentService extends Service {
|
|||||||
// start this torrent in a paused state (see Torrent type for options)
|
// start this torrent in a paused state (see Torrent type for options)
|
||||||
paused: true,
|
paused: true,
|
||||||
});
|
});
|
||||||
|
const { name, infoHash, announce } = parseTorrent(
|
||||||
|
readFileSync("mithrandir.torrent"),
|
||||||
|
);
|
||||||
|
await this.broker.call("library.applyTorrentDownloadMetadata", {
|
||||||
|
name,
|
||||||
|
torrentToDownload,
|
||||||
|
comicObjectId,
|
||||||
|
announce,
|
||||||
|
infoHash,
|
||||||
|
});
|
||||||
return {
|
return {
|
||||||
result,
|
result,
|
||||||
metadata: parseTorrent(readFileSync("mithrandir.torrent")),
|
|
||||||
};
|
};
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error(err);
|
console.error(err);
|
||||||
|
|||||||
Reference in New Issue
Block a user