🧲 Added maindata realtime stats
This commit is contained in:
@@ -61,13 +61,17 @@ export default class QBittorrentService extends Service {
|
|||||||
host: { username, password, hostname, port, protocol },
|
host: { username, password, hostname, port, protocol },
|
||||||
},
|
},
|
||||||
} = result;
|
} = result;
|
||||||
return await this.broker.call("qbittorrent.connect", {
|
|
||||||
|
const connection = await this.broker.call("qbittorrent.connect", {
|
||||||
username,
|
username,
|
||||||
password,
|
password,
|
||||||
hostname,
|
hostname,
|
||||||
port,
|
port,
|
||||||
protocol,
|
protocol,
|
||||||
});
|
});
|
||||||
|
console.log("qbittorrent connection details:");
|
||||||
|
console.log(JSON.stringify(connection, null, 4));
|
||||||
|
return connection;
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
return {
|
return {
|
||||||
@@ -142,32 +146,39 @@ export default class QBittorrentService extends Service {
|
|||||||
return await this.meta.torrents.info();
|
return await this.meta.torrents.info();
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
getTorrentDetails: {
|
getTorrentProperties: {
|
||||||
rest: "POST /getTorrentDetails",
|
rest: "POST /getTorrentProperties",
|
||||||
handler: async (ctx: Context<{ infoHashes: [string] }>) => {
|
handler: async (ctx: Context<{ infoHashes: string[] }>) => {
|
||||||
await this.broker.call("qbittorrent.loginWithStoredCredentials", {});
|
try {
|
||||||
const infoHashes = Object.values(ctx.params);
|
const { infoHashes } = ctx.params;
|
||||||
const torrentDetails = infoHashes.map(async (infoHash) => {
|
await this.broker.call("qbittorrent.loginWithStoredCredentials", {});
|
||||||
return await this.meta.torrents.properties(infoHash);
|
return await this.meta.torrents.info({
|
||||||
});
|
hashes: infoHashes,
|
||||||
return Promise.all(torrentDetails);
|
});
|
||||||
|
} catch (err) {
|
||||||
|
console.error("An error occurred:", err);
|
||||||
|
// Consider handling the error more gracefully here, possibly returning an error response
|
||||||
|
throw err; // or return a specific error object/message
|
||||||
|
}
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
checkForDeletedTorrents: {
|
getTorrentRealTimeStats: {
|
||||||
rest: "GET /checkForDeletedTorrents",
|
rest: "POST /getTorrentRealTimeStats",
|
||||||
handler: async (ctx: Context<{ infoHashes: [string] }>) => {
|
handler: async (
|
||||||
|
ctx: Context<{ infoHashes: { _id: string; infoHashes: string[] }[] }>,
|
||||||
|
) => {
|
||||||
await this.broker.call("qbittorrent.loginWithStoredCredentials", {});
|
await this.broker.call("qbittorrent.loginWithStoredCredentials", {});
|
||||||
const torrents: any = await this.broker.call("qbittorrent.getTorrents", {});
|
|
||||||
const deletedTorrents = this.detectDeletedTorrents(
|
try {
|
||||||
torrents.map((torrent: any) => torrent.hash),
|
return await this.meta.sync.maindata(1);
|
||||||
);
|
} catch (err) {
|
||||||
return deletedTorrents;
|
this.logger.error(err);
|
||||||
|
throw err;
|
||||||
|
}
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {},
|
||||||
detectDeletedTorrents(currentHashes) {},
|
|
||||||
},
|
|
||||||
async started() {},
|
async started() {},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user