🧲 Mild refactor
This commit is contained in:
@@ -167,10 +167,45 @@ export default class QBittorrentService extends Service {
|
|||||||
handler: async (
|
handler: async (
|
||||||
ctx: Context<{ infoHashes: { _id: string; infoHashes: string[] }[] }>,
|
ctx: Context<{ infoHashes: { _id: string; infoHashes: string[] }[] }>,
|
||||||
) => {
|
) => {
|
||||||
|
const { infoHashes } = ctx.params;
|
||||||
await this.broker.call("qbittorrent.loginWithStoredCredentials", {});
|
await this.broker.call("qbittorrent.loginWithStoredCredentials", {});
|
||||||
|
|
||||||
try {
|
try {
|
||||||
return await this.meta.sync.maindata(1);
|
// Increment rid for each call
|
||||||
|
this.rid = typeof this.rid === "number" ? this.rid + 1 : 0;
|
||||||
|
const data = await this.meta.sync.maindata(this.rid);
|
||||||
|
const torrentDetails: any = [];
|
||||||
|
|
||||||
|
infoHashes.forEach(({ _id, infoHashes }) => {
|
||||||
|
// Initialize an object to hold details for this _id
|
||||||
|
const details: any = [];
|
||||||
|
|
||||||
|
infoHashes.forEach((hash) => {
|
||||||
|
// Assuming 'data.torrents[hash]' retrieves the details for the hash
|
||||||
|
const torrent = data.torrents[hash];
|
||||||
|
if (torrent) {
|
||||||
|
details.push({
|
||||||
|
torrent,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// If you have details for this _id, add them to the main array
|
||||||
|
if (details.length > 0) {
|
||||||
|
torrentDetails.push({
|
||||||
|
_id,
|
||||||
|
details,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
// Update rid with the latest value if needed based on the response
|
||||||
|
// Assuming `data.rid` contains the latest rid from the server
|
||||||
|
if (data.rid !== undefined) {
|
||||||
|
this.rid = data.rid;
|
||||||
|
console.log(`rid is ${this.rid}`);
|
||||||
|
}
|
||||||
|
console.log(JSON.stringify(torrentDetails, null, 4));
|
||||||
|
return torrentDetails;
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
this.logger.error(err);
|
this.logger.error(err);
|
||||||
throw err;
|
throw err;
|
||||||
@@ -179,7 +214,11 @@ export default class QBittorrentService extends Service {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
methods: {},
|
methods: {},
|
||||||
async started() {},
|
async started() {
|
||||||
|
console.log(`Initializing rid...`);
|
||||||
|
this.rid = 0;
|
||||||
|
console.log(`rid is ${this.rid}`);
|
||||||
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user